Q: We started development using PDFTron PDF2Image and just switched to
PDFNet so we can get better error detection (we are in a purely .Net
environment). In PDF2Image, I could set the output type to jpeg
using "-f jpg". With PDFNet, I am not seeing a way to explicitly set
it to export as a jpeg. All I am seeing is:
Image.Export() (which will only export as jpeg if the image was added
with jpg compression per the help)
Image.ExportAsPng()
Image.ExportAsTiff().
How do I convert PDF to image using PDFNet?
----------------------------
A: The equivalent of PDF2Image in PDFNet SDK is ‘pdftron.PDF.PDFDraw’.
It can be used as shown in PDFDraw sample project:
Alternatively please follow these steps:
1) Add a reference to PDFNet.DLL to your project.
2) Call the following utility function.
using pdftron;
using pdftron.Common;
using pdftron.PDF;
using pdftron.SDF;
public static void SimpleExport(string pdf) {
string jpg = Path.ChangeExtension(pdf, ".jpg");
PDFNet.Initialize();
using (PDFDoc doc = new PDFDoc(pdf))
using (PDFDraw draw = new PDFDraw())
draw.Export(doc.GetPage(1), jpg, "JPEG", null);
}
Please let me know if this helps.
The function you are using (pdftron.PDF.Image) are typically used to
export embedded image in PDF (which can be used as parts of a PDF
page). Image.Export() will automatically export the embedded image as
JPEG if the underlying image stream is using DCTDecode filter.