You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Ivan Ridao Freitas <in...@ivanrf.com> on 2016/03/24 19:34:02 UTC

Add SVG image to PDF

Hi, I would like to know if it possible to insert SVG images into a PDF 
with PDFBox 2.0.0.

In this old thread 
<http://pdfbox-users.markmail.org/search/?q=Toni+Helenius#query:Toni%20Helenius%20order%3Adate-backward+page:1+mid:6pncjl43qdhgiz35+state:results> 
it is mentioned to use Apache Batik to convert SVG to PDF and then 
import on PDFBox.
Is this still the best procedure?

I'm currently filling a PDF form with PDFBox which has an SVG on it. 
Now, I want to do everything from the software. The SVG image is the 
only thing I don't know how to add and I would like to avoid using PNG 
files instead of a vector.

Thanks,
Ivan

PS: This was also asked by other user at Stackoverflow here 
<http://stackoverflow.com/questions/31718075/drawing-vector-images-on-pdf-with-pdfbox>.

Re: Add SVG image to PDF

Posted by John Hewson <jo...@jahewson.com>.
> On 24 Mar 2016, at 11:34, Ivan Ridao Freitas <in...@ivanrf.com> wrote:
> 
> Hi, I would like to know if it possible to insert SVG images into a PDF with PDFBox 2.0.0.
> 
> In this old thread <http://pdfbox-users.markmail.org/search/?q=Toni+Helenius#query:Toni%20Helenius%20order%3Adate-backward+page:1+mid:6pncjl43qdhgiz35+state:results> it is mentioned to use Apache Batik to convert SVG to PDF and then import on PDFBox.
> Is this still the best procedure?

Yes, this remains the best approach. You can import the PDF created by Batik as a PDFFormXObject, which can be scaled and placed on the page as you wish.

If your SVG is trivial and always in some standard format (i.e. if it’s generated by some other software tool) then you could consider parsing the SVG file yourself and then just drawing the corresponding paths. I’ve done this for trivial black and white outlines before. But for anything non-trivial I’d certainly choose the Batik approach.

— John

> I'm currently filling a PDF form with PDFBox which has an SVG on it. Now, I want to do everything from the software. The SVG image is the only thing I don't know how to add and I would like to avoid using PNG files instead of a vector.
> 
> Thanks,
> Ivan
> 
> PS: This was also asked by other user at Stackoverflow here <http://stackoverflow.com/questions/31718075/drawing-vector-images-on-pdf-with-pdfbox>.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Add SVG image to PDF

Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Am 24.03.2016 um 19:34 schrieb Ivan Ridao Freitas:
> Hi, I would like to know if it possible to insert SVG images into a PDF with
> PDFBox 2.0.0.
>
> In this old thread
> <http://pdfbox-users.markmail.org/search/?q=Toni+Helenius#query:Toni%20Helenius%20order%3Adate-backward+page:1+mid:6pncjl43qdhgiz35+state:results>
> it is mentioned to use Apache Batik to convert SVG to PDF and then import on
> PDFBox.
> Is this still the best procedure?
Yes.

BR
Andreas
> I'm currently filling a PDF form with PDFBox which has an SVG on it. Now, I want
> to do everything from the software. The SVG image is the only thing I don't know
> how to add and I would like to avoid using PNG files instead of a vector.
>
> Thanks,
> Ivan
>
> PS: This was also asked by other user at Stackoverflow here
> <http://stackoverflow.com/questions/31718075/drawing-vector-images-on-pdf-with-pdfbox>.
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Text overlap

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 09.05.2016 um 02:30 schrieb Ivan Ridao Freitas:
> Hi, I'm designing an invoice with PDFBox. The only doubt I have is how 
> to control text overlapping?
> For example, if one line has a text at (x=10) and another at (x=100), 
> how can I prevent the first text to overlap the second one.
> I'm adding text with:
>         content.beginText();
>         content.newLineAtOffset(x, y);
>         content.showText(text);
>         content.endText();
>
> I know how to calculate the string width and I could cut it until it 
> fits, but is that the only approach?
> Should I consider inserting a form field and then set the text to a 
> PDTextField?

What I've seen in PDFs "in the wild" is this:

- save graphics
- rectangle
- set clipping path
- draw your text
- restore graphics


Another strategy, if you want to avoid cutting off, is to use a smaller 
font if the text gets too large, or a narrow  font (Arial narrow).

Tilman

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Text overlap

Posted by Ivan Ridao Freitas <in...@ivanrf.com>.
Hi, I'm designing an invoice with PDFBox. The only doubt I have is how 
to control text overlapping?
For example, if one line has a text at (x=10) and another at (x=100), 
how can I prevent the first text to overlap the second one.
I'm adding text with:
         content.beginText();
         content.newLineAtOffset(x, y);
         content.showText(text);
         content.endText();

I know how to calculate the string width and I could cut it until it 
fits, but is that the only approach?
Should I consider inserting a form field and then set the text to a 
PDTextField?

Thanks,
Ivan