-
Notifications
You must be signed in to change notification settings - Fork 159
Open
Description
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
Labels
No labels