AVAILABLE NOW: Spring 2025 Release
By Apryse | 2025 Apr 18
3 min
Tags
image
C#
java
Our support department recently responded to a request for a code sample to convert PDF to JPEG. The customer needed to leverage Apryse to split and convert thousands of PDF files into single page JPEGs.
JPEG images are universal and can be loaded by practically any client on any operating system. If the PDF files are photos, JPEG is the perfect universal image format for conversion. JPEG is designed specifically for photo images, supporting 24 bits per pixel color and 8 bits per pixel grayscale data.
If the PDF files are text based and need to be converted to a universal image format, PNG and GIF are more appropriate. PNG and GIF support fewer bits per pixel, including 1- and 4-bits and leverage lossless compressions. These factors result in less data to be compressed and clearer images of text and clip art. Typically, PNG results in smaller file sizes when compared to GIF.
Below are some C# and Java code snippets that can be used to convert PDF files to JPGs. The snippets can be easily modified to save the images as GIF or PNG by changing the constant on the pdfDraw.Export line.
using pdftron;
using pdftron.PDF;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
PDFNet.Initialize(PDFTronLicense.License);
using (PDFDoc doc = new PDFDoc("samples\\PDFTRON_about.pdf"))
{
doc.InitSecurityHandler();
PDFDraw pdfDraw = new PDFDraw();
pdfDraw.SetDPI(300); // Set the resolution
for (int i = 1; i <= doc.GetPageCount(); i++)
{
pdftron.PDF.Page page = doc.GetPage(i);
pdfDraw.Export(page, $"output_{i}.jpg", "JPEG");
}
}
PDFNet.Terminate();
}
}
}
import com.pdftron.common.PDFNetException;
import com.pdftron.pdf.*;
public class App {
public static void main(String[] args) {
try{
PDFNet.initialize(PDFTronLicense.LICENSE);
PDFDoc doc = new PDFDoc("src\\samples\\PDFTRON_about.pdf");
doc.initSecurityHandler();
PDFDraw pdfDraw = new PDFDraw();
pdfDraw.setDPI(300); // Set the resolution
for (int i = 1; i <= doc.getPageCount(); i++) {
Page page = doc.getPage(i);
pdfDraw.export(page, "output_" + i + ".jpg", "JPEG");
}
pdfDraw.close();
doc.close();
PDFNet.terminate();
} catch (PDFNetException e) {
System.out.println(e.getMessage());
}
}
Download the Apryse SDK for free. It’s fully functional and comes with free chat and email support.
Stay tuned for more conversion examples to see how Apryse easily fits into any workflow converting PDF files into other document files or images and back again. Need help in the meantime? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team.
Tags
image
C#
java
Apryse
Share this post
PRODUCTS
Platform Integrations
End User Applications
Popular Content