Skip to main content

Error com.sun.pdfview.PDFParseException: Expected 'xref' at start of table

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2014-01-11

I am using pdfrenderer 1.0.5 jar.
When I convert a pdf file into image, following exception is occurred.

com.sun.pdfview.PDFParseException: Expected 'xref' at start of table
at com.sun.pdfview.PDFFile.readTrailer(
at com.sun.pdfview.PDFFile.parseFile(
at com.sun.pdfview.PDFFile.<init>(
at com.sun.pdfview.PDFFile.<init>(
at com.pdfrenderer.maven.PdfToImage.main(


import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

import javax.imageio.ImageIO;

import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;

public class PdfToImage {
public static void main(String[] args) {
try {
String sourceDir = "C:/PDFCopy/1.pdf";
String destinationDir = "C:/PDFCopy/";

File pdfFile = new File(sourceDir);
if (pdfFile.exists()) {
RandomAccessFile raf = new RandomAccessFile(pdfFile, "r");
FileChannel channel = raf.getChannel();
ByteBuffer buf =, 0, channel.size());
PDFFile pdf = new PDFFile(buf);
PDFPage page = pdf.getPage(0);

System.out.println("Total pages:"+ pdf.getNumPages());

String fileName = pdfFile.getName().replace(".pdf", "_cover");

// create the image
Rectangle rect = new Rectangle(0, 0, (int) page.getBBox().getWidth(), (int) page.getBBox().getHeight());
BufferedImage bufferedImage = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_RGB);

// width & height, // clip rect, // null for the ImageObserver, // fill background with white, // block until drawing is done
Image image = page.getImage(rect.width, rect.height, rect, null, true, true );
Graphics2D bufImageGraphics = bufferedImage.createGraphics();
bufImageGraphics.drawImage(image, 0, 0, null);
ImageIO.write(bufferedImage, "png", new File( destinationDir + fileName +".png" ));
} else {
System.err.println(pdfFile.getName()+"> File not exists");

} catch (Exception e) {
1.pdf101.53 KB