pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "blogrongchaua ." <blogrongch...@googlemail.com>
Subject PDFBox in .NET for converting PDF to Image
Date Thu, 06 Jun 2013 10:44:05 GMT
Hi,
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());
if (result)
    Console.WriteLine("successful");
else
    Console.WriteLine("failed");

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);
Console.WriteLine("done");

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 .

Thank you.

Regards,

Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message