I would like to use PDFBox for converting PDF to Image in .NET application. With help of IKVM version 7.2.4630.5, I have successfully convert PDFBox version 1.8.2 into .dll file. However when I try to convert the first page of PDF to image, I can't get a correct result.
First, I try to make conversion with PDFImageWriter
PDDocument pdDocument = PDDocument.load("1.pdf");
PDFImageWriter pdfImageWriter = new PDFImageWriter();
bool result = pdfImageWriter.writeImage(pdDocument, "jpg", "", 1, 1, "myfilename", BufferedImage.TYPE_INT_RGB, Toolkit.getDefaultToolkit().getScreenResolution());
But I got a NullReferenceException. Then I take a look at source code of PDFBox and try not to use PDFImageWriter with code listing like following
PDPage page = (PDPage)pdDocument.getDocumentCatalog().getAllPages().get(0);
BufferedImage bufferedImage = page.convertToImage(BufferedImage.TYPE_INT_ARGB, Toolkit.getDefaultToolkit().getScreenResolution());
java.io.File file = new java.io.File("1.png");
ImageIO.write(bufferedImage, "png", file);
It works fine but when I see the converted image. The text was not displayed correctly. The whole text is getting much more smaller.
Would you please give me some hints so that I can make the text showing correctly.
I attached here the .pdf file, converted image. I also made a test project in Visual Studio but it's large to attach in email (the project contains IKVM dll and converted PDFBox 1.8.2 ), please download at following link http://hintdesk.com/Web/Tmp/TestPdfBox.zip .