pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Wilson <williamstonconsult...@gmail.com>
Subject Re: PDFBox in .NET for converting PDF to Image
Date Thu, 06 Jun 2013 13:20:29 GMT
You need to write a .Net class that inherits PageDrawer and overrides
several of its methods using the .Net drawing library --
System.Graphics.Drawing, iirc.

I did this very successfully for a company I worked for and it's in their
product today ... so the concept is sound.  The details escape me right now
... and I couldn't really share the code I created for them anyway.


On Thu, Jun 6, 2013 at 6:44 AM, blogrongchaua . <
blogrongchaua@googlemail.com> wrote:

> 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/alternative (inline, None, 0 bytes)
View raw message