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/05/10 16:38:52 UTC

Draw Graphics in a PDF

Is it possible to draw a java.awt.Graphics in a PDF?

I read in previous question from 2009 and 2013 that is not implemented 
and will not be.

Would it be possible to add that feature to PDFBox 2.x?

Currently, I'm using Barcode4J which generates an SVG, EPS, Image or 
Java2D. I'm doing fine with the PNG option. I wanted to use SVG for 
quality but I was not able to. So, my last option is Java2D.

Drawing Graphics on a PDF would have the same quality as a SVG? or using 
SVG format is the only way to draw inside a PDF?

Thanks!
Ivan

Re: Draw Graphics in a PDF

Posted by John Hewson <jo...@jahewson.com>.
> On 10 May 2016, at 16:15, Ivan Ridao Freitas <in...@ivanrf.com> wrote:
> 
> I got the code working for horizontal barcodes, looks great! just like an SVG. In fact, is better since I can select the code text :)
> 
> Question: the function that draws the text has the parameter "String fontName". How can I get a PDType1Font by name?

We don’t have an API to do that but you could just map some known font names to the built-in fonts such as Helvetica or Courier.

— John

> For now, I'm using PDType1Font.HELVETICA which is also the default font for Barcode4J.
> 
> I will try to make a post with the code when I finish it. It would be nice to send it to the Barcode4J project, but last release was on 2010...
> 
> Ivan
> On 10/5/2016 4:19 p. m., John Hewson wrote:
>> We often get people asking about Barcode4J, so feel free to share the resulting code, if possible. There will be interest.
>> 
>> — John
> 


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


Re: Draw Graphics in a PDF

Posted by Ivan Ridao Freitas <in...@ivanrf.com>.
I got the code working for horizontal barcodes, looks great! just like 
an SVG. In fact, is better since I can select the code text :)

Question: the function that draws the text has the parameter "String 
fontName". How can I get a PDType1Font by name?

For now, I'm using PDType1Font.HELVETICA which is also the default font 
for Barcode4J.

I will try to make a post with the code when I finish it. It would be 
nice to send it to the Barcode4J project, but last release was on 2010...

Ivan
On 10/5/2016 4:19 p. m., John Hewson wrote:
> We often get people asking about Barcode4J, so feel free to share the resulting code, if possible. There will be interest.
>
> \u2014 John


Re: Draw Graphics in a PDF

Posted by John Hewson <jo...@jahewson.com>.
> On 10 May 2016, at 11:35, Ivan Ridao Freitas <in...@ivanrf.com> wrote:
> 
> Thanks for your reply! it made me realize that I can write a CanvasProvider to draw a barcode and its as easy as draw rectangles and text on a PDPageContentStream. :)

We often get people asking about Barcode4J, so feel free to share the resulting code, if possible. There will be interest.

— John

> Ivan
> On 10/5/2016 2:40 p. m., John Hewson wrote:
>>> Currently, I'm using Barcode4J which generates an SVG, EPS, Image or Java2D. I'm doing fine with the PNG option. I wanted to use SVG for quality but I was not able to. So, my last option is Java2D.
>> You’re likely after only a handful of drawing commands, you could use Java2D’s DebugGraphics to find out which ones and then it wouldn’t be hard to write an absolutely minimal Graphics implementation which draws to a PDPageContentStream.
>> 
>>> >Drawing Graphics on a PDF would have the same quality as a SVG? or using SVG format is the only way to draw inside a PDF?
>> Drawing with a PDPageContentStream gives you vector graphics equivalent in quality to SVG, EPS, Java2D, etc.
>> 
>> — John
>> 
> 


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


Re: Draw Graphics in a PDF

Posted by Ivan Ridao Freitas <in...@ivanrf.com>.
Thanks for your reply! it made me realize that I can write a 
CanvasProvider to draw a barcode and its as easy as draw rectangles and 
text on a PDPageContentStream. :)

Ivan
On 10/5/2016 2:40 p. m., John Hewson wrote:
>> Currently, I'm using Barcode4J which generates an SVG, EPS, Image or Java2D. I'm doing fine with the PNG option. I wanted to use SVG for quality but I was not able to. So, my last option is Java2D.
> You\u2019re likely after only a handful of drawing commands, you could use Java2D\u2019s DebugGraphics to find out which ones and then it wouldn\u2019t be hard to write an absolutely minimal Graphics implementation which draws to a PDPageContentStream.
>
>> >Drawing Graphics on a PDF would have the same quality as a SVG? or using SVG format is the only way to draw inside a PDF?
> Drawing with a PDPageContentStream gives you vector graphics equivalent in quality to SVG, EPS, Java2D, etc.
>
> \u2014 John
>


Re: Draw Graphics in a PDF

Posted by John Hewson <jo...@jahewson.com>.
> On 10 May 2016, at 09:38, Ivan Ridao Freitas <in...@ivanrf.com> wrote:
> 
> Is it possible to draw a java.awt.Graphics in a PDF?

No, it’s not.

> 
> I read in previous question from 2009 and 2013 that is not implemented and will not be.
> 
> Would it be possible to add that feature to PDFBox 2.x?

Probably not because AWT has its own notions of Font and Paint which are different from
those found in PDFBox.

> Currently, I'm using Barcode4J which generates an SVG, EPS, Image or Java2D. I'm doing fine with the PNG option. I wanted to use SVG for quality but I was not able to. So, my last option is Java2D.

You’re likely after only a handful of drawing commands, you could use Java2D’s DebugGraphics to find out which ones and then it wouldn’t be hard to write an absolutely minimal Graphics implementation which draws to a PDPageContentStream.

> Drawing Graphics on a PDF would have the same quality as a SVG? or using SVG format is the only way to draw inside a PDF?

Drawing with a PDPageContentStream gives you vector graphics equivalent in quality to SVG, EPS, Java2D, etc.

— John

> Thanks!
> Ivan


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