संभव डुप्लिकेट:
Convert pdf file to jpg asp.netपीडीएफ
public class Pdf2Image {
private Image image;
int length;
public int convertPdf2Image(String pdfname) {
File file = new File(pdfname);
RandomAccessFile raf;
try {
raf = new RandomAccessFile(file, "r");
FileChannel channel = raf.getChannel();
ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
PDFFile pdffile = new PDFFile(buf);
// draw the first page to an image
int num = pdffile.getNumPages();
length=num;
for (int i = 0; i <= num; i++) {
PDFPage page = pdffile.getPage(i);
//get the width and height for the doc at the default zoom
int width = (int) page.getBBox().getWidth();
int height = (int) page.getBBox().getHeight();
Rectangle rect = new Rectangle(0, 0, width, height);
int rotation = page.getRotation();
Rectangle rect1 = rect;
if (rotation == 90 || rotation == 270) {
rect1 = new Rectangle(0, 0, rect.height, rect.width);
}
//generate the image
BufferedImage img = (BufferedImage) page.getImage(
rect.width, rect.height, //width & height
rect1, // clip rect
null, // null for the ImageObserver
true, // fill background with white
true // block until drawing is done
);
ImageIO.write(img, "png", new File("src\\downloadedFiles\\aa" + i + ".png"));
}
} catch (FileNotFoundException e1) {
System.err.println(e1.getLocalizedMessage());
} catch (IOException e) {
System.err.println(e.getLocalizedMessage());
}
return length;
}
public static void main(String[] args) {
Pdf2Image p = new Pdf2Image();
p.convertPdf2Image("src\\downloadedFiles\\todaypdf.pdf");
}
}
मैं छवि को पीडीएफ फाइल में कनवर्ट करने के लिए इस कोड का उपयोग कर रहा हूँ। यह अधिकांश पीडीएफ के लिए ठीक काम कर रहा है लेकिन पीडीएफ फाइल के लिए अपवाद दिखा रहा है। अपवाद है:
Expected 'xref' at start of table.
क्या कोई मुझे बता सकता है कि यह ऐसा अपवाद क्यों दे रहा है?
क्या आप पूर्ण कॉल स्टैक प्रदान कर सकते हैं? –
क्या आप एक्रोबैट, आईएसपीडीएफ और शायद एक और पीडीएफ दर्शक का उपयोग कर पीडीएफ देख सकते हैं? या क्या वे चेतावनियां/त्रुटियां भी देते हैं? – extraneon