Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
petarpetrovt opened this issue Mar 27, 2023 · 0 comments
Open

Comments

@petarpetrovt
Copy link

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
		}
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant