You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Ad...@swmc.com on 2011/04/21 21:55:17 UTC

Converting an image to a PDF

I'm looking for a way to convert an image to a PDF.  I found 
org.apache.pdfbox.examples.pdmodel.ImageToPDF which looks like it'll work 
for JPG and TIF files, but it doesn't seem to support PNG (or any other 
type for that matter).  I traced through the library a little and found 
some code that was commented out which uses a PDPixelMap, but the 
constructor which takes a BufferedImage no longer exists.  The comments 
around there say "This method is broken and needs to be implemented" which 
is a bit discouraging.

So my basic question is this: Is there an easy way to convert a PNG to a 
PDF?

If so, do I need to worry about things like scaling, images becoming 
blurry or too small to see/read, large images getting cut off b/c they 
don't fit on a page, etc.?

---- 
Thanks,
Adam

- FHA 203b; 203k; HECM; VA; USDA; Conventional 
- Warehouse Lines; FHA-Authorized Originators 
- Lending and Servicing in over 45 States 
www.swmc.com   -  www.simplehecmcalculator.com   Visit  www.swmc.com/resources   for helpful links on Training, Webinars, Lender Alerts and Submitting Conditions  
This email and any content within or attached hereto from Sun West Mortgage Company, Inc. is confidential and/or legally privileged. The information is intended only for the use of the individual or entity named on this email. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this email information is strictly prohibited, and that the documents should be returned to this office immediately by email. Receipt by anyone other than the intended recipient is not a waiver of any privilege. Please do not include your social security number, account number, or any other personal or financial information in the content of the email. Should you have any questions, please call (800) 453 7884.  

Re: Converting an image to a PDF

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Try Apache FOP: http://xmlgraphics.apache.org/fop/.

It has very good support for many different image types. Just download
it and try it from the command-line:

fop -imagein myimage.png -pdf myimage.pdf

On 22.04.2011 02:01:50 Adam wrote:
> I see.  I also found out that converting to a TIF was not a trivial task, 
> so I went with the PNG -> JPG -> [Resized JPG to fit on page ->] PDF 
> route.  Not the best solution, but it's good enough to suit my needs.
> 
> If anyone wants to work on the PDPixelMap(PDDocument doc, BufferedImage 
> awtImage) constructor, this sounds like it's the answer to embed any image 
> into a PDF.
> 
> ---- 
> Thanks,
> Adam
> 
> 
> 
> From:
> Russ Pridemore <ru...@gmail.com>
> To:
> users@pdfbox.apache.org
> Date:
> 04/21/2011 14:07
> Subject:
> Re: Converting an image to a PDF
> 
> 
> 
> Yes, I can confirm that works, but may not produce acceptable results
> depending on the image.  JPG is not optimal for many types of images.  I
> have the same issue with pdfbox...
> 
> Russ
> On Apr 21, 2011 4:38 PM, "Ken Bowen" <ke...@form-runner.com> wrote:
> > Adam,
> >
> > Why not do a separate conversion of the PNG to JPEG first, and then
> convert the JPEG to PDF? There are many tools (if it's only a one-off or
> two) and libraries (for a pipeline) out there. I even think you could
> probably do the conversion using the basic JVM 1.6 AWT facilities.
> >
> > Ken
> >
> > On Apr 21, 2011, at 3:55 PM, Adam@swmc.com wrote:
> >
> >> I'm looking for a way to convert an image to a PDF. I found
> >> org.apache.pdfbox.examples.pdmodel.ImageToPDF which looks like it'll 
> work
> 
> >> for JPG and TIF files, but it doesn't seem to support PNG (or any other
> >> type for that matter). I traced through the library a little and found
> >> some code that was commented out which uses a PDPixelMap, but the
> >> constructor which takes a BufferedImage no longer exists. The comments
> >> around there say "This method is broken and needs to be implemented"
> which
> >> is a bit discouraging.
> >>
> >> So my basic question is this: Is there an easy way to convert a PNG to 
> a
> >> PDF?
> >>
> >> If so, do I need to worry about things like scaling, images becoming
> >> blurry or too small to see/read, large images getting cut off b/c they
> >> don't fit on a page, etc.?
> >>
> >> ----
> >> Thanks,
> >> Adam
> >>
> >> - FHA 203b; 203k; HECM; VA; USDA; Conventional
> >> - Warehouse Lines; FHA-Authorized Originators
> >> - Lending and Servicing in over 45 States
> >> www.swmc.com - www.simplehecmcalculator.com Visit 
> www.swmc.com/resourcesfor helpful links on Training, Webinars, Lender 
> Alerts and Submitting
> Conditions
> >> This email and any content within or attached hereto from Sun West
> Mortgage Company, Inc. is confidential and/or legally privileged. The
> information is intended only for the use of the individual or entity named
> on this email. If you are not the intended recipient, you are hereby
> notified that any disclosure, copying, distribution or taking any action 
> in
> reliance on the contents of this email information is strictly prohibited,
> and that the documents should be returned to this office immediately by
> email. Receipt by anyone other than the intended recipient is not a waiver
> of any privilege. Please do not include your social security number, 
> account
> number, or any other personal or financial information in the content of 
> the
> email. Should you have any questions, please call (800) 453 7884.
> >
> 
> 
> 
> 
> 
> - FHA 203b; 203k; HECM; VA; USDA; Conventional 
> - Warehouse Lines; FHA-Authorized Originators 
> - Lending and Servicing in over 45 States 
> www.swmc.com   -  www.simplehecmcalculator.com   Visit  www.swmc.com/resources   for helpful links on Training, Webinars, Lender Alerts and Submitting Conditions  
> This email and any content within or attached hereto from Sun West Mortgage Company, Inc. is confidential and/or legally privileged. The information is intended only for the use of the individual or entity named on this email. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this email information is strictly prohibited, and that the documents should be returned to this office immediately by email. Receipt by anyone other than the intended recipient is not a waiver of any privilege. Please do not include your social security number, account number, or any other personal or financial information in the content of the email. Should you have any questions, please call (800) 453 7884.  




Jeremias Maerki


Re: Converting an image to a PDF

Posted by Ad...@swmc.com.
I see.  I also found out that converting to a TIF was not a trivial task, 
so I went with the PNG -> JPG -> [Resized JPG to fit on page ->] PDF 
route.  Not the best solution, but it's good enough to suit my needs.

If anyone wants to work on the PDPixelMap(PDDocument doc, BufferedImage 
awtImage) constructor, this sounds like it's the answer to embed any image 
into a PDF.

---- 
Thanks,
Adam



From:
Russ Pridemore <ru...@gmail.com>
To:
users@pdfbox.apache.org
Date:
04/21/2011 14:07
Subject:
Re: Converting an image to a PDF



Yes, I can confirm that works, but may not produce acceptable results
depending on the image.  JPG is not optimal for many types of images.  I
have the same issue with pdfbox...

Russ
On Apr 21, 2011 4:38 PM, "Ken Bowen" <ke...@form-runner.com> wrote:
> Adam,
>
> Why not do a separate conversion of the PNG to JPEG first, and then
convert the JPEG to PDF? There are many tools (if it's only a one-off or
two) and libraries (for a pipeline) out there. I even think you could
probably do the conversion using the basic JVM 1.6 AWT facilities.
>
> Ken
>
> On Apr 21, 2011, at 3:55 PM, Adam@swmc.com wrote:
>
>> I'm looking for a way to convert an image to a PDF. I found
>> org.apache.pdfbox.examples.pdmodel.ImageToPDF which looks like it'll 
work

>> for JPG and TIF files, but it doesn't seem to support PNG (or any other
>> type for that matter). I traced through the library a little and found
>> some code that was commented out which uses a PDPixelMap, but the
>> constructor which takes a BufferedImage no longer exists. The comments
>> around there say "This method is broken and needs to be implemented"
which
>> is a bit discouraging.
>>
>> So my basic question is this: Is there an easy way to convert a PNG to 
a
>> PDF?
>>
>> If so, do I need to worry about things like scaling, images becoming
>> blurry or too small to see/read, large images getting cut off b/c they
>> don't fit on a page, etc.?
>>
>> ----
>> Thanks,
>> Adam
>>
>> - FHA 203b; 203k; HECM; VA; USDA; Conventional
>> - Warehouse Lines; FHA-Authorized Originators
>> - Lending and Servicing in over 45 States
>> www.swmc.com - www.simplehecmcalculator.com Visit 
www.swmc.com/resourcesfor helpful links on Training, Webinars, Lender 
Alerts and Submitting
Conditions
>> This email and any content within or attached hereto from Sun West
Mortgage Company, Inc. is confidential and/or legally privileged. The
information is intended only for the use of the individual or entity named
on this email. If you are not the intended recipient, you are hereby
notified that any disclosure, copying, distribution or taking any action 
in
reliance on the contents of this email information is strictly prohibited,
and that the documents should be returned to this office immediately by
email. Receipt by anyone other than the intended recipient is not a waiver
of any privilege. Please do not include your social security number, 
account
number, or any other personal or financial information in the content of 
the
email. Should you have any questions, please call (800) 453 7884.
>





- FHA 203b; 203k; HECM; VA; USDA; Conventional 
- Warehouse Lines; FHA-Authorized Originators 
- Lending and Servicing in over 45 States 
www.swmc.com   -  www.simplehecmcalculator.com   Visit  www.swmc.com/resources   for helpful links on Training, Webinars, Lender Alerts and Submitting Conditions  
This email and any content within or attached hereto from Sun West Mortgage Company, Inc. is confidential and/or legally privileged. The information is intended only for the use of the individual or entity named on this email. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this email information is strictly prohibited, and that the documents should be returned to this office immediately by email. Receipt by anyone other than the intended recipient is not a waiver of any privilege. Please do not include your social security number, account number, or any other personal or financial information in the content of the email. Should you have any questions, please call (800) 453 7884.  

Re: Converting an image to a PDF

Posted by Russ Pridemore <ru...@gmail.com>.
Yes, I can confirm that works, but may not produce acceptable results
depending on the image.  JPG is not optimal for many types of images.  I
have the same issue with pdfbox...

Russ
On Apr 21, 2011 4:38 PM, "Ken Bowen" <ke...@form-runner.com> wrote:
> Adam,
>
> Why not do a separate conversion of the PNG to JPEG first, and then
convert the JPEG to PDF? There are many tools (if it's only a one-off or
two) and libraries (for a pipeline) out there. I even think you could
probably do the conversion using the basic JVM 1.6 AWT facilities.
>
> Ken
>
> On Apr 21, 2011, at 3:55 PM, Adam@swmc.com wrote:
>
>> I'm looking for a way to convert an image to a PDF. I found
>> org.apache.pdfbox.examples.pdmodel.ImageToPDF which looks like it'll work

>> for JPG and TIF files, but it doesn't seem to support PNG (or any other
>> type for that matter). I traced through the library a little and found
>> some code that was commented out which uses a PDPixelMap, but the
>> constructor which takes a BufferedImage no longer exists. The comments
>> around there say "This method is broken and needs to be implemented"
which
>> is a bit discouraging.
>>
>> So my basic question is this: Is there an easy way to convert a PNG to a
>> PDF?
>>
>> If so, do I need to worry about things like scaling, images becoming
>> blurry or too small to see/read, large images getting cut off b/c they
>> don't fit on a page, etc.?
>>
>> ----
>> Thanks,
>> Adam
>>
>> - FHA 203b; 203k; HECM; VA; USDA; Conventional
>> - Warehouse Lines; FHA-Authorized Originators
>> - Lending and Servicing in over 45 States
>> www.swmc.com - www.simplehecmcalculator.com Visit www.swmc.com/resourcesfor helpful links on Training, Webinars, Lender Alerts and Submitting
Conditions
>> This email and any content within or attached hereto from Sun West
Mortgage Company, Inc. is confidential and/or legally privileged. The
information is intended only for the use of the individual or entity named
on this email. If you are not the intended recipient, you are hereby
notified that any disclosure, copying, distribution or taking any action in
reliance on the contents of this email information is strictly prohibited,
and that the documents should be returned to this office immediately by
email. Receipt by anyone other than the intended recipient is not a waiver
of any privilege. Please do not include your social security number, account
number, or any other personal or financial information in the content of the
email. Should you have any questions, please call (800) 453 7884.
>

Re: Converting an image to a PDF

Posted by Ken Bowen <ke...@form-runner.com>.
Adam,

Why not do a separate conversion of the PNG to JPEG first, and then convert the JPEG to PDF?  There are many tools (if it's only a one-off or two) and libraries (for a pipeline) out there.  I even think you could probably do the conversion using the basic JVM 1.6 AWT facilities.

Ken

On Apr 21, 2011, at 3:55 PM, Adam@swmc.com wrote:

> I'm looking for a way to convert an image to a PDF.  I found 
> org.apache.pdfbox.examples.pdmodel.ImageToPDF which looks like it'll work 
> for JPG and TIF files, but it doesn't seem to support PNG (or any other 
> type for that matter).  I traced through the library a little and found 
> some code that was commented out which uses a PDPixelMap, but the 
> constructor which takes a BufferedImage no longer exists.  The comments 
> around there say "This method is broken and needs to be implemented" which 
> is a bit discouraging.
> 
> So my basic question is this: Is there an easy way to convert a PNG to a 
> PDF?
> 
> If so, do I need to worry about things like scaling, images becoming 
> blurry or too small to see/read, large images getting cut off b/c they 
> don't fit on a page, etc.?
> 
> ---- 
> Thanks,
> Adam
> 
> - FHA 203b; 203k; HECM; VA; USDA; Conventional 
> - Warehouse Lines; FHA-Authorized Originators 
> - Lending and Servicing in over 45 States 
> www.swmc.com   -  www.simplehecmcalculator.com   Visit  www.swmc.com/resources   for helpful links on Training, Webinars, Lender Alerts and Submitting Conditions  
> This email and any content within or attached hereto from Sun West Mortgage Company, Inc. is confidential and/or legally privileged. The information is intended only for the use of the individual or entity named on this email. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this email information is strictly prohibited, and that the documents should be returned to this office immediately by email. Receipt by anyone other than the intended recipient is not a waiver of any privilege. Please do not include your social security number, account number, or any other personal or financial information in the content of the email. Should you have any questions, please call (800) 453 7884.  


RE: Converting an image to a PDF

Posted by Eric Douglas <ed...@blockhouse.com>.
I'm using the org.apache.pdfbox.pdfviewer.PageDrawer class to draw an
image of a PDF and it doesn't look quite the same.  Surely the method I
came up with to draw lines on the pages of the PDF is not the best but
they look fine in the PDF and don't come up on the drawing.  I think
it's a layering issue, that the PDF has multiple objects positioned on
top each other and they're getting hidden in the graphic drawing.
 

-----Original Message-----
From: Adam@swmc.com [mailto:Adam@swmc.com] 
Sent: Thursday, April 21, 2011 3:55 PM
To: users@pdfbox.apache.org
Subject: Converting an image to a PDF

I'm looking for a way to convert an image to a PDF.  I found
org.apache.pdfbox.examples.pdmodel.ImageToPDF which looks like it'll
work for JPG and TIF files, but it doesn't seem to support PNG (or any
other type for that matter).  I traced through the library a little and
found some code that was commented out which uses a PDPixelMap, but the
constructor which takes a BufferedImage no longer exists.  The comments
around there say "This method is broken and needs to be implemented"
which is a bit discouraging.

So my basic question is this: Is there an easy way to convert a PNG to a
PDF?

If so, do I need to worry about things like scaling, images becoming
blurry or too small to see/read, large images getting cut off b/c they
don't fit on a page, etc.?

----
Thanks,
Adam

- FHA 203b; 203k; HECM; VA; USDA; Conventional
- Warehouse Lines; FHA-Authorized Originators
- Lending and Servicing in over 45 States 
www.swmc.com   -  www.simplehecmcalculator.com   Visit
www.swmc.com/resources   for helpful links on Training, Webinars, Lender
Alerts and Submitting Conditions  
This email and any content within or attached hereto from Sun West
Mortgage Company, Inc. is confidential and/or legally privileged. The
information is intended only for the use of the individual or entity
named on this email. If you are not the intended recipient, you are
hereby notified that any disclosure, copying, distribution or taking any
action in reliance on the contents of this email information is strictly
prohibited, and that the documents should be returned to this office
immediately by email. Receipt by anyone other than the intended
recipient is not a waiver of any privilege. Please do not include your
social security number, account number, or any other personal or
financial information in the content of the email. Should you have any
questions, please call (800) 453 7884.