Skip to content

Is there a easy way to convert from iTextSharp Image to SKBitmap? #119

@petarpetrovt

Description

@petarpetrovt

I want to export images from PDF as PNGs.

using (var reader = new PdfReader(filePath))
{
	for (int pageNumber = 1; pageNumber <= reader.NumberOfPages; pageNumber++)
	{
		// Create a new parser object to extract images from the page
		PdfDictionary pageDictionary = reader.GetPageN(pageNumber);
		PdfDictionary resourcesDictionary = pageDictionary.GetAsDict(PdfName.Resources);
		PdfDictionary xObjectDictionary = resourcesDictionary.GetAsDict(PdfName.Xobject);

		if (xObjectDictionary == null)
		{
			continue;
		}

		foreach (PdfName name in xObjectDictionary.Keys)
		{
			PdfObject obj = xObjectDictionary.Get(name);
			if (!obj.IsIndirect())
			{
				continue;
			}

			PdfDictionary imageDictionary = (PdfDictionary)PdfReader.GetPdfObject(obj);
			if (imageDictionary == null
				|| !imageDictionary.Get(PdfName.Subtype).Equals(PdfName.Image))
			{
				continue;
			}

			var image = Image.GetInstance((PrIndirectReference)obj);

			// TODO: convert to SKBitmap and save as PNG
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions