You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@incubator.apache.org by Angelo zerr <an...@gmail.com> on 2011/09/05 10:11:27 UTC

Re: Replace itext with PDFBox for XDocReport project?

Hi PDFBox Team,

I suppose that my post was not well explained as I have no answer. I will be
very happy to use PDFBox in our XDocReport converter (docx-> PDF and odt->
PDF) but develop converter is a big work and I can not investiaget time if I
have no support.

The big problem with PDFBox is that it doesn't provide complex widget. Yes
we can do it (liek
http://fahdshariff.blogspot.com/2010/10/creating-tables-with-pdfbox.html),
but IMHO I think PDFBox should provide widgets like table, table-row,
chapter, section, etc like iText. I hope you will understand my idea (I
apologize if you think I offend you).

There is somebody in the XDocReport forum (please see at
http://groups.google.com/group/xdocreport/browse_thread/thread/3f453ed7e53f1ebd)
who want implement a converter with PDFBox but he doesn't know very well
PDFBox. I suggest him to implement at first PDFBox widgets. If he can do it
an dif he agree, I think it should be cool if he can contribute to PDFBox
widgets.

Thank a lot for your help.

Regards Angelo

2011/8/12 Angelo zerr <an...@gmail.com>

> Hi PDFBox Team,
>
> I introduce to me. I'm Angelo ZERR, one of developer of XDocRepor
> <http://code.google.com/p/xdocreport/>It's Java API to merge XML document
> created with MS Office <http://office.microsoft.com/fr-fr/> (docx) or
> OpenOffice <http://www.openoffice.org/> (odt), LibreOffice<http://www.libreoffice.org/>(odt) with a Java model to generate report and convert it if you need to
> another format (PDF, XHTML...).
>
> * To convert ODT -> PDF, process is to load ODT with ODFDOM and loop for
> each Java ODFDOM structure to create iText widget. Please read
> http://code.google.com/p/xdocreport/wiki/ODFDOMConverter
> * To convert Docx -> PDF, process is to load docx with POI (HWPF) and loop
> for each Java HWPF structure to create iText widget. Please read
> http://code.google.com/p/xdocreport/wiki/XWPFConverter
>
> You can play with XDocReport at
> http://xdocreport.opensagres.cloudbees.net/processReport.jsp where you can
> generate report and convert it to XHTML:PDF (select the converter combo). An
> iframe display the result of the report converted. If you change the data
> model of the form, iframe is refreshed at runtime. So you can evaluate the
> performance of the XDocReport.
>
> XDocReport provides Java converter for docx and odt. We wish gives our 2
> converter for POI and ODFDOM (soon Apache) but problem is itext license. So
> we tell us if we could replace itext with PDFBox to manage converter for odt
> and docx. odt and docx can be complex like Table, image in a table cell,
> etc... and it seems that PDFPox doesn't support widget Table (just find this
> article
> http://fahdshariff.blogspot.com/2010/10/creating-tables-with-pdfbox.htmlbut if we wish manage images in a table cell, etc...I would like avoid
> implementing my own widgets).
>
> For performance have you doen benchmark (itext VS PDFBox).
>
> Thank a lot for your answer.
>
> Regards Angelo
>
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Kévin Sailly <ke...@gmail.com>.
ok, no problem

2011/10/18 Angelo zerr <an...@gmail.com>

> Hi Kevin,
>
> Thank a lot for your information. I have studied PDFBox and FOP with only
> Java and I though FOP with only Java (Graphics2D) is the best solution
> because
> you can export it to another format than PDF. More Jeremias motivated me to
> use FOP because it seems I will have some support with FOP.
>
> The only problem (with FOP or PDFBox) is the layout and it's a complex
> thing
> to do. I have started to develop that but it's a big work and before
> developing that I must finish our
> Eclipse RCP/RAP demo wich generate report and export it to PDF at
>
> http://xdocreport-rap.opensagres.cloudbees.net/xdocreport?startup=fr.opensagres.xdocreport.eclipse.application
>
> Regards Angelo
>
> 2011/10/18 Kévin Sailly <ke...@gmail.com>
>
> > Hello Angello,
> >
> > I found out that to get the text justified, I have to use the
> > appendRawCommands method on PDPageContentStream to adjust the space
> between
> > letters and words, using raw commands Tc and Tw from PDF reference.
> >
> > I am just surprised that this commands are not implemented on
> > PDPageContentStream, as this representing no such code:
> >    private static final String SET_CHAR_SPACING = "Tc\n";
> >    private static final String SET_WORD_SPACING = "Tw\n";
> >
> >
> >    public void setCharSpace( float charSpace ) throws IOException
> >    {
> >        appendRawCommands( formatDecimal.format( charSpace ) );
> >        appendRawCommands( SPACE );
> >        appendRawCommands( SET_CHAR_SPACING );
> >    }
> >
> >    public void setWordSpace( float charSpace ) throws IOException
> >    {
> >        appendRawCommands( formatDecimal.format( charSpace ) );
> >        appendRawCommands( SPACE );
> >        appendRawCommands( SET_WORD_SPACING );
> >    }
> >
> > or something like that!
> >
> >
> >
> > 2011/10/16 Angelo zerr <an...@gmail.com>
> >
> > > Hi Jeremias,
> > >
> > > Many thanks for your great explanation! I'm very motivated to study
> > > PDFDocumentGraphics2D with your explanation and your support.
> > > I would like create the same API than iText (Paragraph, Table, etc)
> with
> > > FOP
> > > (or PDFBox) and use it for our converterODF/OOXML.
> > > I would like avoid managing layout for docx and layour for odt, but use
> > in
> > > the 2 cases the Paragraph, Table structures that I would like provides
> > with
> > > FOP or PDFBox.
> > > I have started to manage that with PDFBox (but with FOP it will be same
> > > thing) and I track x and y when I add a structure (to compute x/y
> > position
> > > and know if new page must be added) :
> > >
> > > ex:
> > > -----------------------------------------------------------
> > > Document doc=new Document()
> > > Paragrapf p = new Paragraph();
> > > p.addRun(new Run("AAAA"));
> > > p.addRun(new Run(" "));
> > > p.addRun(new Run("BBBB"));
> > > doc.addParagraph(p);
> > >
> > > doc.save("test.pdf"); // <= here it loops to each structure and compute
> > x,
> > > y
> > > position, after coputing that it render each structure.
> > > -----------------------------------------------------------
> > >
> > > I don't know how to manage layout (x and y position) with a different
> > > means?
> > >
> > > Anyway thank a lot for your great help.
> > >
> > > Regards Angelo
> > >
> > > 2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>
> > >
> > > > Hi Angelo
> > > >
> > > > PDFDocumentGraphics2D is a Graphics2D subclass, so the API is stable.
> > > > The only thing special to it is the font and page size setup and the
> > > > nextPage() method.
> > > >
> > > > You program once against a Graphics2D object to paint individual
> pages
> > > > and that allows you to paint on the Screen (AWT/Swing), print to a
> > > > printer (javax.print) or to create SVG (SVGGraphics2D from Apache
> > Batik),
> > > > PDF (PDFDocumentGraphics2D from Apache FOP), PostScript
> > > > (PSDocumentGraphics2D from Apache XML Graphics Commons) or whatever.
> I
> > > > think iText has a Graphics2D implementation, too. We could even write
> > > > one for PDFBox.
> > > >
> > > > PDFBox already has the opposite direction: it takes a PDF page and
> can
> > > > paint it on a Graphics2D object. That's how it does PDF2Image and how
> > > > the PDFReader displays the PDF contents.
> > > >
> > > > Graphics2D is a vector graphics painting API suitable for a single
> > > > page/box/screen. It works with absolute coordinates. You can use it
> to
> > > > create paged documents. There are tools in java.awt.text that help
> > > > laying out text but it's no full layout engine.
> > > >
> > > > Word processing documents (ODF/OOXML/DOC) are flow-oriented formats,
> > > > just like HTML and XSL-FO. It's the job of a formatting engine (like
> > > > Apache FOP) to turn that into a paged format, i.e. from not having to
> > > > track X/Y to absolute positioning on a page. It does line breaking
> und
> > > > checks how many lines fit into a page and continues on a new page if
> an
> > > > overflow occurs (that's simplified).
> > > >
> > > > Apparently, you have a nice API in iText that allows you to build up
> > the
> > > > PDF by adding paragraphs and runs where you don't have to worry about
> > > > line breaking, hyphenation and page breaks. That means, iText has at
> > > > least a simple formatting engine built in. PDFBox doesn't have that
> > > (yet).
> > > > FOP has a sophisticated one for XSL-FO. Apache Batik has one for the
> > SVG
> > > > flow-text feature (using java.text.AttributedCharacterIterator, but
> > > > heavily relying on their internal GVT framework).
> > > >
> > > > The JDK has one in javax.swing.text (rendering Text, HTML and RTF,
> also
> > > > using java.awt.font and java.text) although I'm starting to believe
> > that
> > > > it only supports line-breaking, not page breaking. That's the one I
> > used
> > > > in the example for PDFDocumentGraphics2D. I can't tell if that would
> > > > make a good basis for a simple layout engine for PDFBox. But I
> > certainly
> > > > think it might be possible to reuse some of that and try to build a
> > > > simple page breaker on top of that. I think that might actually one
> of
> > > > the best option for have something useful relatively quickly but it
> > > > might not fit for all possible features that ODF/OOXML offer.
> > > >
> > > > So, in the end I don't think you can get around to find or program
> some
> > > > kind of formatter/layout engine that handles the transition from
> > > > flow-based to absolute text, when you go from ODF/OOXML to PDF.
> > > >
> > > > Doing that on an engine that does not directly depend on PDFBox would
> > > > allow you to cater for more than just PDF (taking XDocReport's and
> ODF
> > > > Toolkit's view). That's why I suggested to have a look at FOP's
> > > > intermediate format. Because if you can generate that format you have
> > > > immediate access to all paged output formats that FOP supports (PDF,
> > PS,
> > > > AFP, PCL, TIFF, Print). To a lesser degree the same is also possible
> if
> > > > you program against Graphics2D because you can then also produce
> > various
> > > > output formats (see the list of Graphics2D implementations that I
> gave
> > > > above).
> > > >
> > > > Please note: I don't want to deny PDFBox a nice simple
> (flow-oriented)
> > > > API for generating PDFs or a Graphics2D implementation. I'm just
> > > > pointing out possible directions.
> > > >
> > > > And the bitter pill at the end: doing layout can be real hard. I'm
> > > > speaking from experience.
> > > >
> > > > On 15.10.2011 14:09:20 Angelo zerr wrote:
> > > > > Hi Jeremias ,
> > > > >
> > > > > Wow thta's a very cool sample! Thank a lot.
> > > > >
> > > > > With you sample I must manage x and y position that I have started
> > with
> > > > > PDFBox implementation.
> > > > > It seems that PDFDocumentGraphics2D  looks like PDPageContentStream
> > > (draw
> > > > > string, set font, color, exc).
> > > > >
> > > > > So my question what is advantage to use PDFDocumentGraphics2D from
> > FOP
> > > > > instead of PDPageContentStream from PDFBox?
> > > > > PDFDocumentGraphics2D  is an API stable?
> > > > >
> > > > > Thank a lot for your answer.
> > > > >
> > > > > Regards Angelo
> > > > >
> > > > > 2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>
> > > > >
> > > > > > It turned out PDFDocumentGraphics2D was not so operational
> anymore.
> > > > > > Somewhere along the way it broke. I've fixed it again [1] and
> added
> > a
> > > > > > usage example [2]. That means you'll have to download FOP Trunk
> > [3].
> > > > > >
> > > > > > [1] http://svn.apache.org/viewvc?rev=1183620&view=rev
> > > > > > [2]
> > > > > >
> > > >
> > >
> >
> http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleJava2D2PDF.java?view=markup
> > > > > > [3] http://xmlgraphics.apache.org/fop/download.html
> > > > > >
> > > > > > But guys, talking about PDFDocumentGraphics2D is getting very
> > > off-topic
> > > > > > for this list. Please take that part to
> > > > fop-users@xmlgraphics.apache.org
> > > > > > from here.
> > > > > >
> > > > > > On 14.10.2011 23:54:56 Angelo zerr wrote:
> > > > > > > Hi Steve
> > > > > > >
> > > > > > > 2011/10/14 Steve Hannah <st...@weblite.ca>
> > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > It works but I have the same problem than PDFBox. I must
> > manage
> > > x
> > > > and
> > > > > > y
> > > > > > > > > position (increment x and y when I add some text).
> > > > > > > > >
> > > > > > > >
> > > > > > > > It appears that PDFDocumentGraphics2D is just a Graphics2D
> > > context.
> > > > > >  Then
> > > > > > > > presumably you could pass it to the paint() method of any AWT
> > or
> > > > Swing
> > > > > > > > component to have that component paint itself to the PDF.
> > E.g.
> > > > Just
> > > > > > use a
> > > > > > > > JTextPane or a JTable, then pas the PDFDocumentGraphics2D
> > object
> > > to
> > > > > > their
> > > > > > > > paint() methods
> > > > > > > >
> > > > > > >
> > > > > > > Ok thank's for this information.
> > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > > I have started to manage that with PDFBox and it works
> great
> > > > > > (increment x
> > > > > > > > > when text is added, increment y when text is too long for
> the
> > > > line,
> > > > > > etc).
> > > > > > > > >
> > > > > > > > > I don't see the advantage to use PDFDocumentGraphics2D
> > instread
> > > > of
> > > > > > using
> > > > > > > > > PDFBox PDPageContentStream.
> > > > > > > > > I'm afraid with FOP because:
> > > > > > > > >
> > > > > > > > > * PDFDocumentGraphics2D  is not documented. It seems that
> > > nobody
> > > > > > (google
> > > > > > > > > tell me that)  has used PDFDocumentGraphics2D to create PDF
> > > from
> > > > > > scratch.
> > > > > > > > >
> > > > > > > > One google search found some API docs.
> > > > > > > >
> > > > > > > >
> > > > > >
> > > >
> > >
> >
> http://www.jarvana.com/jarvana/view/org/apache/xmlgraphics/fop/1.0/fop-1.0-javadoc.jar!/org/apache/fop/svg/PDFDocumentGraphics2D.html
> > > > > > > >
> > > > > > > > Possibly old, but that's what 10 seconds of research found.
> > > > > > > >
> > > > > > >
> > > > > > > When I said documented, I meant that I have no found
> > documentation
> > > in
> > > > the
> > > > > > > FOP WebSite or other blog which explains how to use this class.
> I
> > > > have
> > > > > > not
> > > > > > > found sample which use this class.
> > > > > > > Your link is the Javadoc that I have already read because I
> have
> > > the
> > > > > > sources
> > > > > > > of FOP in my Eclipse Workspace.
> > > > > > >
> > > > > > > Regards Angelo
> > > > > > >
> > > > > > > >
> > > > > > > > Best regards
> > > > > > > >
> > > > > > > > Steve
> > > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Jeremias Maerki
> > > > > >
> > > > > >
> > > >
> > > >
> > > >
> > > >
> > > > Jeremias Maerki
> > > >
> > > >
> > >
> >
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Angelo zerr <an...@gmail.com>.
Hi Kevin,

Thank a lot for your information. I have studied PDFBox and FOP with only
Java and I though FOP with only Java (Graphics2D) is the best solution
because
you can export it to another format than PDF. More Jeremias motivated me to
use FOP because it seems I will have some support with FOP.

The only problem (with FOP or PDFBox) is the layout and it's a complex thing
to do. I have started to develop that but it's a big work and before
developing that I must finish our
Eclipse RCP/RAP demo wich generate report and export it to PDF at
http://xdocreport-rap.opensagres.cloudbees.net/xdocreport?startup=fr.opensagres.xdocreport.eclipse.application

Regards Angelo

2011/10/18 Kévin Sailly <ke...@gmail.com>

> Hello Angello,
>
> I found out that to get the text justified, I have to use the
> appendRawCommands method on PDPageContentStream to adjust the space between
> letters and words, using raw commands Tc and Tw from PDF reference.
>
> I am just surprised that this commands are not implemented on
> PDPageContentStream, as this representing no such code:
>    private static final String SET_CHAR_SPACING = "Tc\n";
>    private static final String SET_WORD_SPACING = "Tw\n";
>
>
>    public void setCharSpace( float charSpace ) throws IOException
>    {
>        appendRawCommands( formatDecimal.format( charSpace ) );
>        appendRawCommands( SPACE );
>        appendRawCommands( SET_CHAR_SPACING );
>    }
>
>    public void setWordSpace( float charSpace ) throws IOException
>    {
>        appendRawCommands( formatDecimal.format( charSpace ) );
>        appendRawCommands( SPACE );
>        appendRawCommands( SET_WORD_SPACING );
>    }
>
> or something like that!
>
>
>
> 2011/10/16 Angelo zerr <an...@gmail.com>
>
> > Hi Jeremias,
> >
> > Many thanks for your great explanation! I'm very motivated to study
> > PDFDocumentGraphics2D with your explanation and your support.
> > I would like create the same API than iText (Paragraph, Table, etc) with
> > FOP
> > (or PDFBox) and use it for our converterODF/OOXML.
> > I would like avoid managing layout for docx and layour for odt, but use
> in
> > the 2 cases the Paragraph, Table structures that I would like provides
> with
> > FOP or PDFBox.
> > I have started to manage that with PDFBox (but with FOP it will be same
> > thing) and I track x and y when I add a structure (to compute x/y
> position
> > and know if new page must be added) :
> >
> > ex:
> > -----------------------------------------------------------
> > Document doc=new Document()
> > Paragrapf p = new Paragraph();
> > p.addRun(new Run("AAAA"));
> > p.addRun(new Run(" "));
> > p.addRun(new Run("BBBB"));
> > doc.addParagraph(p);
> >
> > doc.save("test.pdf"); // <= here it loops to each structure and compute
> x,
> > y
> > position, after coputing that it render each structure.
> > -----------------------------------------------------------
> >
> > I don't know how to manage layout (x and y position) with a different
> > means?
> >
> > Anyway thank a lot for your great help.
> >
> > Regards Angelo
> >
> > 2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>
> >
> > > Hi Angelo
> > >
> > > PDFDocumentGraphics2D is a Graphics2D subclass, so the API is stable.
> > > The only thing special to it is the font and page size setup and the
> > > nextPage() method.
> > >
> > > You program once against a Graphics2D object to paint individual pages
> > > and that allows you to paint on the Screen (AWT/Swing), print to a
> > > printer (javax.print) or to create SVG (SVGGraphics2D from Apache
> Batik),
> > > PDF (PDFDocumentGraphics2D from Apache FOP), PostScript
> > > (PSDocumentGraphics2D from Apache XML Graphics Commons) or whatever. I
> > > think iText has a Graphics2D implementation, too. We could even write
> > > one for PDFBox.
> > >
> > > PDFBox already has the opposite direction: it takes a PDF page and can
> > > paint it on a Graphics2D object. That's how it does PDF2Image and how
> > > the PDFReader displays the PDF contents.
> > >
> > > Graphics2D is a vector graphics painting API suitable for a single
> > > page/box/screen. It works with absolute coordinates. You can use it to
> > > create paged documents. There are tools in java.awt.text that help
> > > laying out text but it's no full layout engine.
> > >
> > > Word processing documents (ODF/OOXML/DOC) are flow-oriented formats,
> > > just like HTML and XSL-FO. It's the job of a formatting engine (like
> > > Apache FOP) to turn that into a paged format, i.e. from not having to
> > > track X/Y to absolute positioning on a page. It does line breaking und
> > > checks how many lines fit into a page and continues on a new page if an
> > > overflow occurs (that's simplified).
> > >
> > > Apparently, you have a nice API in iText that allows you to build up
> the
> > > PDF by adding paragraphs and runs where you don't have to worry about
> > > line breaking, hyphenation and page breaks. That means, iText has at
> > > least a simple formatting engine built in. PDFBox doesn't have that
> > (yet).
> > > FOP has a sophisticated one for XSL-FO. Apache Batik has one for the
> SVG
> > > flow-text feature (using java.text.AttributedCharacterIterator, but
> > > heavily relying on their internal GVT framework).
> > >
> > > The JDK has one in javax.swing.text (rendering Text, HTML and RTF, also
> > > using java.awt.font and java.text) although I'm starting to believe
> that
> > > it only supports line-breaking, not page breaking. That's the one I
> used
> > > in the example for PDFDocumentGraphics2D. I can't tell if that would
> > > make a good basis for a simple layout engine for PDFBox. But I
> certainly
> > > think it might be possible to reuse some of that and try to build a
> > > simple page breaker on top of that. I think that might actually one of
> > > the best option for have something useful relatively quickly but it
> > > might not fit for all possible features that ODF/OOXML offer.
> > >
> > > So, in the end I don't think you can get around to find or program some
> > > kind of formatter/layout engine that handles the transition from
> > > flow-based to absolute text, when you go from ODF/OOXML to PDF.
> > >
> > > Doing that on an engine that does not directly depend on PDFBox would
> > > allow you to cater for more than just PDF (taking XDocReport's and ODF
> > > Toolkit's view). That's why I suggested to have a look at FOP's
> > > intermediate format. Because if you can generate that format you have
> > > immediate access to all paged output formats that FOP supports (PDF,
> PS,
> > > AFP, PCL, TIFF, Print). To a lesser degree the same is also possible if
> > > you program against Graphics2D because you can then also produce
> various
> > > output formats (see the list of Graphics2D implementations that I gave
> > > above).
> > >
> > > Please note: I don't want to deny PDFBox a nice simple (flow-oriented)
> > > API for generating PDFs or a Graphics2D implementation. I'm just
> > > pointing out possible directions.
> > >
> > > And the bitter pill at the end: doing layout can be real hard. I'm
> > > speaking from experience.
> > >
> > > On 15.10.2011 14:09:20 Angelo zerr wrote:
> > > > Hi Jeremias ,
> > > >
> > > > Wow thta's a very cool sample! Thank a lot.
> > > >
> > > > With you sample I must manage x and y position that I have started
> with
> > > > PDFBox implementation.
> > > > It seems that PDFDocumentGraphics2D  looks like PDPageContentStream
> > (draw
> > > > string, set font, color, exc).
> > > >
> > > > So my question what is advantage to use PDFDocumentGraphics2D from
> FOP
> > > > instead of PDPageContentStream from PDFBox?
> > > > PDFDocumentGraphics2D  is an API stable?
> > > >
> > > > Thank a lot for your answer.
> > > >
> > > > Regards Angelo
> > > >
> > > > 2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>
> > > >
> > > > > It turned out PDFDocumentGraphics2D was not so operational anymore.
> > > > > Somewhere along the way it broke. I've fixed it again [1] and added
> a
> > > > > usage example [2]. That means you'll have to download FOP Trunk
> [3].
> > > > >
> > > > > [1] http://svn.apache.org/viewvc?rev=1183620&view=rev
> > > > > [2]
> > > > >
> > >
> >
> http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleJava2D2PDF.java?view=markup
> > > > > [3] http://xmlgraphics.apache.org/fop/download.html
> > > > >
> > > > > But guys, talking about PDFDocumentGraphics2D is getting very
> > off-topic
> > > > > for this list. Please take that part to
> > > fop-users@xmlgraphics.apache.org
> > > > > from here.
> > > > >
> > > > > On 14.10.2011 23:54:56 Angelo zerr wrote:
> > > > > > Hi Steve
> > > > > >
> > > > > > 2011/10/14 Steve Hannah <st...@weblite.ca>
> > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > It works but I have the same problem than PDFBox. I must
> manage
> > x
> > > and
> > > > > y
> > > > > > > > position (increment x and y when I add some text).
> > > > > > > >
> > > > > > >
> > > > > > > It appears that PDFDocumentGraphics2D is just a Graphics2D
> > context.
> > > > >  Then
> > > > > > > presumably you could pass it to the paint() method of any AWT
> or
> > > Swing
> > > > > > > component to have that component paint itself to the PDF.
> E.g.
> > > Just
> > > > > use a
> > > > > > > JTextPane or a JTable, then pas the PDFDocumentGraphics2D
> object
> > to
> > > > > their
> > > > > > > paint() methods
> > > > > > >
> > > > > >
> > > > > > Ok thank's for this information.
> > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > > I have started to manage that with PDFBox and it works great
> > > > > (increment x
> > > > > > > > when text is added, increment y when text is too long for the
> > > line,
> > > > > etc).
> > > > > > > >
> > > > > > > > I don't see the advantage to use PDFDocumentGraphics2D
> instread
> > > of
> > > > > using
> > > > > > > > PDFBox PDPageContentStream.
> > > > > > > > I'm afraid with FOP because:
> > > > > > > >
> > > > > > > > * PDFDocumentGraphics2D  is not documented. It seems that
> > nobody
> > > > > (google
> > > > > > > > tell me that)  has used PDFDocumentGraphics2D to create PDF
> > from
> > > > > scratch.
> > > > > > > >
> > > > > > > One google search found some API docs.
> > > > > > >
> > > > > > >
> > > > >
> > >
> >
> http://www.jarvana.com/jarvana/view/org/apache/xmlgraphics/fop/1.0/fop-1.0-javadoc.jar!/org/apache/fop/svg/PDFDocumentGraphics2D.html
> > > > > > >
> > > > > > > Possibly old, but that's what 10 seconds of research found.
> > > > > > >
> > > > > >
> > > > > > When I said documented, I meant that I have no found
> documentation
> > in
> > > the
> > > > > > FOP WebSite or other blog which explains how to use this class. I
> > > have
> > > > > not
> > > > > > found sample which use this class.
> > > > > > Your link is the Javadoc that I have already read because I have
> > the
> > > > > sources
> > > > > > of FOP in my Eclipse Workspace.
> > > > > >
> > > > > > Regards Angelo
> > > > > >
> > > > > > >
> > > > > > > Best regards
> > > > > > >
> > > > > > > Steve
> > > > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Jeremias Maerki
> > > > >
> > > > >
> > >
> > >
> > >
> > >
> > > Jeremias Maerki
> > >
> > >
> >
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Angelo zerr <an...@gmail.com>.
Hi Kevin,

Thank a lot for your information. I have studied PDFBox and FOP with only
Java and I though FOP with only Java (Graphics2D) is the best solution
because
you can export it to another format than PDF. More Jeremias motivated me to
use FOP because it seems I will have some support with FOP.

The only problem (with FOP or PDFBox) is the layout and it's a complex thing
to do. I have started to develop that but it's a big work and before
developing that I must finish our
Eclipse RCP/RAP demo wich generate report and export it to PDF at
http://xdocreport-rap.opensagres.cloudbees.net/xdocreport?startup=fr.opensagres.xdocreport.eclipse.application

Regards Angelo

2011/10/18 Kévin Sailly <ke...@gmail.com>

> Hello Angello,
>
> I found out that to get the text justified, I have to use the
> appendRawCommands method on PDPageContentStream to adjust the space between
> letters and words, using raw commands Tc and Tw from PDF reference.
>
> I am just surprised that this commands are not implemented on
> PDPageContentStream, as this representing no such code:
>    private static final String SET_CHAR_SPACING = "Tc\n";
>    private static final String SET_WORD_SPACING = "Tw\n";
>
>
>    public void setCharSpace( float charSpace ) throws IOException
>    {
>        appendRawCommands( formatDecimal.format( charSpace ) );
>        appendRawCommands( SPACE );
>        appendRawCommands( SET_CHAR_SPACING );
>    }
>
>    public void setWordSpace( float charSpace ) throws IOException
>    {
>        appendRawCommands( formatDecimal.format( charSpace ) );
>        appendRawCommands( SPACE );
>        appendRawCommands( SET_WORD_SPACING );
>    }
>
> or something like that!
>
>
>
> 2011/10/16 Angelo zerr <an...@gmail.com>
>
> > Hi Jeremias,
> >
> > Many thanks for your great explanation! I'm very motivated to study
> > PDFDocumentGraphics2D with your explanation and your support.
> > I would like create the same API than iText (Paragraph, Table, etc) with
> > FOP
> > (or PDFBox) and use it for our converterODF/OOXML.
> > I would like avoid managing layout for docx and layour for odt, but use
> in
> > the 2 cases the Paragraph, Table structures that I would like provides
> with
> > FOP or PDFBox.
> > I have started to manage that with PDFBox (but with FOP it will be same
> > thing) and I track x and y when I add a structure (to compute x/y
> position
> > and know if new page must be added) :
> >
> > ex:
> > -----------------------------------------------------------
> > Document doc=new Document()
> > Paragrapf p = new Paragraph();
> > p.addRun(new Run("AAAA"));
> > p.addRun(new Run(" "));
> > p.addRun(new Run("BBBB"));
> > doc.addParagraph(p);
> >
> > doc.save("test.pdf"); // <= here it loops to each structure and compute
> x,
> > y
> > position, after coputing that it render each structure.
> > -----------------------------------------------------------
> >
> > I don't know how to manage layout (x and y position) with a different
> > means?
> >
> > Anyway thank a lot for your great help.
> >
> > Regards Angelo
> >
> > 2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>
> >
> > > Hi Angelo
> > >
> > > PDFDocumentGraphics2D is a Graphics2D subclass, so the API is stable.
> > > The only thing special to it is the font and page size setup and the
> > > nextPage() method.
> > >
> > > You program once against a Graphics2D object to paint individual pages
> > > and that allows you to paint on the Screen (AWT/Swing), print to a
> > > printer (javax.print) or to create SVG (SVGGraphics2D from Apache
> Batik),
> > > PDF (PDFDocumentGraphics2D from Apache FOP), PostScript
> > > (PSDocumentGraphics2D from Apache XML Graphics Commons) or whatever. I
> > > think iText has a Graphics2D implementation, too. We could even write
> > > one for PDFBox.
> > >
> > > PDFBox already has the opposite direction: it takes a PDF page and can
> > > paint it on a Graphics2D object. That's how it does PDF2Image and how
> > > the PDFReader displays the PDF contents.
> > >
> > > Graphics2D is a vector graphics painting API suitable for a single
> > > page/box/screen. It works with absolute coordinates. You can use it to
> > > create paged documents. There are tools in java.awt.text that help
> > > laying out text but it's no full layout engine.
> > >
> > > Word processing documents (ODF/OOXML/DOC) are flow-oriented formats,
> > > just like HTML and XSL-FO. It's the job of a formatting engine (like
> > > Apache FOP) to turn that into a paged format, i.e. from not having to
> > > track X/Y to absolute positioning on a page. It does line breaking und
> > > checks how many lines fit into a page and continues on a new page if an
> > > overflow occurs (that's simplified).
> > >
> > > Apparently, you have a nice API in iText that allows you to build up
> the
> > > PDF by adding paragraphs and runs where you don't have to worry about
> > > line breaking, hyphenation and page breaks. That means, iText has at
> > > least a simple formatting engine built in. PDFBox doesn't have that
> > (yet).
> > > FOP has a sophisticated one for XSL-FO. Apache Batik has one for the
> SVG
> > > flow-text feature (using java.text.AttributedCharacterIterator, but
> > > heavily relying on their internal GVT framework).
> > >
> > > The JDK has one in javax.swing.text (rendering Text, HTML and RTF, also
> > > using java.awt.font and java.text) although I'm starting to believe
> that
> > > it only supports line-breaking, not page breaking. That's the one I
> used
> > > in the example for PDFDocumentGraphics2D. I can't tell if that would
> > > make a good basis for a simple layout engine for PDFBox. But I
> certainly
> > > think it might be possible to reuse some of that and try to build a
> > > simple page breaker on top of that. I think that might actually one of
> > > the best option for have something useful relatively quickly but it
> > > might not fit for all possible features that ODF/OOXML offer.
> > >
> > > So, in the end I don't think you can get around to find or program some
> > > kind of formatter/layout engine that handles the transition from
> > > flow-based to absolute text, when you go from ODF/OOXML to PDF.
> > >
> > > Doing that on an engine that does not directly depend on PDFBox would
> > > allow you to cater for more than just PDF (taking XDocReport's and ODF
> > > Toolkit's view). That's why I suggested to have a look at FOP's
> > > intermediate format. Because if you can generate that format you have
> > > immediate access to all paged output formats that FOP supports (PDF,
> PS,
> > > AFP, PCL, TIFF, Print). To a lesser degree the same is also possible if
> > > you program against Graphics2D because you can then also produce
> various
> > > output formats (see the list of Graphics2D implementations that I gave
> > > above).
> > >
> > > Please note: I don't want to deny PDFBox a nice simple (flow-oriented)
> > > API for generating PDFs or a Graphics2D implementation. I'm just
> > > pointing out possible directions.
> > >
> > > And the bitter pill at the end: doing layout can be real hard. I'm
> > > speaking from experience.
> > >
> > > On 15.10.2011 14:09:20 Angelo zerr wrote:
> > > > Hi Jeremias ,
> > > >
> > > > Wow thta's a very cool sample! Thank a lot.
> > > >
> > > > With you sample I must manage x and y position that I have started
> with
> > > > PDFBox implementation.
> > > > It seems that PDFDocumentGraphics2D  looks like PDPageContentStream
> > (draw
> > > > string, set font, color, exc).
> > > >
> > > > So my question what is advantage to use PDFDocumentGraphics2D from
> FOP
> > > > instead of PDPageContentStream from PDFBox?
> > > > PDFDocumentGraphics2D  is an API stable?
> > > >
> > > > Thank a lot for your answer.
> > > >
> > > > Regards Angelo
> > > >
> > > > 2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>
> > > >
> > > > > It turned out PDFDocumentGraphics2D was not so operational anymore.
> > > > > Somewhere along the way it broke. I've fixed it again [1] and added
> a
> > > > > usage example [2]. That means you'll have to download FOP Trunk
> [3].
> > > > >
> > > > > [1] http://svn.apache.org/viewvc?rev=1183620&view=rev
> > > > > [2]
> > > > >
> > >
> >
> http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleJava2D2PDF.java?view=markup
> > > > > [3] http://xmlgraphics.apache.org/fop/download.html
> > > > >
> > > > > But guys, talking about PDFDocumentGraphics2D is getting very
> > off-topic
> > > > > for this list. Please take that part to
> > > fop-users@xmlgraphics.apache.org
> > > > > from here.
> > > > >
> > > > > On 14.10.2011 23:54:56 Angelo zerr wrote:
> > > > > > Hi Steve
> > > > > >
> > > > > > 2011/10/14 Steve Hannah <st...@weblite.ca>
> > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > It works but I have the same problem than PDFBox. I must
> manage
> > x
> > > and
> > > > > y
> > > > > > > > position (increment x and y when I add some text).
> > > > > > > >
> > > > > > >
> > > > > > > It appears that PDFDocumentGraphics2D is just a Graphics2D
> > context.
> > > > >  Then
> > > > > > > presumably you could pass it to the paint() method of any AWT
> or
> > > Swing
> > > > > > > component to have that component paint itself to the PDF.
> E.g.
> > > Just
> > > > > use a
> > > > > > > JTextPane or a JTable, then pas the PDFDocumentGraphics2D
> object
> > to
> > > > > their
> > > > > > > paint() methods
> > > > > > >
> > > > > >
> > > > > > Ok thank's for this information.
> > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > > I have started to manage that with PDFBox and it works great
> > > > > (increment x
> > > > > > > > when text is added, increment y when text is too long for the
> > > line,
> > > > > etc).
> > > > > > > >
> > > > > > > > I don't see the advantage to use PDFDocumentGraphics2D
> instread
> > > of
> > > > > using
> > > > > > > > PDFBox PDPageContentStream.
> > > > > > > > I'm afraid with FOP because:
> > > > > > > >
> > > > > > > > * PDFDocumentGraphics2D  is not documented. It seems that
> > nobody
> > > > > (google
> > > > > > > > tell me that)  has used PDFDocumentGraphics2D to create PDF
> > from
> > > > > scratch.
> > > > > > > >
> > > > > > > One google search found some API docs.
> > > > > > >
> > > > > > >
> > > > >
> > >
> >
> http://www.jarvana.com/jarvana/view/org/apache/xmlgraphics/fop/1.0/fop-1.0-javadoc.jar!/org/apache/fop/svg/PDFDocumentGraphics2D.html
> > > > > > >
> > > > > > > Possibly old, but that's what 10 seconds of research found.
> > > > > > >
> > > > > >
> > > > > > When I said documented, I meant that I have no found
> documentation
> > in
> > > the
> > > > > > FOP WebSite or other blog which explains how to use this class. I
> > > have
> > > > > not
> > > > > > found sample which use this class.
> > > > > > Your link is the Javadoc that I have already read because I have
> > the
> > > > > sources
> > > > > > of FOP in my Eclipse Workspace.
> > > > > >
> > > > > > Regards Angelo
> > > > > >
> > > > > > >
> > > > > > > Best regards
> > > > > > >
> > > > > > > Steve
> > > > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Jeremias Maerki
> > > > >
> > > > >
> > >
> > >
> > >
> > >
> > > Jeremias Maerki
> > >
> > >
> >
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Kévin Sailly <ke...@gmail.com>.
Hello Angello,

I found out that to get the text justified, I have to use the
appendRawCommands method on PDPageContentStream to adjust the space between
letters and words, using raw commands Tc and Tw from PDF reference.

I am just surprised that this commands are not implemented on
PDPageContentStream, as this representing no such code:
    private static final String SET_CHAR_SPACING = "Tc\n";
    private static final String SET_WORD_SPACING = "Tw\n";


    public void setCharSpace( float charSpace ) throws IOException
    {
        appendRawCommands( formatDecimal.format( charSpace ) );
        appendRawCommands( SPACE );
        appendRawCommands( SET_CHAR_SPACING );
    }

    public void setWordSpace( float charSpace ) throws IOException
    {
        appendRawCommands( formatDecimal.format( charSpace ) );
        appendRawCommands( SPACE );
        appendRawCommands( SET_WORD_SPACING );
    }

or something like that!



2011/10/16 Angelo zerr <an...@gmail.com>

> Hi Jeremias,
>
> Many thanks for your great explanation! I'm very motivated to study
> PDFDocumentGraphics2D with your explanation and your support.
> I would like create the same API than iText (Paragraph, Table, etc) with
> FOP
> (or PDFBox) and use it for our converterODF/OOXML.
> I would like avoid managing layout for docx and layour for odt, but use in
> the 2 cases the Paragraph, Table structures that I would like provides with
> FOP or PDFBox.
> I have started to manage that with PDFBox (but with FOP it will be same
> thing) and I track x and y when I add a structure (to compute x/y position
> and know if new page must be added) :
>
> ex:
> -----------------------------------------------------------
> Document doc=new Document()
> Paragrapf p = new Paragraph();
> p.addRun(new Run("AAAA"));
> p.addRun(new Run(" "));
> p.addRun(new Run("BBBB"));
> doc.addParagraph(p);
>
> doc.save("test.pdf"); // <= here it loops to each structure and compute x,
> y
> position, after coputing that it render each structure.
> -----------------------------------------------------------
>
> I don't know how to manage layout (x and y position) with a different
> means?
>
> Anyway thank a lot for your great help.
>
> Regards Angelo
>
> 2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>
>
> > Hi Angelo
> >
> > PDFDocumentGraphics2D is a Graphics2D subclass, so the API is stable.
> > The only thing special to it is the font and page size setup and the
> > nextPage() method.
> >
> > You program once against a Graphics2D object to paint individual pages
> > and that allows you to paint on the Screen (AWT/Swing), print to a
> > printer (javax.print) or to create SVG (SVGGraphics2D from Apache Batik),
> > PDF (PDFDocumentGraphics2D from Apache FOP), PostScript
> > (PSDocumentGraphics2D from Apache XML Graphics Commons) or whatever. I
> > think iText has a Graphics2D implementation, too. We could even write
> > one for PDFBox.
> >
> > PDFBox already has the opposite direction: it takes a PDF page and can
> > paint it on a Graphics2D object. That's how it does PDF2Image and how
> > the PDFReader displays the PDF contents.
> >
> > Graphics2D is a vector graphics painting API suitable for a single
> > page/box/screen. It works with absolute coordinates. You can use it to
> > create paged documents. There are tools in java.awt.text that help
> > laying out text but it's no full layout engine.
> >
> > Word processing documents (ODF/OOXML/DOC) are flow-oriented formats,
> > just like HTML and XSL-FO. It's the job of a formatting engine (like
> > Apache FOP) to turn that into a paged format, i.e. from not having to
> > track X/Y to absolute positioning on a page. It does line breaking und
> > checks how many lines fit into a page and continues on a new page if an
> > overflow occurs (that's simplified).
> >
> > Apparently, you have a nice API in iText that allows you to build up the
> > PDF by adding paragraphs and runs where you don't have to worry about
> > line breaking, hyphenation and page breaks. That means, iText has at
> > least a simple formatting engine built in. PDFBox doesn't have that
> (yet).
> > FOP has a sophisticated one for XSL-FO. Apache Batik has one for the SVG
> > flow-text feature (using java.text.AttributedCharacterIterator, but
> > heavily relying on their internal GVT framework).
> >
> > The JDK has one in javax.swing.text (rendering Text, HTML and RTF, also
> > using java.awt.font and java.text) although I'm starting to believe that
> > it only supports line-breaking, not page breaking. That's the one I used
> > in the example for PDFDocumentGraphics2D. I can't tell if that would
> > make a good basis for a simple layout engine for PDFBox. But I certainly
> > think it might be possible to reuse some of that and try to build a
> > simple page breaker on top of that. I think that might actually one of
> > the best option for have something useful relatively quickly but it
> > might not fit for all possible features that ODF/OOXML offer.
> >
> > So, in the end I don't think you can get around to find or program some
> > kind of formatter/layout engine that handles the transition from
> > flow-based to absolute text, when you go from ODF/OOXML to PDF.
> >
> > Doing that on an engine that does not directly depend on PDFBox would
> > allow you to cater for more than just PDF (taking XDocReport's and ODF
> > Toolkit's view). That's why I suggested to have a look at FOP's
> > intermediate format. Because if you can generate that format you have
> > immediate access to all paged output formats that FOP supports (PDF, PS,
> > AFP, PCL, TIFF, Print). To a lesser degree the same is also possible if
> > you program against Graphics2D because you can then also produce various
> > output formats (see the list of Graphics2D implementations that I gave
> > above).
> >
> > Please note: I don't want to deny PDFBox a nice simple (flow-oriented)
> > API for generating PDFs or a Graphics2D implementation. I'm just
> > pointing out possible directions.
> >
> > And the bitter pill at the end: doing layout can be real hard. I'm
> > speaking from experience.
> >
> > On 15.10.2011 14:09:20 Angelo zerr wrote:
> > > Hi Jeremias ,
> > >
> > > Wow thta's a very cool sample! Thank a lot.
> > >
> > > With you sample I must manage x and y position that I have started with
> > > PDFBox implementation.
> > > It seems that PDFDocumentGraphics2D  looks like PDPageContentStream
> (draw
> > > string, set font, color, exc).
> > >
> > > So my question what is advantage to use PDFDocumentGraphics2D from FOP
> > > instead of PDPageContentStream from PDFBox?
> > > PDFDocumentGraphics2D  is an API stable?
> > >
> > > Thank a lot for your answer.
> > >
> > > Regards Angelo
> > >
> > > 2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>
> > >
> > > > It turned out PDFDocumentGraphics2D was not so operational anymore.
> > > > Somewhere along the way it broke. I've fixed it again [1] and added a
> > > > usage example [2]. That means you'll have to download FOP Trunk [3].
> > > >
> > > > [1] http://svn.apache.org/viewvc?rev=1183620&view=rev
> > > > [2]
> > > >
> >
> http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleJava2D2PDF.java?view=markup
> > > > [3] http://xmlgraphics.apache.org/fop/download.html
> > > >
> > > > But guys, talking about PDFDocumentGraphics2D is getting very
> off-topic
> > > > for this list. Please take that part to
> > fop-users@xmlgraphics.apache.org
> > > > from here.
> > > >
> > > > On 14.10.2011 23:54:56 Angelo zerr wrote:
> > > > > Hi Steve
> > > > >
> > > > > 2011/10/14 Steve Hannah <st...@weblite.ca>
> > > > >
> > > > > > >
> > > > > > >
> > > > > > > It works but I have the same problem than PDFBox. I must manage
> x
> > and
> > > > y
> > > > > > > position (increment x and y when I add some text).
> > > > > > >
> > > > > >
> > > > > > It appears that PDFDocumentGraphics2D is just a Graphics2D
> context.
> > > >  Then
> > > > > > presumably you could pass it to the paint() method of any AWT or
> > Swing
> > > > > > component to have that component paint itself to the PDF.   E.g.
> > Just
> > > > use a
> > > > > > JTextPane or a JTable, then pas the PDFDocumentGraphics2D object
> to
> > > > their
> > > > > > paint() methods
> > > > > >
> > > > >
> > > > > Ok thank's for this information.
> > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > > I have started to manage that with PDFBox and it works great
> > > > (increment x
> > > > > > > when text is added, increment y when text is too long for the
> > line,
> > > > etc).
> > > > > > >
> > > > > > > I don't see the advantage to use PDFDocumentGraphics2D instread
> > of
> > > > using
> > > > > > > PDFBox PDPageContentStream.
> > > > > > > I'm afraid with FOP because:
> > > > > > >
> > > > > > > * PDFDocumentGraphics2D  is not documented. It seems that
> nobody
> > > > (google
> > > > > > > tell me that)  has used PDFDocumentGraphics2D to create PDF
> from
> > > > scratch.
> > > > > > >
> > > > > > One google search found some API docs.
> > > > > >
> > > > > >
> > > >
> >
> http://www.jarvana.com/jarvana/view/org/apache/xmlgraphics/fop/1.0/fop-1.0-javadoc.jar!/org/apache/fop/svg/PDFDocumentGraphics2D.html
> > > > > >
> > > > > > Possibly old, but that's what 10 seconds of research found.
> > > > > >
> > > > >
> > > > > When I said documented, I meant that I have no found documentation
> in
> > the
> > > > > FOP WebSite or other blog which explains how to use this class. I
> > have
> > > > not
> > > > > found sample which use this class.
> > > > > Your link is the Javadoc that I have already read because I have
> the
> > > > sources
> > > > > of FOP in my Eclipse Workspace.
> > > > >
> > > > > Regards Angelo
> > > > >
> > > > > >
> > > > > > Best regards
> > > > > >
> > > > > > Steve
> > > > > >
> > > >
> > > >
> > > >
> > > >
> > > > Jeremias Maerki
> > > >
> > > >
> >
> >
> >
> >
> > Jeremias Maerki
> >
> >
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Kévin Sailly <ke...@gmail.com>.
Hello Angello,

I found out that to get the text justified, I have to use the
appendRawCommands method on PDPageContentStream to adjust the space between
letters and words, using raw commands Tc and Tw from PDF reference.

I am just surprised that this commands are not implemented on
PDPageContentStream, as this representing no such code:
    private static final String SET_CHAR_SPACING = "Tc\n";
    private static final String SET_WORD_SPACING = "Tw\n";


    public void setCharSpace( float charSpace ) throws IOException
    {
        appendRawCommands( formatDecimal.format( charSpace ) );
        appendRawCommands( SPACE );
        appendRawCommands( SET_CHAR_SPACING );
    }

    public void setWordSpace( float charSpace ) throws IOException
    {
        appendRawCommands( formatDecimal.format( charSpace ) );
        appendRawCommands( SPACE );
        appendRawCommands( SET_WORD_SPACING );
    }

or something like that!



2011/10/16 Angelo zerr <an...@gmail.com>

> Hi Jeremias,
>
> Many thanks for your great explanation! I'm very motivated to study
> PDFDocumentGraphics2D with your explanation and your support.
> I would like create the same API than iText (Paragraph, Table, etc) with
> FOP
> (or PDFBox) and use it for our converterODF/OOXML.
> I would like avoid managing layout for docx and layour for odt, but use in
> the 2 cases the Paragraph, Table structures that I would like provides with
> FOP or PDFBox.
> I have started to manage that with PDFBox (but with FOP it will be same
> thing) and I track x and y when I add a structure (to compute x/y position
> and know if new page must be added) :
>
> ex:
> -----------------------------------------------------------
> Document doc=new Document()
> Paragrapf p = new Paragraph();
> p.addRun(new Run("AAAA"));
> p.addRun(new Run(" "));
> p.addRun(new Run("BBBB"));
> doc.addParagraph(p);
>
> doc.save("test.pdf"); // <= here it loops to each structure and compute x,
> y
> position, after coputing that it render each structure.
> -----------------------------------------------------------
>
> I don't know how to manage layout (x and y position) with a different
> means?
>
> Anyway thank a lot for your great help.
>
> Regards Angelo
>
> 2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>
>
> > Hi Angelo
> >
> > PDFDocumentGraphics2D is a Graphics2D subclass, so the API is stable.
> > The only thing special to it is the font and page size setup and the
> > nextPage() method.
> >
> > You program once against a Graphics2D object to paint individual pages
> > and that allows you to paint on the Screen (AWT/Swing), print to a
> > printer (javax.print) or to create SVG (SVGGraphics2D from Apache Batik),
> > PDF (PDFDocumentGraphics2D from Apache FOP), PostScript
> > (PSDocumentGraphics2D from Apache XML Graphics Commons) or whatever. I
> > think iText has a Graphics2D implementation, too. We could even write
> > one for PDFBox.
> >
> > PDFBox already has the opposite direction: it takes a PDF page and can
> > paint it on a Graphics2D object. That's how it does PDF2Image and how
> > the PDFReader displays the PDF contents.
> >
> > Graphics2D is a vector graphics painting API suitable for a single
> > page/box/screen. It works with absolute coordinates. You can use it to
> > create paged documents. There are tools in java.awt.text that help
> > laying out text but it's no full layout engine.
> >
> > Word processing documents (ODF/OOXML/DOC) are flow-oriented formats,
> > just like HTML and XSL-FO. It's the job of a formatting engine (like
> > Apache FOP) to turn that into a paged format, i.e. from not having to
> > track X/Y to absolute positioning on a page. It does line breaking und
> > checks how many lines fit into a page and continues on a new page if an
> > overflow occurs (that's simplified).
> >
> > Apparently, you have a nice API in iText that allows you to build up the
> > PDF by adding paragraphs and runs where you don't have to worry about
> > line breaking, hyphenation and page breaks. That means, iText has at
> > least a simple formatting engine built in. PDFBox doesn't have that
> (yet).
> > FOP has a sophisticated one for XSL-FO. Apache Batik has one for the SVG
> > flow-text feature (using java.text.AttributedCharacterIterator, but
> > heavily relying on their internal GVT framework).
> >
> > The JDK has one in javax.swing.text (rendering Text, HTML and RTF, also
> > using java.awt.font and java.text) although I'm starting to believe that
> > it only supports line-breaking, not page breaking. That's the one I used
> > in the example for PDFDocumentGraphics2D. I can't tell if that would
> > make a good basis for a simple layout engine for PDFBox. But I certainly
> > think it might be possible to reuse some of that and try to build a
> > simple page breaker on top of that. I think that might actually one of
> > the best option for have something useful relatively quickly but it
> > might not fit for all possible features that ODF/OOXML offer.
> >
> > So, in the end I don't think you can get around to find or program some
> > kind of formatter/layout engine that handles the transition from
> > flow-based to absolute text, when you go from ODF/OOXML to PDF.
> >
> > Doing that on an engine that does not directly depend on PDFBox would
> > allow you to cater for more than just PDF (taking XDocReport's and ODF
> > Toolkit's view). That's why I suggested to have a look at FOP's
> > intermediate format. Because if you can generate that format you have
> > immediate access to all paged output formats that FOP supports (PDF, PS,
> > AFP, PCL, TIFF, Print). To a lesser degree the same is also possible if
> > you program against Graphics2D because you can then also produce various
> > output formats (see the list of Graphics2D implementations that I gave
> > above).
> >
> > Please note: I don't want to deny PDFBox a nice simple (flow-oriented)
> > API for generating PDFs or a Graphics2D implementation. I'm just
> > pointing out possible directions.
> >
> > And the bitter pill at the end: doing layout can be real hard. I'm
> > speaking from experience.
> >
> > On 15.10.2011 14:09:20 Angelo zerr wrote:
> > > Hi Jeremias ,
> > >
> > > Wow thta's a very cool sample! Thank a lot.
> > >
> > > With you sample I must manage x and y position that I have started with
> > > PDFBox implementation.
> > > It seems that PDFDocumentGraphics2D  looks like PDPageContentStream
> (draw
> > > string, set font, color, exc).
> > >
> > > So my question what is advantage to use PDFDocumentGraphics2D from FOP
> > > instead of PDPageContentStream from PDFBox?
> > > PDFDocumentGraphics2D  is an API stable?
> > >
> > > Thank a lot for your answer.
> > >
> > > Regards Angelo
> > >
> > > 2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>
> > >
> > > > It turned out PDFDocumentGraphics2D was not so operational anymore.
> > > > Somewhere along the way it broke. I've fixed it again [1] and added a
> > > > usage example [2]. That means you'll have to download FOP Trunk [3].
> > > >
> > > > [1] http://svn.apache.org/viewvc?rev=1183620&view=rev
> > > > [2]
> > > >
> >
> http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleJava2D2PDF.java?view=markup
> > > > [3] http://xmlgraphics.apache.org/fop/download.html
> > > >
> > > > But guys, talking about PDFDocumentGraphics2D is getting very
> off-topic
> > > > for this list. Please take that part to
> > fop-users@xmlgraphics.apache.org
> > > > from here.
> > > >
> > > > On 14.10.2011 23:54:56 Angelo zerr wrote:
> > > > > Hi Steve
> > > > >
> > > > > 2011/10/14 Steve Hannah <st...@weblite.ca>
> > > > >
> > > > > > >
> > > > > > >
> > > > > > > It works but I have the same problem than PDFBox. I must manage
> x
> > and
> > > > y
> > > > > > > position (increment x and y when I add some text).
> > > > > > >
> > > > > >
> > > > > > It appears that PDFDocumentGraphics2D is just a Graphics2D
> context.
> > > >  Then
> > > > > > presumably you could pass it to the paint() method of any AWT or
> > Swing
> > > > > > component to have that component paint itself to the PDF.   E.g.
> > Just
> > > > use a
> > > > > > JTextPane or a JTable, then pas the PDFDocumentGraphics2D object
> to
> > > > their
> > > > > > paint() methods
> > > > > >
> > > > >
> > > > > Ok thank's for this information.
> > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > > I have started to manage that with PDFBox and it works great
> > > > (increment x
> > > > > > > when text is added, increment y when text is too long for the
> > line,
> > > > etc).
> > > > > > >
> > > > > > > I don't see the advantage to use PDFDocumentGraphics2D instread
> > of
> > > > using
> > > > > > > PDFBox PDPageContentStream.
> > > > > > > I'm afraid with FOP because:
> > > > > > >
> > > > > > > * PDFDocumentGraphics2D  is not documented. It seems that
> nobody
> > > > (google
> > > > > > > tell me that)  has used PDFDocumentGraphics2D to create PDF
> from
> > > > scratch.
> > > > > > >
> > > > > > One google search found some API docs.
> > > > > >
> > > > > >
> > > >
> >
> http://www.jarvana.com/jarvana/view/org/apache/xmlgraphics/fop/1.0/fop-1.0-javadoc.jar!/org/apache/fop/svg/PDFDocumentGraphics2D.html
> > > > > >
> > > > > > Possibly old, but that's what 10 seconds of research found.
> > > > > >
> > > > >
> > > > > When I said documented, I meant that I have no found documentation
> in
> > the
> > > > > FOP WebSite or other blog which explains how to use this class. I
> > have
> > > > not
> > > > > found sample which use this class.
> > > > > Your link is the Javadoc that I have already read because I have
> the
> > > > sources
> > > > > of FOP in my Eclipse Workspace.
> > > > >
> > > > > Regards Angelo
> > > > >
> > > > > >
> > > > > > Best regards
> > > > > >
> > > > > > Steve
> > > > > >
> > > >
> > > >
> > > >
> > > >
> > > > Jeremias Maerki
> > > >
> > > >
> >
> >
> >
> >
> > Jeremias Maerki
> >
> >
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Angelo zerr <an...@gmail.com>.
Hi Jeremias,

Many thanks for your great explanation! I'm very motivated to study
PDFDocumentGraphics2D with your explanation and your support.
I would like create the same API than iText (Paragraph, Table, etc) with FOP
(or PDFBox) and use it for our converterODF/OOXML.
I would like avoid managing layout for docx and layour for odt, but use in
the 2 cases the Paragraph, Table structures that I would like provides with
FOP or PDFBox.
I have started to manage that with PDFBox (but with FOP it will be same
thing) and I track x and y when I add a structure (to compute x/y position
and know if new page must be added) :

ex:
-----------------------------------------------------------
Document doc=new Document()
Paragrapf p = new Paragraph();
p.addRun(new Run("AAAA"));
p.addRun(new Run(" "));
p.addRun(new Run("BBBB"));
doc.addParagraph(p);

doc.save("test.pdf"); // <= here it loops to each structure and compute x, y
position, after coputing that it render each structure.
-----------------------------------------------------------

I don't know how to manage layout (x and y position) with a different means?

Anyway thank a lot for your great help.

Regards Angelo

2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>

> Hi Angelo
>
> PDFDocumentGraphics2D is a Graphics2D subclass, so the API is stable.
> The only thing special to it is the font and page size setup and the
> nextPage() method.
>
> You program once against a Graphics2D object to paint individual pages
> and that allows you to paint on the Screen (AWT/Swing), print to a
> printer (javax.print) or to create SVG (SVGGraphics2D from Apache Batik),
> PDF (PDFDocumentGraphics2D from Apache FOP), PostScript
> (PSDocumentGraphics2D from Apache XML Graphics Commons) or whatever. I
> think iText has a Graphics2D implementation, too. We could even write
> one for PDFBox.
>
> PDFBox already has the opposite direction: it takes a PDF page and can
> paint it on a Graphics2D object. That's how it does PDF2Image and how
> the PDFReader displays the PDF contents.
>
> Graphics2D is a vector graphics painting API suitable for a single
> page/box/screen. It works with absolute coordinates. You can use it to
> create paged documents. There are tools in java.awt.text that help
> laying out text but it's no full layout engine.
>
> Word processing documents (ODF/OOXML/DOC) are flow-oriented formats,
> just like HTML and XSL-FO. It's the job of a formatting engine (like
> Apache FOP) to turn that into a paged format, i.e. from not having to
> track X/Y to absolute positioning on a page. It does line breaking und
> checks how many lines fit into a page and continues on a new page if an
> overflow occurs (that's simplified).
>
> Apparently, you have a nice API in iText that allows you to build up the
> PDF by adding paragraphs and runs where you don't have to worry about
> line breaking, hyphenation and page breaks. That means, iText has at
> least a simple formatting engine built in. PDFBox doesn't have that (yet).
> FOP has a sophisticated one for XSL-FO. Apache Batik has one for the SVG
> flow-text feature (using java.text.AttributedCharacterIterator, but
> heavily relying on their internal GVT framework).
>
> The JDK has one in javax.swing.text (rendering Text, HTML and RTF, also
> using java.awt.font and java.text) although I'm starting to believe that
> it only supports line-breaking, not page breaking. That's the one I used
> in the example for PDFDocumentGraphics2D. I can't tell if that would
> make a good basis for a simple layout engine for PDFBox. But I certainly
> think it might be possible to reuse some of that and try to build a
> simple page breaker on top of that. I think that might actually one of
> the best option for have something useful relatively quickly but it
> might not fit for all possible features that ODF/OOXML offer.
>
> So, in the end I don't think you can get around to find or program some
> kind of formatter/layout engine that handles the transition from
> flow-based to absolute text, when you go from ODF/OOXML to PDF.
>
> Doing that on an engine that does not directly depend on PDFBox would
> allow you to cater for more than just PDF (taking XDocReport's and ODF
> Toolkit's view). That's why I suggested to have a look at FOP's
> intermediate format. Because if you can generate that format you have
> immediate access to all paged output formats that FOP supports (PDF, PS,
> AFP, PCL, TIFF, Print). To a lesser degree the same is also possible if
> you program against Graphics2D because you can then also produce various
> output formats (see the list of Graphics2D implementations that I gave
> above).
>
> Please note: I don't want to deny PDFBox a nice simple (flow-oriented)
> API for generating PDFs or a Graphics2D implementation. I'm just
> pointing out possible directions.
>
> And the bitter pill at the end: doing layout can be real hard. I'm
> speaking from experience.
>
> On 15.10.2011 14:09:20 Angelo zerr wrote:
> > Hi Jeremias ,
> >
> > Wow thta's a very cool sample! Thank a lot.
> >
> > With you sample I must manage x and y position that I have started with
> > PDFBox implementation.
> > It seems that PDFDocumentGraphics2D  looks like PDPageContentStream (draw
> > string, set font, color, exc).
> >
> > So my question what is advantage to use PDFDocumentGraphics2D from FOP
> > instead of PDPageContentStream from PDFBox?
> > PDFDocumentGraphics2D  is an API stable?
> >
> > Thank a lot for your answer.
> >
> > Regards Angelo
> >
> > 2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>
> >
> > > It turned out PDFDocumentGraphics2D was not so operational anymore.
> > > Somewhere along the way it broke. I've fixed it again [1] and added a
> > > usage example [2]. That means you'll have to download FOP Trunk [3].
> > >
> > > [1] http://svn.apache.org/viewvc?rev=1183620&view=rev
> > > [2]
> > >
> http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleJava2D2PDF.java?view=markup
> > > [3] http://xmlgraphics.apache.org/fop/download.html
> > >
> > > But guys, talking about PDFDocumentGraphics2D is getting very off-topic
> > > for this list. Please take that part to
> fop-users@xmlgraphics.apache.org
> > > from here.
> > >
> > > On 14.10.2011 23:54:56 Angelo zerr wrote:
> > > > Hi Steve
> > > >
> > > > 2011/10/14 Steve Hannah <st...@weblite.ca>
> > > >
> > > > > >
> > > > > >
> > > > > > It works but I have the same problem than PDFBox. I must manage x
> and
> > > y
> > > > > > position (increment x and y when I add some text).
> > > > > >
> > > > >
> > > > > It appears that PDFDocumentGraphics2D is just a Graphics2D context.
> > >  Then
> > > > > presumably you could pass it to the paint() method of any AWT or
> Swing
> > > > > component to have that component paint itself to the PDF.   E.g.
> Just
> > > use a
> > > > > JTextPane or a JTable, then pas the PDFDocumentGraphics2D object to
> > > their
> > > > > paint() methods
> > > > >
> > > >
> > > > Ok thank's for this information.
> > > >
> > > > >
> > > > >
> > > > >
> > > > > > I have started to manage that with PDFBox and it works great
> > > (increment x
> > > > > > when text is added, increment y when text is too long for the
> line,
> > > etc).
> > > > > >
> > > > > > I don't see the advantage to use PDFDocumentGraphics2D instread
> of
> > > using
> > > > > > PDFBox PDPageContentStream.
> > > > > > I'm afraid with FOP because:
> > > > > >
> > > > > > * PDFDocumentGraphics2D  is not documented. It seems that nobody
> > > (google
> > > > > > tell me that)  has used PDFDocumentGraphics2D to create PDF from
> > > scratch.
> > > > > >
> > > > > One google search found some API docs.
> > > > >
> > > > >
> > >
> http://www.jarvana.com/jarvana/view/org/apache/xmlgraphics/fop/1.0/fop-1.0-javadoc.jar!/org/apache/fop/svg/PDFDocumentGraphics2D.html
> > > > >
> > > > > Possibly old, but that's what 10 seconds of research found.
> > > > >
> > > >
> > > > When I said documented, I meant that I have no found documentation in
> the
> > > > FOP WebSite or other blog which explains how to use this class. I
> have
> > > not
> > > > found sample which use this class.
> > > > Your link is the Javadoc that I have already read because I have the
> > > sources
> > > > of FOP in my Eclipse Workspace.
> > > >
> > > > Regards Angelo
> > > >
> > > > >
> > > > > Best regards
> > > > >
> > > > > Steve
> > > > >
> > >
> > >
> > >
> > >
> > > Jeremias Maerki
> > >
> > >
>
>
>
>
> Jeremias Maerki
>
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Hi Angelo

PDFDocumentGraphics2D is a Graphics2D subclass, so the API is stable.
The only thing special to it is the font and page size setup and the
nextPage() method.

You program once against a Graphics2D object to paint individual pages
and that allows you to paint on the Screen (AWT/Swing), print to a
printer (javax.print) or to create SVG (SVGGraphics2D from Apache Batik),
PDF (PDFDocumentGraphics2D from Apache FOP), PostScript
(PSDocumentGraphics2D from Apache XML Graphics Commons) or whatever. I
think iText has a Graphics2D implementation, too. We could even write
one for PDFBox.

PDFBox already has the opposite direction: it takes a PDF page and can
paint it on a Graphics2D object. That's how it does PDF2Image and how
the PDFReader displays the PDF contents.

Graphics2D is a vector graphics painting API suitable for a single
page/box/screen. It works with absolute coordinates. You can use it to
create paged documents. There are tools in java.awt.text that help
laying out text but it's no full layout engine.

Word processing documents (ODF/OOXML/DOC) are flow-oriented formats,
just like HTML and XSL-FO. It's the job of a formatting engine (like
Apache FOP) to turn that into a paged format, i.e. from not having to
track X/Y to absolute positioning on a page. It does line breaking und
checks how many lines fit into a page and continues on a new page if an
overflow occurs (that's simplified).

Apparently, you have a nice API in iText that allows you to build up the
PDF by adding paragraphs and runs where you don't have to worry about
line breaking, hyphenation and page breaks. That means, iText has at
least a simple formatting engine built in. PDFBox doesn't have that (yet).
FOP has a sophisticated one for XSL-FO. Apache Batik has one for the SVG
flow-text feature (using java.text.AttributedCharacterIterator, but
heavily relying on their internal GVT framework).

The JDK has one in javax.swing.text (rendering Text, HTML and RTF, also
using java.awt.font and java.text) although I'm starting to believe that
it only supports line-breaking, not page breaking. That's the one I used
in the example for PDFDocumentGraphics2D. I can't tell if that would
make a good basis for a simple layout engine for PDFBox. But I certainly
think it might be possible to reuse some of that and try to build a
simple page breaker on top of that. I think that might actually one of
the best option for have something useful relatively quickly but it
might not fit for all possible features that ODF/OOXML offer.

So, in the end I don't think you can get around to find or program some
kind of formatter/layout engine that handles the transition from
flow-based to absolute text, when you go from ODF/OOXML to PDF.

Doing that on an engine that does not directly depend on PDFBox would
allow you to cater for more than just PDF (taking XDocReport's and ODF
Toolkit's view). That's why I suggested to have a look at FOP's
intermediate format. Because if you can generate that format you have
immediate access to all paged output formats that FOP supports (PDF, PS,
AFP, PCL, TIFF, Print). To a lesser degree the same is also possible if
you program against Graphics2D because you can then also produce various
output formats (see the list of Graphics2D implementations that I gave
above).

Please note: I don't want to deny PDFBox a nice simple (flow-oriented)
API for generating PDFs or a Graphics2D implementation. I'm just
pointing out possible directions.

And the bitter pill at the end: doing layout can be real hard. I'm
speaking from experience.

On 15.10.2011 14:09:20 Angelo zerr wrote:
> Hi Jeremias ,
> 
> Wow thta's a very cool sample! Thank a lot.
> 
> With you sample I must manage x and y position that I have started with
> PDFBox implementation.
> It seems that PDFDocumentGraphics2D  looks like PDPageContentStream (draw
> string, set font, color, exc).
> 
> So my question what is advantage to use PDFDocumentGraphics2D from FOP
> instead of PDPageContentStream from PDFBox?
> PDFDocumentGraphics2D  is an API stable?
> 
> Thank a lot for your answer.
> 
> Regards Angelo
> 
> 2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>
> 
> > It turned out PDFDocumentGraphics2D was not so operational anymore.
> > Somewhere along the way it broke. I've fixed it again [1] and added a
> > usage example [2]. That means you'll have to download FOP Trunk [3].
> >
> > [1] http://svn.apache.org/viewvc?rev=1183620&view=rev
> > [2]
> > http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleJava2D2PDF.java?view=markup
> > [3] http://xmlgraphics.apache.org/fop/download.html
> >
> > But guys, talking about PDFDocumentGraphics2D is getting very off-topic
> > for this list. Please take that part to fop-users@xmlgraphics.apache.org
> > from here.
> >
> > On 14.10.2011 23:54:56 Angelo zerr wrote:
> > > Hi Steve
> > >
> > > 2011/10/14 Steve Hannah <st...@weblite.ca>
> > >
> > > > >
> > > > >
> > > > > It works but I have the same problem than PDFBox. I must manage x and
> > y
> > > > > position (increment x and y when I add some text).
> > > > >
> > > >
> > > > It appears that PDFDocumentGraphics2D is just a Graphics2D context.
> >  Then
> > > > presumably you could pass it to the paint() method of any AWT or Swing
> > > > component to have that component paint itself to the PDF.   E.g. Just
> > use a
> > > > JTextPane or a JTable, then pas the PDFDocumentGraphics2D object to
> > their
> > > > paint() methods
> > > >
> > >
> > > Ok thank's for this information.
> > >
> > > >
> > > >
> > > >
> > > > > I have started to manage that with PDFBox and it works great
> > (increment x
> > > > > when text is added, increment y when text is too long for the line,
> > etc).
> > > > >
> > > > > I don't see the advantage to use PDFDocumentGraphics2D instread of
> > using
> > > > > PDFBox PDPageContentStream.
> > > > > I'm afraid with FOP because:
> > > > >
> > > > > * PDFDocumentGraphics2D  is not documented. It seems that nobody
> > (google
> > > > > tell me that)  has used PDFDocumentGraphics2D to create PDF from
> > scratch.
> > > > >
> > > > One google search found some API docs.
> > > >
> > > >
> > http://www.jarvana.com/jarvana/view/org/apache/xmlgraphics/fop/1.0/fop-1.0-javadoc.jar!/org/apache/fop/svg/PDFDocumentGraphics2D.html
> > > >
> > > > Possibly old, but that's what 10 seconds of research found.
> > > >
> > >
> > > When I said documented, I meant that I have no found documentation in the
> > > FOP WebSite or other blog which explains how to use this class. I have
> > not
> > > found sample which use this class.
> > > Your link is the Javadoc that I have already read because I have the
> > sources
> > > of FOP in my Eclipse Workspace.
> > >
> > > Regards Angelo
> > >
> > > >
> > > > Best regards
> > > >
> > > > Steve
> > > >
> >
> >
> >
> >
> > Jeremias Maerki
> >
> >




Jeremias Maerki


Re: Replace itext with PDFBox for XDocReport project?

Posted by Angelo zerr <an...@gmail.com>.
Hi Jeremias ,

Wow thta's a very cool sample! Thank a lot.

With you sample I must manage x and y position that I have started with
PDFBox implementation.
It seems that PDFDocumentGraphics2D  looks like PDPageContentStream (draw
string, set font, color, exc).

So my question what is advantage to use PDFDocumentGraphics2D from FOP
instead of PDPageContentStream from PDFBox?
PDFDocumentGraphics2D  is an API stable?

Thank a lot for your answer.

Regards Angelo

2011/10/15 Jeremias Maerki <de...@jeremias-maerki.ch>

> It turned out PDFDocumentGraphics2D was not so operational anymore.
> Somewhere along the way it broke. I've fixed it again [1] and added a
> usage example [2]. That means you'll have to download FOP Trunk [3].
>
> [1] http://svn.apache.org/viewvc?rev=1183620&view=rev
> [2]
> http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleJava2D2PDF.java?view=markup
> [3] http://xmlgraphics.apache.org/fop/download.html
>
> But guys, talking about PDFDocumentGraphics2D is getting very off-topic
> for this list. Please take that part to fop-users@xmlgraphics.apache.org
> from here.
>
> On 14.10.2011 23:54:56 Angelo zerr wrote:
> > Hi Steve
> >
> > 2011/10/14 Steve Hannah <st...@weblite.ca>
> >
> > > >
> > > >
> > > > It works but I have the same problem than PDFBox. I must manage x and
> y
> > > > position (increment x and y when I add some text).
> > > >
> > >
> > > It appears that PDFDocumentGraphics2D is just a Graphics2D context.
>  Then
> > > presumably you could pass it to the paint() method of any AWT or Swing
> > > component to have that component paint itself to the PDF.   E.g. Just
> use a
> > > JTextPane or a JTable, then pas the PDFDocumentGraphics2D object to
> their
> > > paint() methods
> > >
> >
> > Ok thank's for this information.
> >
> > >
> > >
> > >
> > > > I have started to manage that with PDFBox and it works great
> (increment x
> > > > when text is added, increment y when text is too long for the line,
> etc).
> > > >
> > > > I don't see the advantage to use PDFDocumentGraphics2D instread of
> using
> > > > PDFBox PDPageContentStream.
> > > > I'm afraid with FOP because:
> > > >
> > > > * PDFDocumentGraphics2D  is not documented. It seems that nobody
> (google
> > > > tell me that)  has used PDFDocumentGraphics2D to create PDF from
> scratch.
> > > >
> > > One google search found some API docs.
> > >
> > >
> http://www.jarvana.com/jarvana/view/org/apache/xmlgraphics/fop/1.0/fop-1.0-javadoc.jar!/org/apache/fop/svg/PDFDocumentGraphics2D.html
> > >
> > > Possibly old, but that's what 10 seconds of research found.
> > >
> >
> > When I said documented, I meant that I have no found documentation in the
> > FOP WebSite or other blog which explains how to use this class. I have
> not
> > found sample which use this class.
> > Your link is the Javadoc that I have already read because I have the
> sources
> > of FOP in my Eclipse Workspace.
> >
> > Regards Angelo
> >
> > >
> > > Best regards
> > >
> > > Steve
> > >
>
>
>
>
> Jeremias Maerki
>
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
It turned out PDFDocumentGraphics2D was not so operational anymore.
Somewhere along the way it broke. I've fixed it again [1] and added a
usage example [2]. That means you'll have to download FOP Trunk [3].

[1] http://svn.apache.org/viewvc?rev=1183620&view=rev
[2] http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleJava2D2PDF.java?view=markup
[3] http://xmlgraphics.apache.org/fop/download.html

But guys, talking about PDFDocumentGraphics2D is getting very off-topic
for this list. Please take that part to fop-users@xmlgraphics.apache.org
from here.

On 14.10.2011 23:54:56 Angelo zerr wrote:
> Hi Steve
> 
> 2011/10/14 Steve Hannah <st...@weblite.ca>
> 
> > >
> > >
> > > It works but I have the same problem than PDFBox. I must manage x and y
> > > position (increment x and y when I add some text).
> > >
> >
> > It appears that PDFDocumentGraphics2D is just a Graphics2D context.  Then
> > presumably you could pass it to the paint() method of any AWT or Swing
> > component to have that component paint itself to the PDF.   E.g. Just use a
> > JTextPane or a JTable, then pas the PDFDocumentGraphics2D object to their
> > paint() methods
> >
> 
> Ok thank's for this information.
> 
> >
> >
> >
> > > I have started to manage that with PDFBox and it works great (increment x
> > > when text is added, increment y when text is too long for the line, etc).
> > >
> > > I don't see the advantage to use PDFDocumentGraphics2D instread of using
> > > PDFBox PDPageContentStream.
> > > I'm afraid with FOP because:
> > >
> > > * PDFDocumentGraphics2D  is not documented. It seems that nobody (google
> > > tell me that)  has used PDFDocumentGraphics2D to create PDF from scratch.
> > >
> > One google search found some API docs.
> >
> > http://www.jarvana.com/jarvana/view/org/apache/xmlgraphics/fop/1.0/fop-1.0-javadoc.jar!/org/apache/fop/svg/PDFDocumentGraphics2D.html
> >
> > Possibly old, but that's what 10 seconds of research found.
> >
> 
> When I said documented, I meant that I have no found documentation in the
> FOP WebSite or other blog which explains how to use this class. I have not
> found sample which use this class.
> Your link is the Javadoc that I have already read because I have the sources
> of FOP in my Eclipse Workspace.
> 
> Regards Angelo
> 
> >
> > Best regards
> >
> > Steve
> >




Jeremias Maerki


Re: Replace itext with PDFBox for XDocReport project?

Posted by Angelo zerr <an...@gmail.com>.
Hi Steve

2011/10/14 Steve Hannah <st...@weblite.ca>

> >
> >
> > It works but I have the same problem than PDFBox. I must manage x and y
> > position (increment x and y when I add some text).
> >
>
> It appears that PDFDocumentGraphics2D is just a Graphics2D context.  Then
> presumably you could pass it to the paint() method of any AWT or Swing
> component to have that component paint itself to the PDF.   E.g. Just use a
> JTextPane or a JTable, then pas the PDFDocumentGraphics2D object to their
> paint() methods
>

Ok thank's for this information.

>
>
>
> > I have started to manage that with PDFBox and it works great (increment x
> > when text is added, increment y when text is too long for the line, etc).
> >
> > I don't see the advantage to use PDFDocumentGraphics2D instread of using
> > PDFBox PDPageContentStream.
> > I'm afraid with FOP because:
> >
> > * PDFDocumentGraphics2D  is not documented. It seems that nobody (google
> > tell me that)  has used PDFDocumentGraphics2D to create PDF from scratch.
> >
> One google search found some API docs.
>
> http://www.jarvana.com/jarvana/view/org/apache/xmlgraphics/fop/1.0/fop-1.0-javadoc.jar!/org/apache/fop/svg/PDFDocumentGraphics2D.html
>
> Possibly old, but that's what 10 seconds of research found.
>

When I said documented, I meant that I have no found documentation in the
FOP WebSite or other blog which explains how to use this class. I have not
found sample which use this class.
Your link is the Javadoc that I have already read because I have the sources
of FOP in my Eclipse Workspace.

Regards Angelo

>
> Best regards
>
> Steve
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Steve Hannah <st...@weblite.ca>.
>
>
> It works but I have the same problem than PDFBox. I must manage x and y
> position (increment x and y when I add some text).
>

It appears that PDFDocumentGraphics2D is just a Graphics2D context.  Then
presumably you could pass it to the paint() method of any AWT or Swing
component to have that component paint itself to the PDF.   E.g. Just use a
JTextPane or a JTable, then pas the PDFDocumentGraphics2D object to their
paint() methods



> I have started to manage that with PDFBox and it works great (increment x
> when text is added, increment y when text is too long for the line, etc).
>
> I don't see the advantage to use PDFDocumentGraphics2D instread of using
> PDFBox PDPageContentStream.
> I'm afraid with FOP because:
>
> * PDFDocumentGraphics2D  is not documented. It seems that nobody (google
> tell me that)  has used PDFDocumentGraphics2D to create PDF from scratch.
>
One google search found some API docs.
http://www.jarvana.com/jarvana/view/org/apache/xmlgraphics/fop/1.0/fop-1.0-javadoc.jar!/org/apache/fop/svg/PDFDocumentGraphics2D.html

Possibly old, but that's what 10 seconds of research found.

Best regards

Steve

Re: Replace itext with PDFBox for XDocReport project?

Posted by Angelo zerr <an...@gmail.com>.
@Eric iText license is a problem for us if we wish gives our code to Apache.

@Jeremias :I have tried to use PDFDocumentGraphics2D to generate simple PDF
like

--------------------------
AAAA BBBB
--------------------------

with this code :

------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.fop.svg.PDFDocumentGraphics2D;
import org.apache.xmlgraphics.java2d.GraphicContext;

public class Test {

    public static void main(String[] args) throws IOException {

        File pdfFile = new File("test.pdf");
        PDFDocumentGraphics2D doc = new PDFDocumentGraphics2D(false);
        doc.setupDefaultFontInfo();
        doc.setGraphicContext(new GraphicContext());

        OutputStream stream = new FileOutputStream(pdfFile);
        doc.setupDocument(stream, 200, 700);
        doc.setDeviceDPI(60);

        doc.drawString("AAAA", 100, 100);
        doc.drawString("BBBB", 160, 100);

        stream.flush();
        doc.finish();
        stream.close();
    }
}
------------------------------------------------------------------------------------------------------------------------------------------------------------

It works but I have the same problem than PDFBox. I must manage x and y
position (increment x and y when I add some text).
I have started to manage that with PDFBox and it works great (increment x
when text is added, increment y when text is too long for the line, etc).

I don't see the advantage to use PDFDocumentGraphics2D instread of using
PDFBox PDPageContentStream.
I'm afraid with FOP because:

* PDFDocumentGraphics2D  is not documented. It seems that nobody (google
tell me that)  has used PDFDocumentGraphics2D to create PDF from scratch.
* PDFDocumentGraphics2D is it an API stable?
* there are a lof of dependencies (batik, etc)

Regards Angelo

2011/10/14 Jeremias Maerki <de...@jeremias-maerki.ch>

> On 14.10.2011 19:09:32 Eric Douglas wrote:
> > Why switch from iText?  What is the issue with the license?  The only
> > thing I can tell is you can't reference iText from your code if you plan
> > to sell your code.  Is there something else I'm missing?  It's highly
> > doubtful they'd sell the code I write, it's all for in house projects.
>
> ASF License Policy: the ASF wants to provide software that people can be
> use in any software, including commercial applications. Recent iText
> versions are published under the AGPL which makes it a complete no-go as
> a dependency on source code hosted at the ASF.
> http://www.apache.org/legal/3party.html
>
> > Does pdfbox do the one thing that iText does that we need to do (if it
> > does we're not seeing it)?  For my purpose we just want a report API
> > that can provide a Graphics object to create a PDF with the exact same
> > code we're using to draw a screen (but Pageable).  Our code for drawing
> > the screen is pageable but of course we can only draw one page at a
> > time.
>
> --> org.apache.fop.svg.PDFDocumentGraphics2D
>
> You can even do multi-page by calling its nextPage() method.
>
>
> Jeremias Maerki
>
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
On 14.10.2011 19:09:32 Eric Douglas wrote:
> Why switch from iText?  What is the issue with the license?  The only
> thing I can tell is you can't reference iText from your code if you plan
> to sell your code.  Is there something else I'm missing?  It's highly
> doubtful they'd sell the code I write, it's all for in house projects.

ASF License Policy: the ASF wants to provide software that people can be
use in any software, including commercial applications. Recent iText
versions are published under the AGPL which makes it a complete no-go as
a dependency on source code hosted at the ASF.
http://www.apache.org/legal/3party.html

> Does pdfbox do the one thing that iText does that we need to do (if it
> does we're not seeing it)?  For my purpose we just want a report API
> that can provide a Graphics object to create a PDF with the exact same
> code we're using to draw a screen (but Pageable).  Our code for drawing
> the screen is pageable but of course we can only draw one page at a
> time.

--> org.apache.fop.svg.PDFDocumentGraphics2D

You can even do multi-page by calling its nextPage() method.


Jeremias Maerki


RE: Replace itext with PDFBox for XDocReport project?

Posted by Eric Douglas <ed...@blockhouse.com>.
Why switch from iText?  What is the issue with the license?  The only
thing I can tell is you can't reference iText from your code if you plan
to sell your code.  Is there something else I'm missing?  It's highly
doubtful they'd sell the code I write, it's all for in house projects.

Does pdfbox do the one thing that iText does that we need to do (if it
does we're not seeing it)?  For my purpose we just want a report API
that can provide a Graphics object to create a PDF with the exact same
code we're using to draw a screen (but Pageable).  Our code for drawing
the screen is pageable but of course we can only draw one page at a
time.

Re: Replace itext with PDFBox for XDocReport project?

Posted by Kévin Sailly <ke...@gmail.com>.
Nothing at the moment, I was working on the ability to get the text
justified on a page.
I am trying to apply that style to PDPageContentStream, but this could be
suitable for something like "PDParagraphContentStream" as a style for
PDFBoxParagraph.

I will try to finish this development this week if I found enough time.



2011/10/14 Angelo zerr <an...@gmail.com>

> That's cool.
>
> Ok Kevin, I will tell you when I will commit my work.
> Do you have developped something? If yes, which widgets do you have
> managed?
> Table, Paragraph, etc
>
> In my case I have developped the case with paragraph (which seems simple
> but
> complex for me a newbie with PDFBox) because x and y must be computed every
> time.
>
> Regards Angelo
>
> 2011/10/14 Kévin Sailly <ke...@gmail.com>
>
> > It sounds good...
> >
> >
> >
> > 2011/10/14 Angelo zerr <an...@gmail.com>
> >
> > > Ok I understand. I think we have the same goal :
> > >
> > > 1) My goal: docx -> PDF.
> > > 2) Your goal : XML -> PDF.
> > >
> > > My idea is to provide a Java DOM-like PDFBox.(When I say DOM, its not
> w3c
> > > DOM). So you can use it just with Java code liek this:
> > >
> > >
> > >
> >
> -----------------------------------------------------------------------------------------------
> > > PDFBoxDocument document = new PDFBoxDocument();
> > > PDFBoxParagraph paragraph = document.addParagraph();
> > > paragraph.addRun("AAAA");
> > > paragraph.addRun(" ");
> > > paragraph.addRun("BBB");
> > >
> > >
> >
> -----------------------------------------------------------------------------------------------
> > >
> > > For my case (docx) I will load my docx with POI to have docx Java
> > scrutcure
> > > and I will loop to thoses structure to createPDFBoxDocument ,
> > > PDFBoxParagraph instances.
> > >
> > > For your case (HTML) you could implement SAX handler like :
> > >
> > >
> > >
> >
> -----------------------------------------------------------------------------------------------
> > > public void startElement(String uri, String localName, String name,
> > > Attributes atts) throws SAXException {
> > > if ("p".localName) {
> > > PDFBoxParagraph paragraph = document.addParagraph();
> > > }
> > > }
> > >
> > >
> >
> -----------------------------------------------------------------------------------------------
> > >
> > > docx and HTML (your sample) manages too styles. So I would like to
> manage
> > a
> > > style method like this:
> > >
> > >
> > >
> >
> -----------------------------------------------------------------------------------------------
> > > ParagraphStyle style=new ParagraphStyle();
> > > style.setMargin(10);
> > > PDFBoxParagraph paragraph = document.addParagraph();
> > > paragraph.applyStyle(style);
> > >
> > >
> >
> -----------------------------------------------------------------------------------------------
> > >
> > > ParagraphStyle could be populated with CSS or declared styles.
> > >
> > > What do you think?
> > >
> > > Regards Angelo
> > >
> > > 2011/10/14 Kévin Sailly <ke...@gmail.com>
> > >
> > > > Angelo,
> > > >
> > > > My goal is to get some text like:
> > > > <p>some text</p>
> > > > <p style="margin-left: 30px;">this one positionned!</p>
> > > >
> > > > And then produce the PDF with style applied:
> > > > some text
> > > >      this one positionned!
> > > >
> > > > Regards,
> > > > Kéivn
> > > >
> > > >
> > > >
> > > >
> > > > 2011/10/14 Angelo zerr <an...@gmail.com>
> > > >
> > > > > Hi Srinivaas,
> > > > >
> > > > > At first my PDFBox-DOM like can be used without docx (I must manage
> > odt
> > > > > too). And my idea is to use that for another application.
> > > > > Your idea to convert docx 2 PDF with FOP, I have already
> implemented
> > > but
> > > > I
> > > > > don't like that :
> > > > >
> > > > > 1) FOP converter is very more slowly than iText converter. The
> > > > explanation
> > > > > is simple :
> > > > > => FOP process :  docx -> XSLT -> XSL-FO -> PDF
> > > > > => iText process : docx -> (POI to get Java model) -> iText
> > > > >
> > > > > As you can notice with FOP process are more steps than IText
> process.
> > > FOP
> > > > > process for docx is less powerfull than iText process and I have a
> > lot
> > > > > optimized my XSL (XSL Template is in a cahe, I'm using xsl:key,
> etc).
> > > > >
> > > > > 2) with FOP converter you manage the conversion with XSL. With
> IText
> > > > > converter you manage teh conversion with Java.
> > > > > IMHO, I prefer developping Java than XSL. Debug XSL is very hard
> > > compare
> > > > > debug Java code.
> > > > > More docx use  styles.xml where style A can extends style B. With
> XSL
> > I
> > > > > compute style every time (how to manage some cache with XSL?)
> > although
> > > > with
> > > > > Java I compute one time.
> > > > >
> > > > > Our iText converter works great but for license problem we can give
> > our
> > > > > code
> > > > > to Apacahe. So I'm investiagting PDFBox.
> > > > >
> > > > > Regards Angelo
> > > > >
> > > > > 2011/10/14 Srinivaas_Venkatarayan <
> > > > > Srinivaas_Venkatarayan@mahindrasatyam.com
> > > > > >
> > > > >
> > > > > > Hi Angelo, If the source is going to be docx file, can you not
> use
> > > xslt
> > > > > and
> > > > > > FOP to convert the xml (provided by docx file) to PDF?
> > > > > >
> > > > > > Srinivaas
> > > > > >
> > > > > > -----Original Message-----
> > > > > > From: Angelo zerr [mailto:angelo.zerr@gmail.com]
> > > > > > Sent: Friday, October 14, 2011 5:07 PM
> > > > > > To: users@pdfbox.apache.org
> > > > > > Subject: Re: Replace itext with PDFBox for XDocReport project?
> > > > > >
> > > > > > Hi Kevin,
> > > > > >
> > > > > > What do you mean with richtext? In my case I would like create a
> > PDF
> > > > from
> > > > > > scratch with PDF DOM-like with the same mean than iText.
> > > > > > I have started to create a project (not commited for the moment
> > > > > >
> > > > > > Here my (basic sample) to generate paragraph with several text
> > > content
> > > > > > (that
> > > > > > I have called run like docx)
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > > > > PDFBoxDocument document = new PDFBoxDocument();
> > > > > >
> > > > > > PDFBoxParagraph paragraph = document.addParagraph();
> > > > > > paragraph.addRun("AAAA");
> > > > > > paragraph.addRun(" ");
> > > > > > paragraph.addRun("BBB");
> > > > > >
> > > > > > document.save("test.pdf");
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > > > >
> > > > > > This code generate a PDF with :
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > > > > AAAA BBB
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > > > >
> > > > > > If you are interested (working together?) I could commit my work
> on
> > > our
> > > > > > XDocReport git.
> > > > > >
> > > > > > Regards Angelo
> > > > > >
> > > > > > 2011/10/14 Kévin Sailly <ke...@gmail.com>
> > > > > >
> > > > > > > Hello,
> > > > > > >
> > > > > > > I am planning to build some code to create text from richtext
> > (text
> > > > > from
> > > > > > > rech text editor), is that what you are planning to do?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Kévin
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > 2011/10/13 Angelo zerr <an...@gmail.com>
> > > > > > >
> > > > > > > > Hi PDFBox Team,
> > > > > > > >
> > > > > > > > I have started to investigate time with PDFBox to try to
> > provides
> > > > > > > > High-Level
> > > > > > > > API to manage paragraph, table widgets etc....
> > > > > > > > I recall my problem : we are using iText for our ODT->PDF and
> > > > > Docx->PDF
> > > > > > > > converter and we wish provides our code for Apache. Problem
> is
> > > > iText
> > > > > > > > license.
> > > > > > > > So I'm searching PDF API (PDFBox?FOP?) to manage PDF with
> Java
> > > > model
> > > > > > (not
> > > > > > > > with XSL-FO). It seems that FOP provides this feature, but
> it's
> > > > very
> > > > > > hard
> > > > > > > > to
> > > > > > > > understand how to manage that?
> > > > > > > >
> > > > > > > > I have tried to manage a simple case : a paragraph with some
> > > text.
> > > > I
> > > > > > > would
> > > > > > > > like generate PDF with this content:
> > > > > > > >
> > > > > > > > ----------------------------
> > > > > > > > AAAA BBBB
> > > > > > > > ----------------------------
> > > > > > > >
> > > > > > > > But not with one String but with 3 Strings (call 3 times
> > > > > > > > contentStream.drawString(...);)
> > > > > > > > The solution that I have found to manage that is to store the
> > > last
> > > > X
> > > > > of
> > > > > > > the
> > > > > > > > added Stringby using Stringlenght+Font + Font size. Here my
> > code
> > > > > > > >
> > > > > > > > ------------------------------------------------------
> > > > > > > > import java.io.IOException;
> > > > > > > >
> > > > > > > > import org.apache.pdfbox.exceptions.COSVisitorException;
> > > > > > > > import org.apache.pdfbox.pdmodel.PDDocument;
> > > > > > > > import org.apache.pdfbox.pdmodel.PDPage;
> > > > > > > > import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
> > > > > > > > import org.apache.pdfbox.pdmodel.font.PDFont;
> > > > > > > > import org.apache.pdfbox.pdmodel.font.PDType1Font;
> > > > > > > >
> > > > > > > > public class Test3 {
> > > > > > > >
> > > > > > > >    private static float lastX = 0;
> > > > > > > >
> > > > > > > >    public static void main(String[] args) throws IOException,
> > > > > > > >            COSVisitorException {
> > > > > > > >        PDDocument doc = null;
> > > > > > > >        try {
> > > > > > > >            doc = new PDDocument();
> > > > > > > >
> > > > > > > >            PDPage page = new PDPage();
> > > > > > > >            doc.addPage(page);
> > > > > > > >
> > > > > > > >            PDPageContentStream contentStream = new
> > > > > > > PDPageContentStream(doc,
> > > > > > > >                    page);
> > > > > > > >
> > > > > > > >            PDFont font = PDType1Font.HELVETICA_BOLD;
> > > > > > > >            long fontSize = 5;
> > > > > > > >            addText("AAAA", font, fontSize, page,
> > contentStream);
> > > > > > > >            addText(" ", font, fontSize, page, contentStream);
> > > > > > > >            addText("BBBB", font, fontSize, page,
> > contentStream);
> > > > > > > >
> > > > > > > >            contentStream.close();
> > > > > > > >
> > > > > > > >            doc.save("test.pdf");
> > > > > > > >
> > > > > > > >        } finally {
> > > > > > > >            if (doc != null) {
> > > > > > > >                doc.close();
> > > > > > > >            }
> > > > > > > >        }
> > > > > > > >    }
> > > > > > > >
> > > > > > > >    public static void addText(String text, PDFont font, long
> > > > > fontSize,
> > > > > > > >            PDPage page, PDPageContentStream contentStream)
> > throws
> > > > > > > > IOException {
> > > > > > > >
> > > > > > > >        // Compute x
> > > > > > > >        float x = lastX;
> > > > > > > >        float nextX = lastX + font.getStringWidth(text) *
> > fontSize
> > > /
> > > > > > > 1000f;
> > > > > > > >
> > > > > > > >        // Compute Y
> > > > > > > >        float y = page.getMediaBox().getHeight()
> > > > > > > >                - (font.getFontHeight("A".getBytes(), 0, 1) *
> > > > fontSize
> > > > > /
> > > > > > > > 1000f);
> > > > > > > >
> > > > > > > >        contentStream.beginText();
> > > > > > > >        contentStream.setFont(font, fontSize);
> > > > > > > >        contentStream.moveTextPositionByAmount(x, y);
> > > > > > > >        contentStream.drawString(text);
> > > > > > > >        contentStream.endText();
> > > > > > > >
> > > > > > > >        // Recompute lastX
> > > > > > > >        lastX = nextX;
> > > > > > > >    }
> > > > > > > >
> > > > > > > > }
> > > > > > > > ------------------------------------------------------
> > > > > > > >
> > > > > > > > I would like know if it's the correct mean? If it's OK, I
> would
> > > > like
> > > > > > know
> > > > > > > > if
> > > > > > > > it's possible to retrieve the default Font of the document,
> > > because
> > > > > in
> > > > > > my
> > > > > > > > case I have setted the Font?
> > > > > > > >
> > > > > > > > My code doesn't manage wrap text and I would like know how to
> > > > manage
> > > > > > > that?
> > > > > > > >
> > > > > > > > I'm very interested to provides and contribute Hight level
> API
> > > for
> > > > > > PDFBox
> > > > > > > > (paragraph, table...) but if I have no support I will give up
> > my
> > > > idea
> > > > > > > (hope
> > > > > > > > you will understand).
> > > > > > > >
> > > > > > > > Thank a lot for your help!
> > > > > > > >
> > > > > > > > Regards Angelo
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > 2011/9/5 Angelo zerr <an...@gmail.com>
> > > > > > > >
> > > > > > > > > Hi Jeremias,
> > > > > > > > >
> > > > > > > > > I'm sorry I have not seen your answer
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > > > > > > > When I have studied FOP to manage PDF just with Java PDF
> > widget
> > > I
> > > > > > have
> > > > > > > > not
> > > > > > > > > found documentation so I believed that it was not possible,
> > but
> > > > it
> > > > > > > seems
> > > > > > > > > that is possible.
> > > > > > > > > That's very cool. I will study that.
> > > > > > > > >
> > > > > > > > > Many thanks!
> > > > > > > > >
> > > > > > > > > Regards Angelo
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > 2011/9/5 Jeremias Maerki <de...@jeremias-maerki.ch>
> > > > > > > > >
> > > > > > > > >> Angelo,
> > > > > > > > >> as I explained in [1], you don't have to use XSL-FO when
> > using
> > > > > > Apache
> > > > > > > > >> FOP. It supports alternative means to create PDFs.
> > > > > > > > >>
> > > > > > > > >> [1]
> > > > > > > > >>
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > > > > > > >>
> > > > > > > > >> But of course, Apache PDFBox would profit a lot from a
> > > > > higher-level
> > > > > > > PDF
> > > > > > > > >> production API. Any contributions are more than welcome.
> > > > > > > > >>
> > > > > > > > >> On 05.09.2011 10:56:20 Angelo zerr wrote:
> > > > > > > > >> > Hi Jukka,
> > > > > > > > >> >
> > > > > > > > >> > Thank a lot for you answer. I have already implemented a
> > > > > docx->PDF
> > > > > > > and
> > > > > > > > >> > odt->PDF converters with FOP but I decided to give up
> for
> > :
> > > > > > > > >> >
> > > > > > > > >> > * performance reason. I have used XSLT cache, use
> xsl:key
> > to
> > > > > > compute
> > > > > > > > the
> > > > > > > > >> > odt/docx styles but the FOP implementation is less
> > > performant
> > > > > than
> > > > > > > > iText
> > > > > > > > >> > implementation, because :
> > > > > > > > >> >   * FOP process : odt -> XSLT -> FO -> FOP
> > > > > > > > >> >   * iText process : odt -> ODFDOM (Java) -> iText
> > > > > > > > >> > * xslt vs Java model : with the iText process, your
> model
> > is
> > > > > Java,
> > > > > > > > >> although
> > > > > > > > >> > with FOP your model is XML. I prefer develop Java
> instead
> > of
> > > > > XSLT.
> > > > > > > > >> >
> > > > > > > > >> > That's why I'm searching Java PDF API like PDFBox to
> > replace
> > > > > iText
> > > > > > > to
> > > > > > > > >> > provides our code to Apache.
> > > > > > > > >> >
> > > > > > > > >> > Regards Angelo
> > > > > > > > >> >
> > > > > > > > >> > 2011/9/5 Jukka Zitting <ju...@gmail.com>
> > > > > > > > >> >
> > > > > > > > >> > > Hi Angelo,
> > > > > > > > >> > >
> > > > > > > > >> > > On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <
> > > > > > > angelo.zerr@gmail.com
> > > > > > > > >
> > > > > > > > >> > > wrote:
> > > > > > > > >> > > > I suppose that my post was not well explained as I
> > have
> > > no
> > > > > > > answer.
> > > > > > > > I
> > > > > > > > >> will
> > > > > > > > >> > > be
> > > > > > > > >> > > > very happy to use PDFBox in our XDocReport converter
> > > > (docx->
> > > > > > PDF
> > > > > > > > and
> > > > > > > > >> > > odt->
> > > > > > > > >> > > > PDF) but develop converter is a big work and I can
> not
> > > > > > > investiaget
> > > > > > > > >> time
> > > > > > > > >> > > if I
> > > > > > > > >> > > > have no support.
> > > > > > > > >> > >
> > > > > > > > >> > > There's been some interest in making it easier to use
> > > PDFBox
> > > > > to
> > > > > > > > >> > > generate complex new PDF documents, but so far the
> main
> > > use
> > > > > > cases
> > > > > > > > have
> > > > > > > > >> > > been simpler. You might want to look at Apache FOP
> > > > > > > > >> > > (http://xmlgraphics.apache.org/fop/) for a
> higher-level
> > > PDF
> > > > > > > > >> generation
> > > > > > > > >> > > tool.
> > > > > > > > >> > >
> > > > > > > > >> > > BR,
> > > > > > > > >> > >
> > > > > > > > >> > > Jukka Zitting
> > > > > > > > >> > >
> > > > > > > > >>
> > > > > > > > >>
> > > > > > > > >>
> > > > > > > > >>
> > > > > > > > >> Jeremias Maerki
> > > > > > > > >>
> > > > > > > > >>
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > > > DISCLAIMER:
> > > > > > This email (including any attachments) is intended for the sole
> use
> > > of
> > > > > the
> > > > > > intended recipient/s and may contain material that is
> CONFIDENTIAL
> > > AND
> > > > > > PRIVATE COMPANY INFORMATION. Any review or reliance by others or
> > > > copying
> > > > > or
> > > > > > distribution or forwarding of any or all of the contents in this
> > > > message
> > > > > is
> > > > > > STRICTLY PROHIBITED. If you are not the intended recipient,
> please
> > > > > contact
> > > > > > the sender by email and delete all copies; your cooperation in
> this
> > > > > regard
> > > > > > is appreciated.
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Angelo zerr <an...@gmail.com>.
That's cool.

Ok Kevin, I will tell you when I will commit my work.
Do you have developped something? If yes, which widgets do you have managed?
Table, Paragraph, etc

In my case I have developped the case with paragraph (which seems simple but
complex for me a newbie with PDFBox) because x and y must be computed every
time.

Regards Angelo

2011/10/14 Kévin Sailly <ke...@gmail.com>

> It sounds good...
>
>
>
> 2011/10/14 Angelo zerr <an...@gmail.com>
>
> > Ok I understand. I think we have the same goal :
> >
> > 1) My goal: docx -> PDF.
> > 2) Your goal : XML -> PDF.
> >
> > My idea is to provide a Java DOM-like PDFBox.(When I say DOM, its not w3c
> > DOM). So you can use it just with Java code liek this:
> >
> >
> >
> -----------------------------------------------------------------------------------------------
> > PDFBoxDocument document = new PDFBoxDocument();
> > PDFBoxParagraph paragraph = document.addParagraph();
> > paragraph.addRun("AAAA");
> > paragraph.addRun(" ");
> > paragraph.addRun("BBB");
> >
> >
> -----------------------------------------------------------------------------------------------
> >
> > For my case (docx) I will load my docx with POI to have docx Java
> scrutcure
> > and I will loop to thoses structure to createPDFBoxDocument ,
> > PDFBoxParagraph instances.
> >
> > For your case (HTML) you could implement SAX handler like :
> >
> >
> >
> -----------------------------------------------------------------------------------------------
> > public void startElement(String uri, String localName, String name,
> > Attributes atts) throws SAXException {
> > if ("p".localName) {
> > PDFBoxParagraph paragraph = document.addParagraph();
> > }
> > }
> >
> >
> -----------------------------------------------------------------------------------------------
> >
> > docx and HTML (your sample) manages too styles. So I would like to manage
> a
> > style method like this:
> >
> >
> >
> -----------------------------------------------------------------------------------------------
> > ParagraphStyle style=new ParagraphStyle();
> > style.setMargin(10);
> > PDFBoxParagraph paragraph = document.addParagraph();
> > paragraph.applyStyle(style);
> >
> >
> -----------------------------------------------------------------------------------------------
> >
> > ParagraphStyle could be populated with CSS or declared styles.
> >
> > What do you think?
> >
> > Regards Angelo
> >
> > 2011/10/14 Kévin Sailly <ke...@gmail.com>
> >
> > > Angelo,
> > >
> > > My goal is to get some text like:
> > > <p>some text</p>
> > > <p style="margin-left: 30px;">this one positionned!</p>
> > >
> > > And then produce the PDF with style applied:
> > > some text
> > >      this one positionned!
> > >
> > > Regards,
> > > Kéivn
> > >
> > >
> > >
> > >
> > > 2011/10/14 Angelo zerr <an...@gmail.com>
> > >
> > > > Hi Srinivaas,
> > > >
> > > > At first my PDFBox-DOM like can be used without docx (I must manage
> odt
> > > > too). And my idea is to use that for another application.
> > > > Your idea to convert docx 2 PDF with FOP, I have already implemented
> > but
> > > I
> > > > don't like that :
> > > >
> > > > 1) FOP converter is very more slowly than iText converter. The
> > > explanation
> > > > is simple :
> > > > => FOP process :  docx -> XSLT -> XSL-FO -> PDF
> > > > => iText process : docx -> (POI to get Java model) -> iText
> > > >
> > > > As you can notice with FOP process are more steps than IText process.
> > FOP
> > > > process for docx is less powerfull than iText process and I have a
> lot
> > > > optimized my XSL (XSL Template is in a cahe, I'm using xsl:key, etc).
> > > >
> > > > 2) with FOP converter you manage the conversion with XSL. With IText
> > > > converter you manage teh conversion with Java.
> > > > IMHO, I prefer developping Java than XSL. Debug XSL is very hard
> > compare
> > > > debug Java code.
> > > > More docx use  styles.xml where style A can extends style B. With XSL
> I
> > > > compute style every time (how to manage some cache with XSL?)
> although
> > > with
> > > > Java I compute one time.
> > > >
> > > > Our iText converter works great but for license problem we can give
> our
> > > > code
> > > > to Apacahe. So I'm investiagting PDFBox.
> > > >
> > > > Regards Angelo
> > > >
> > > > 2011/10/14 Srinivaas_Venkatarayan <
> > > > Srinivaas_Venkatarayan@mahindrasatyam.com
> > > > >
> > > >
> > > > > Hi Angelo, If the source is going to be docx file, can you not use
> > xslt
> > > > and
> > > > > FOP to convert the xml (provided by docx file) to PDF?
> > > > >
> > > > > Srinivaas
> > > > >
> > > > > -----Original Message-----
> > > > > From: Angelo zerr [mailto:angelo.zerr@gmail.com]
> > > > > Sent: Friday, October 14, 2011 5:07 PM
> > > > > To: users@pdfbox.apache.org
> > > > > Subject: Re: Replace itext with PDFBox for XDocReport project?
> > > > >
> > > > > Hi Kevin,
> > > > >
> > > > > What do you mean with richtext? In my case I would like create a
> PDF
> > > from
> > > > > scratch with PDF DOM-like with the same mean than iText.
> > > > > I have started to create a project (not commited for the moment
> > > > >
> > > > > Here my (basic sample) to generate paragraph with several text
> > content
> > > > > (that
> > > > > I have called run like docx)
> > > > >
> > > > >
> > > > >
> > > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > > > PDFBoxDocument document = new PDFBoxDocument();
> > > > >
> > > > > PDFBoxParagraph paragraph = document.addParagraph();
> > > > > paragraph.addRun("AAAA");
> > > > > paragraph.addRun(" ");
> > > > > paragraph.addRun("BBB");
> > > > >
> > > > > document.save("test.pdf");
> > > > >
> > > > >
> > > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > > >
> > > > > This code generate a PDF with :
> > > > >
> > > > >
> > > > >
> > > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > > > AAAA BBB
> > > > >
> > > > >
> > > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > > >
> > > > > If you are interested (working together?) I could commit my work on
> > our
> > > > > XDocReport git.
> > > > >
> > > > > Regards Angelo
> > > > >
> > > > > 2011/10/14 Kévin Sailly <ke...@gmail.com>
> > > > >
> > > > > > Hello,
> > > > > >
> > > > > > I am planning to build some code to create text from richtext
> (text
> > > > from
> > > > > > rech text editor), is that what you are planning to do?
> > > > > >
> > > > > > Regards,
> > > > > > Kévin
> > > > > >
> > > > > >
> > > > > >
> > > > > > 2011/10/13 Angelo zerr <an...@gmail.com>
> > > > > >
> > > > > > > Hi PDFBox Team,
> > > > > > >
> > > > > > > I have started to investigate time with PDFBox to try to
> provides
> > > > > > > High-Level
> > > > > > > API to manage paragraph, table widgets etc....
> > > > > > > I recall my problem : we are using iText for our ODT->PDF and
> > > > Docx->PDF
> > > > > > > converter and we wish provides our code for Apache. Problem is
> > > iText
> > > > > > > license.
> > > > > > > So I'm searching PDF API (PDFBox?FOP?) to manage PDF with Java
> > > model
> > > > > (not
> > > > > > > with XSL-FO). It seems that FOP provides this feature, but it's
> > > very
> > > > > hard
> > > > > > > to
> > > > > > > understand how to manage that?
> > > > > > >
> > > > > > > I have tried to manage a simple case : a paragraph with some
> > text.
> > > I
> > > > > > would
> > > > > > > like generate PDF with this content:
> > > > > > >
> > > > > > > ----------------------------
> > > > > > > AAAA BBBB
> > > > > > > ----------------------------
> > > > > > >
> > > > > > > But not with one String but with 3 Strings (call 3 times
> > > > > > > contentStream.drawString(...);)
> > > > > > > The solution that I have found to manage that is to store the
> > last
> > > X
> > > > of
> > > > > > the
> > > > > > > added Stringby using Stringlenght+Font + Font size. Here my
> code
> > > > > > >
> > > > > > > ------------------------------------------------------
> > > > > > > import java.io.IOException;
> > > > > > >
> > > > > > > import org.apache.pdfbox.exceptions.COSVisitorException;
> > > > > > > import org.apache.pdfbox.pdmodel.PDDocument;
> > > > > > > import org.apache.pdfbox.pdmodel.PDPage;
> > > > > > > import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
> > > > > > > import org.apache.pdfbox.pdmodel.font.PDFont;
> > > > > > > import org.apache.pdfbox.pdmodel.font.PDType1Font;
> > > > > > >
> > > > > > > public class Test3 {
> > > > > > >
> > > > > > >    private static float lastX = 0;
> > > > > > >
> > > > > > >    public static void main(String[] args) throws IOException,
> > > > > > >            COSVisitorException {
> > > > > > >        PDDocument doc = null;
> > > > > > >        try {
> > > > > > >            doc = new PDDocument();
> > > > > > >
> > > > > > >            PDPage page = new PDPage();
> > > > > > >            doc.addPage(page);
> > > > > > >
> > > > > > >            PDPageContentStream contentStream = new
> > > > > > PDPageContentStream(doc,
> > > > > > >                    page);
> > > > > > >
> > > > > > >            PDFont font = PDType1Font.HELVETICA_BOLD;
> > > > > > >            long fontSize = 5;
> > > > > > >            addText("AAAA", font, fontSize, page,
> contentStream);
> > > > > > >            addText(" ", font, fontSize, page, contentStream);
> > > > > > >            addText("BBBB", font, fontSize, page,
> contentStream);
> > > > > > >
> > > > > > >            contentStream.close();
> > > > > > >
> > > > > > >            doc.save("test.pdf");
> > > > > > >
> > > > > > >        } finally {
> > > > > > >            if (doc != null) {
> > > > > > >                doc.close();
> > > > > > >            }
> > > > > > >        }
> > > > > > >    }
> > > > > > >
> > > > > > >    public static void addText(String text, PDFont font, long
> > > > fontSize,
> > > > > > >            PDPage page, PDPageContentStream contentStream)
> throws
> > > > > > > IOException {
> > > > > > >
> > > > > > >        // Compute x
> > > > > > >        float x = lastX;
> > > > > > >        float nextX = lastX + font.getStringWidth(text) *
> fontSize
> > /
> > > > > > 1000f;
> > > > > > >
> > > > > > >        // Compute Y
> > > > > > >        float y = page.getMediaBox().getHeight()
> > > > > > >                - (font.getFontHeight("A".getBytes(), 0, 1) *
> > > fontSize
> > > > /
> > > > > > > 1000f);
> > > > > > >
> > > > > > >        contentStream.beginText();
> > > > > > >        contentStream.setFont(font, fontSize);
> > > > > > >        contentStream.moveTextPositionByAmount(x, y);
> > > > > > >        contentStream.drawString(text);
> > > > > > >        contentStream.endText();
> > > > > > >
> > > > > > >        // Recompute lastX
> > > > > > >        lastX = nextX;
> > > > > > >    }
> > > > > > >
> > > > > > > }
> > > > > > > ------------------------------------------------------
> > > > > > >
> > > > > > > I would like know if it's the correct mean? If it's OK, I would
> > > like
> > > > > know
> > > > > > > if
> > > > > > > it's possible to retrieve the default Font of the document,
> > because
> > > > in
> > > > > my
> > > > > > > case I have setted the Font?
> > > > > > >
> > > > > > > My code doesn't manage wrap text and I would like know how to
> > > manage
> > > > > > that?
> > > > > > >
> > > > > > > I'm very interested to provides and contribute Hight level API
> > for
> > > > > PDFBox
> > > > > > > (paragraph, table...) but if I have no support I will give up
> my
> > > idea
> > > > > > (hope
> > > > > > > you will understand).
> > > > > > >
> > > > > > > Thank a lot for your help!
> > > > > > >
> > > > > > > Regards Angelo
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > 2011/9/5 Angelo zerr <an...@gmail.com>
> > > > > > >
> > > > > > > > Hi Jeremias,
> > > > > > > >
> > > > > > > > I'm sorry I have not seen your answer
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > > > > > > When I have studied FOP to manage PDF just with Java PDF
> widget
> > I
> > > > > have
> > > > > > > not
> > > > > > > > found documentation so I believed that it was not possible,
> but
> > > it
> > > > > > seems
> > > > > > > > that is possible.
> > > > > > > > That's very cool. I will study that.
> > > > > > > >
> > > > > > > > Many thanks!
> > > > > > > >
> > > > > > > > Regards Angelo
> > > > > > > >
> > > > > > > >
> > > > > > > > 2011/9/5 Jeremias Maerki <de...@jeremias-maerki.ch>
> > > > > > > >
> > > > > > > >> Angelo,
> > > > > > > >> as I explained in [1], you don't have to use XSL-FO when
> using
> > > > > Apache
> > > > > > > >> FOP. It supports alternative means to create PDFs.
> > > > > > > >>
> > > > > > > >> [1]
> > > > > > > >>
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > > > > > >>
> > > > > > > >> But of course, Apache PDFBox would profit a lot from a
> > > > higher-level
> > > > > > PDF
> > > > > > > >> production API. Any contributions are more than welcome.
> > > > > > > >>
> > > > > > > >> On 05.09.2011 10:56:20 Angelo zerr wrote:
> > > > > > > >> > Hi Jukka,
> > > > > > > >> >
> > > > > > > >> > Thank a lot for you answer. I have already implemented a
> > > > docx->PDF
> > > > > > and
> > > > > > > >> > odt->PDF converters with FOP but I decided to give up for
> :
> > > > > > > >> >
> > > > > > > >> > * performance reason. I have used XSLT cache, use xsl:key
> to
> > > > > compute
> > > > > > > the
> > > > > > > >> > odt/docx styles but the FOP implementation is less
> > performant
> > > > than
> > > > > > > iText
> > > > > > > >> > implementation, because :
> > > > > > > >> >   * FOP process : odt -> XSLT -> FO -> FOP
> > > > > > > >> >   * iText process : odt -> ODFDOM (Java) -> iText
> > > > > > > >> > * xslt vs Java model : with the iText process, your model
> is
> > > > Java,
> > > > > > > >> although
> > > > > > > >> > with FOP your model is XML. I prefer develop Java instead
> of
> > > > XSLT.
> > > > > > > >> >
> > > > > > > >> > That's why I'm searching Java PDF API like PDFBox to
> replace
> > > > iText
> > > > > > to
> > > > > > > >> > provides our code to Apache.
> > > > > > > >> >
> > > > > > > >> > Regards Angelo
> > > > > > > >> >
> > > > > > > >> > 2011/9/5 Jukka Zitting <ju...@gmail.com>
> > > > > > > >> >
> > > > > > > >> > > Hi Angelo,
> > > > > > > >> > >
> > > > > > > >> > > On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <
> > > > > > angelo.zerr@gmail.com
> > > > > > > >
> > > > > > > >> > > wrote:
> > > > > > > >> > > > I suppose that my post was not well explained as I
> have
> > no
> > > > > > answer.
> > > > > > > I
> > > > > > > >> will
> > > > > > > >> > > be
> > > > > > > >> > > > very happy to use PDFBox in our XDocReport converter
> > > (docx->
> > > > > PDF
> > > > > > > and
> > > > > > > >> > > odt->
> > > > > > > >> > > > PDF) but develop converter is a big work and I can not
> > > > > > investiaget
> > > > > > > >> time
> > > > > > > >> > > if I
> > > > > > > >> > > > have no support.
> > > > > > > >> > >
> > > > > > > >> > > There's been some interest in making it easier to use
> > PDFBox
> > > > to
> > > > > > > >> > > generate complex new PDF documents, but so far the main
> > use
> > > > > cases
> > > > > > > have
> > > > > > > >> > > been simpler. You might want to look at Apache FOP
> > > > > > > >> > > (http://xmlgraphics.apache.org/fop/) for a higher-level
> > PDF
> > > > > > > >> generation
> > > > > > > >> > > tool.
> > > > > > > >> > >
> > > > > > > >> > > BR,
> > > > > > > >> > >
> > > > > > > >> > > Jukka Zitting
> > > > > > > >> > >
> > > > > > > >>
> > > > > > > >>
> > > > > > > >>
> > > > > > > >>
> > > > > > > >> Jeremias Maerki
> > > > > > > >>
> > > > > > > >>
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > > > DISCLAIMER:
> > > > > This email (including any attachments) is intended for the sole use
> > of
> > > > the
> > > > > intended recipient/s and may contain material that is CONFIDENTIAL
> > AND
> > > > > PRIVATE COMPANY INFORMATION. Any review or reliance by others or
> > > copying
> > > > or
> > > > > distribution or forwarding of any or all of the contents in this
> > > message
> > > > is
> > > > > STRICTLY PROHIBITED. If you are not the intended recipient, please
> > > > contact
> > > > > the sender by email and delete all copies; your cooperation in this
> > > > regard
> > > > > is appreciated.
> > > > >
> > > >
> > >
> >
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Kévin Sailly <ke...@gmail.com>.
It sounds good...



2011/10/14 Angelo zerr <an...@gmail.com>

> Ok I understand. I think we have the same goal :
>
> 1) My goal: docx -> PDF.
> 2) Your goal : XML -> PDF.
>
> My idea is to provide a Java DOM-like PDFBox.(When I say DOM, its not w3c
> DOM). So you can use it just with Java code liek this:
>
>
> -----------------------------------------------------------------------------------------------
> PDFBoxDocument document = new PDFBoxDocument();
> PDFBoxParagraph paragraph = document.addParagraph();
> paragraph.addRun("AAAA");
> paragraph.addRun(" ");
> paragraph.addRun("BBB");
>
> -----------------------------------------------------------------------------------------------
>
> For my case (docx) I will load my docx with POI to have docx Java scrutcure
> and I will loop to thoses structure to createPDFBoxDocument ,
> PDFBoxParagraph instances.
>
> For your case (HTML) you could implement SAX handler like :
>
>
> -----------------------------------------------------------------------------------------------
> public void startElement(String uri, String localName, String name,
> Attributes atts) throws SAXException {
> if ("p".localName) {
> PDFBoxParagraph paragraph = document.addParagraph();
> }
> }
>
> -----------------------------------------------------------------------------------------------
>
> docx and HTML (your sample) manages too styles. So I would like to manage a
> style method like this:
>
>
> -----------------------------------------------------------------------------------------------
> ParagraphStyle style=new ParagraphStyle();
> style.setMargin(10);
> PDFBoxParagraph paragraph = document.addParagraph();
> paragraph.applyStyle(style);
>
> -----------------------------------------------------------------------------------------------
>
> ParagraphStyle could be populated with CSS or declared styles.
>
> What do you think?
>
> Regards Angelo
>
> 2011/10/14 Kévin Sailly <ke...@gmail.com>
>
> > Angelo,
> >
> > My goal is to get some text like:
> > <p>some text</p>
> > <p style="margin-left: 30px;">this one positionned!</p>
> >
> > And then produce the PDF with style applied:
> > some text
> >      this one positionned!
> >
> > Regards,
> > Kéivn
> >
> >
> >
> >
> > 2011/10/14 Angelo zerr <an...@gmail.com>
> >
> > > Hi Srinivaas,
> > >
> > > At first my PDFBox-DOM like can be used without docx (I must manage odt
> > > too). And my idea is to use that for another application.
> > > Your idea to convert docx 2 PDF with FOP, I have already implemented
> but
> > I
> > > don't like that :
> > >
> > > 1) FOP converter is very more slowly than iText converter. The
> > explanation
> > > is simple :
> > > => FOP process :  docx -> XSLT -> XSL-FO -> PDF
> > > => iText process : docx -> (POI to get Java model) -> iText
> > >
> > > As you can notice with FOP process are more steps than IText process.
> FOP
> > > process for docx is less powerfull than iText process and I have a lot
> > > optimized my XSL (XSL Template is in a cahe, I'm using xsl:key, etc).
> > >
> > > 2) with FOP converter you manage the conversion with XSL. With IText
> > > converter you manage teh conversion with Java.
> > > IMHO, I prefer developping Java than XSL. Debug XSL is very hard
> compare
> > > debug Java code.
> > > More docx use  styles.xml where style A can extends style B. With XSL I
> > > compute style every time (how to manage some cache with XSL?) although
> > with
> > > Java I compute one time.
> > >
> > > Our iText converter works great but for license problem we can give our
> > > code
> > > to Apacahe. So I'm investiagting PDFBox.
> > >
> > > Regards Angelo
> > >
> > > 2011/10/14 Srinivaas_Venkatarayan <
> > > Srinivaas_Venkatarayan@mahindrasatyam.com
> > > >
> > >
> > > > Hi Angelo, If the source is going to be docx file, can you not use
> xslt
> > > and
> > > > FOP to convert the xml (provided by docx file) to PDF?
> > > >
> > > > Srinivaas
> > > >
> > > > -----Original Message-----
> > > > From: Angelo zerr [mailto:angelo.zerr@gmail.com]
> > > > Sent: Friday, October 14, 2011 5:07 PM
> > > > To: users@pdfbox.apache.org
> > > > Subject: Re: Replace itext with PDFBox for XDocReport project?
> > > >
> > > > Hi Kevin,
> > > >
> > > > What do you mean with richtext? In my case I would like create a PDF
> > from
> > > > scratch with PDF DOM-like with the same mean than iText.
> > > > I have started to create a project (not commited for the moment
> > > >
> > > > Here my (basic sample) to generate paragraph with several text
> content
> > > > (that
> > > > I have called run like docx)
> > > >
> > > >
> > > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > > PDFBoxDocument document = new PDFBoxDocument();
> > > >
> > > > PDFBoxParagraph paragraph = document.addParagraph();
> > > > paragraph.addRun("AAAA");
> > > > paragraph.addRun(" ");
> > > > paragraph.addRun("BBB");
> > > >
> > > > document.save("test.pdf");
> > > >
> > > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > >
> > > > This code generate a PDF with :
> > > >
> > > >
> > > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > > AAAA BBB
> > > >
> > > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > >
> > > > If you are interested (working together?) I could commit my work on
> our
> > > > XDocReport git.
> > > >
> > > > Regards Angelo
> > > >
> > > > 2011/10/14 Kévin Sailly <ke...@gmail.com>
> > > >
> > > > > Hello,
> > > > >
> > > > > I am planning to build some code to create text from richtext (text
> > > from
> > > > > rech text editor), is that what you are planning to do?
> > > > >
> > > > > Regards,
> > > > > Kévin
> > > > >
> > > > >
> > > > >
> > > > > 2011/10/13 Angelo zerr <an...@gmail.com>
> > > > >
> > > > > > Hi PDFBox Team,
> > > > > >
> > > > > > I have started to investigate time with PDFBox to try to provides
> > > > > > High-Level
> > > > > > API to manage paragraph, table widgets etc....
> > > > > > I recall my problem : we are using iText for our ODT->PDF and
> > > Docx->PDF
> > > > > > converter and we wish provides our code for Apache. Problem is
> > iText
> > > > > > license.
> > > > > > So I'm searching PDF API (PDFBox?FOP?) to manage PDF with Java
> > model
> > > > (not
> > > > > > with XSL-FO). It seems that FOP provides this feature, but it's
> > very
> > > > hard
> > > > > > to
> > > > > > understand how to manage that?
> > > > > >
> > > > > > I have tried to manage a simple case : a paragraph with some
> text.
> > I
> > > > > would
> > > > > > like generate PDF with this content:
> > > > > >
> > > > > > ----------------------------
> > > > > > AAAA BBBB
> > > > > > ----------------------------
> > > > > >
> > > > > > But not with one String but with 3 Strings (call 3 times
> > > > > > contentStream.drawString(...);)
> > > > > > The solution that I have found to manage that is to store the
> last
> > X
> > > of
> > > > > the
> > > > > > added Stringby using Stringlenght+Font + Font size. Here my code
> > > > > >
> > > > > > ------------------------------------------------------
> > > > > > import java.io.IOException;
> > > > > >
> > > > > > import org.apache.pdfbox.exceptions.COSVisitorException;
> > > > > > import org.apache.pdfbox.pdmodel.PDDocument;
> > > > > > import org.apache.pdfbox.pdmodel.PDPage;
> > > > > > import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
> > > > > > import org.apache.pdfbox.pdmodel.font.PDFont;
> > > > > > import org.apache.pdfbox.pdmodel.font.PDType1Font;
> > > > > >
> > > > > > public class Test3 {
> > > > > >
> > > > > >    private static float lastX = 0;
> > > > > >
> > > > > >    public static void main(String[] args) throws IOException,
> > > > > >            COSVisitorException {
> > > > > >        PDDocument doc = null;
> > > > > >        try {
> > > > > >            doc = new PDDocument();
> > > > > >
> > > > > >            PDPage page = new PDPage();
> > > > > >            doc.addPage(page);
> > > > > >
> > > > > >            PDPageContentStream contentStream = new
> > > > > PDPageContentStream(doc,
> > > > > >                    page);
> > > > > >
> > > > > >            PDFont font = PDType1Font.HELVETICA_BOLD;
> > > > > >            long fontSize = 5;
> > > > > >            addText("AAAA", font, fontSize, page, contentStream);
> > > > > >            addText(" ", font, fontSize, page, contentStream);
> > > > > >            addText("BBBB", font, fontSize, page, contentStream);
> > > > > >
> > > > > >            contentStream.close();
> > > > > >
> > > > > >            doc.save("test.pdf");
> > > > > >
> > > > > >        } finally {
> > > > > >            if (doc != null) {
> > > > > >                doc.close();
> > > > > >            }
> > > > > >        }
> > > > > >    }
> > > > > >
> > > > > >    public static void addText(String text, PDFont font, long
> > > fontSize,
> > > > > >            PDPage page, PDPageContentStream contentStream) throws
> > > > > > IOException {
> > > > > >
> > > > > >        // Compute x
> > > > > >        float x = lastX;
> > > > > >        float nextX = lastX + font.getStringWidth(text) * fontSize
> /
> > > > > 1000f;
> > > > > >
> > > > > >        // Compute Y
> > > > > >        float y = page.getMediaBox().getHeight()
> > > > > >                - (font.getFontHeight("A".getBytes(), 0, 1) *
> > fontSize
> > > /
> > > > > > 1000f);
> > > > > >
> > > > > >        contentStream.beginText();
> > > > > >        contentStream.setFont(font, fontSize);
> > > > > >        contentStream.moveTextPositionByAmount(x, y);
> > > > > >        contentStream.drawString(text);
> > > > > >        contentStream.endText();
> > > > > >
> > > > > >        // Recompute lastX
> > > > > >        lastX = nextX;
> > > > > >    }
> > > > > >
> > > > > > }
> > > > > > ------------------------------------------------------
> > > > > >
> > > > > > I would like know if it's the correct mean? If it's OK, I would
> > like
> > > > know
> > > > > > if
> > > > > > it's possible to retrieve the default Font of the document,
> because
> > > in
> > > > my
> > > > > > case I have setted the Font?
> > > > > >
> > > > > > My code doesn't manage wrap text and I would like know how to
> > manage
> > > > > that?
> > > > > >
> > > > > > I'm very interested to provides and contribute Hight level API
> for
> > > > PDFBox
> > > > > > (paragraph, table...) but if I have no support I will give up my
> > idea
> > > > > (hope
> > > > > > you will understand).
> > > > > >
> > > > > > Thank a lot for your help!
> > > > > >
> > > > > > Regards Angelo
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > 2011/9/5 Angelo zerr <an...@gmail.com>
> > > > > >
> > > > > > > Hi Jeremias,
> > > > > > >
> > > > > > > I'm sorry I have not seen your answer
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > > > > > When I have studied FOP to manage PDF just with Java PDF widget
> I
> > > > have
> > > > > > not
> > > > > > > found documentation so I believed that it was not possible, but
> > it
> > > > > seems
> > > > > > > that is possible.
> > > > > > > That's very cool. I will study that.
> > > > > > >
> > > > > > > Many thanks!
> > > > > > >
> > > > > > > Regards Angelo
> > > > > > >
> > > > > > >
> > > > > > > 2011/9/5 Jeremias Maerki <de...@jeremias-maerki.ch>
> > > > > > >
> > > > > > >> Angelo,
> > > > > > >> as I explained in [1], you don't have to use XSL-FO when using
> > > > Apache
> > > > > > >> FOP. It supports alternative means to create PDFs.
> > > > > > >>
> > > > > > >> [1]
> > > > > > >>
> > > > > >
> > > > >
> > > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > > > > >>
> > > > > > >> But of course, Apache PDFBox would profit a lot from a
> > > higher-level
> > > > > PDF
> > > > > > >> production API. Any contributions are more than welcome.
> > > > > > >>
> > > > > > >> On 05.09.2011 10:56:20 Angelo zerr wrote:
> > > > > > >> > Hi Jukka,
> > > > > > >> >
> > > > > > >> > Thank a lot for you answer. I have already implemented a
> > > docx->PDF
> > > > > and
> > > > > > >> > odt->PDF converters with FOP but I decided to give up for :
> > > > > > >> >
> > > > > > >> > * performance reason. I have used XSLT cache, use xsl:key to
> > > > compute
> > > > > > the
> > > > > > >> > odt/docx styles but the FOP implementation is less
> performant
> > > than
> > > > > > iText
> > > > > > >> > implementation, because :
> > > > > > >> >   * FOP process : odt -> XSLT -> FO -> FOP
> > > > > > >> >   * iText process : odt -> ODFDOM (Java) -> iText
> > > > > > >> > * xslt vs Java model : with the iText process, your model is
> > > Java,
> > > > > > >> although
> > > > > > >> > with FOP your model is XML. I prefer develop Java instead of
> > > XSLT.
> > > > > > >> >
> > > > > > >> > That's why I'm searching Java PDF API like PDFBox to replace
> > > iText
> > > > > to
> > > > > > >> > provides our code to Apache.
> > > > > > >> >
> > > > > > >> > Regards Angelo
> > > > > > >> >
> > > > > > >> > 2011/9/5 Jukka Zitting <ju...@gmail.com>
> > > > > > >> >
> > > > > > >> > > Hi Angelo,
> > > > > > >> > >
> > > > > > >> > > On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <
> > > > > angelo.zerr@gmail.com
> > > > > > >
> > > > > > >> > > wrote:
> > > > > > >> > > > I suppose that my post was not well explained as I have
> no
> > > > > answer.
> > > > > > I
> > > > > > >> will
> > > > > > >> > > be
> > > > > > >> > > > very happy to use PDFBox in our XDocReport converter
> > (docx->
> > > > PDF
> > > > > > and
> > > > > > >> > > odt->
> > > > > > >> > > > PDF) but develop converter is a big work and I can not
> > > > > investiaget
> > > > > > >> time
> > > > > > >> > > if I
> > > > > > >> > > > have no support.
> > > > > > >> > >
> > > > > > >> > > There's been some interest in making it easier to use
> PDFBox
> > > to
> > > > > > >> > > generate complex new PDF documents, but so far the main
> use
> > > > cases
> > > > > > have
> > > > > > >> > > been simpler. You might want to look at Apache FOP
> > > > > > >> > > (http://xmlgraphics.apache.org/fop/) for a higher-level
> PDF
> > > > > > >> generation
> > > > > > >> > > tool.
> > > > > > >> > >
> > > > > > >> > > BR,
> > > > > > >> > >
> > > > > > >> > > Jukka Zitting
> > > > > > >> > >
> > > > > > >>
> > > > > > >>
> > > > > > >>
> > > > > > >>
> > > > > > >> Jeremias Maerki
> > > > > > >>
> > > > > > >>
> > > > > > >
> > > > > >
> > > > >
> > > >
> > > > DISCLAIMER:
> > > > This email (including any attachments) is intended for the sole use
> of
> > > the
> > > > intended recipient/s and may contain material that is CONFIDENTIAL
> AND
> > > > PRIVATE COMPANY INFORMATION. Any review or reliance by others or
> > copying
> > > or
> > > > distribution or forwarding of any or all of the contents in this
> > message
> > > is
> > > > STRICTLY PROHIBITED. If you are not the intended recipient, please
> > > contact
> > > > the sender by email and delete all copies; your cooperation in this
> > > regard
> > > > is appreciated.
> > > >
> > >
> >
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Angelo zerr <an...@gmail.com>.
Ok I understand. I think we have the same goal :

1) My goal: docx -> PDF.
2) Your goal : XML -> PDF.

My idea is to provide a Java DOM-like PDFBox.(When I say DOM, its not w3c
DOM). So you can use it just with Java code liek this:

-----------------------------------------------------------------------------------------------
PDFBoxDocument document = new PDFBoxDocument();
PDFBoxParagraph paragraph = document.addParagraph();
paragraph.addRun("AAAA");
paragraph.addRun(" ");
paragraph.addRun("BBB");
-----------------------------------------------------------------------------------------------

For my case (docx) I will load my docx with POI to have docx Java scrutcure
and I will loop to thoses structure to createPDFBoxDocument ,
PDFBoxParagraph instances.

For your case (HTML) you could implement SAX handler like :

-----------------------------------------------------------------------------------------------
public void startElement(String uri, String localName, String name,
Attributes atts) throws SAXException {
if ("p".localName) {
PDFBoxParagraph paragraph = document.addParagraph();
}
}
-----------------------------------------------------------------------------------------------

docx and HTML (your sample) manages too styles. So I would like to manage a
style method like this:

-----------------------------------------------------------------------------------------------
ParagraphStyle style=new ParagraphStyle();
style.setMargin(10);
PDFBoxParagraph paragraph = document.addParagraph();
paragraph.applyStyle(style);
-----------------------------------------------------------------------------------------------

ParagraphStyle could be populated with CSS or declared styles.

What do you think?

Regards Angelo

2011/10/14 Kévin Sailly <ke...@gmail.com>

> Angelo,
>
> My goal is to get some text like:
> <p>some text</p>
> <p style="margin-left: 30px;">this one positionned!</p>
>
> And then produce the PDF with style applied:
> some text
>      this one positionned!
>
> Regards,
> Kéivn
>
>
>
>
> 2011/10/14 Angelo zerr <an...@gmail.com>
>
> > Hi Srinivaas,
> >
> > At first my PDFBox-DOM like can be used without docx (I must manage odt
> > too). And my idea is to use that for another application.
> > Your idea to convert docx 2 PDF with FOP, I have already implemented but
> I
> > don't like that :
> >
> > 1) FOP converter is very more slowly than iText converter. The
> explanation
> > is simple :
> > => FOP process :  docx -> XSLT -> XSL-FO -> PDF
> > => iText process : docx -> (POI to get Java model) -> iText
> >
> > As you can notice with FOP process are more steps than IText process. FOP
> > process for docx is less powerfull than iText process and I have a lot
> > optimized my XSL (XSL Template is in a cahe, I'm using xsl:key, etc).
> >
> > 2) with FOP converter you manage the conversion with XSL. With IText
> > converter you manage teh conversion with Java.
> > IMHO, I prefer developping Java than XSL. Debug XSL is very hard compare
> > debug Java code.
> > More docx use  styles.xml where style A can extends style B. With XSL I
> > compute style every time (how to manage some cache with XSL?) although
> with
> > Java I compute one time.
> >
> > Our iText converter works great but for license problem we can give our
> > code
> > to Apacahe. So I'm investiagting PDFBox.
> >
> > Regards Angelo
> >
> > 2011/10/14 Srinivaas_Venkatarayan <
> > Srinivaas_Venkatarayan@mahindrasatyam.com
> > >
> >
> > > Hi Angelo, If the source is going to be docx file, can you not use xslt
> > and
> > > FOP to convert the xml (provided by docx file) to PDF?
> > >
> > > Srinivaas
> > >
> > > -----Original Message-----
> > > From: Angelo zerr [mailto:angelo.zerr@gmail.com]
> > > Sent: Friday, October 14, 2011 5:07 PM
> > > To: users@pdfbox.apache.org
> > > Subject: Re: Replace itext with PDFBox for XDocReport project?
> > >
> > > Hi Kevin,
> > >
> > > What do you mean with richtext? In my case I would like create a PDF
> from
> > > scratch with PDF DOM-like with the same mean than iText.
> > > I have started to create a project (not commited for the moment
> > >
> > > Here my (basic sample) to generate paragraph with several text content
> > > (that
> > > I have called run like docx)
> > >
> > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > PDFBoxDocument document = new PDFBoxDocument();
> > >
> > > PDFBoxParagraph paragraph = document.addParagraph();
> > > paragraph.addRun("AAAA");
> > > paragraph.addRun(" ");
> > > paragraph.addRun("BBB");
> > >
> > > document.save("test.pdf");
> > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > >
> > > This code generate a PDF with :
> > >
> > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > > AAAA BBB
> > >
> > >
> >
> ------------------------------------------------------------------------------------------------
> > >
> > > If you are interested (working together?) I could commit my work on our
> > > XDocReport git.
> > >
> > > Regards Angelo
> > >
> > > 2011/10/14 Kévin Sailly <ke...@gmail.com>
> > >
> > > > Hello,
> > > >
> > > > I am planning to build some code to create text from richtext (text
> > from
> > > > rech text editor), is that what you are planning to do?
> > > >
> > > > Regards,
> > > > Kévin
> > > >
> > > >
> > > >
> > > > 2011/10/13 Angelo zerr <an...@gmail.com>
> > > >
> > > > > Hi PDFBox Team,
> > > > >
> > > > > I have started to investigate time with PDFBox to try to provides
> > > > > High-Level
> > > > > API to manage paragraph, table widgets etc....
> > > > > I recall my problem : we are using iText for our ODT->PDF and
> > Docx->PDF
> > > > > converter and we wish provides our code for Apache. Problem is
> iText
> > > > > license.
> > > > > So I'm searching PDF API (PDFBox?FOP?) to manage PDF with Java
> model
> > > (not
> > > > > with XSL-FO). It seems that FOP provides this feature, but it's
> very
> > > hard
> > > > > to
> > > > > understand how to manage that?
> > > > >
> > > > > I have tried to manage a simple case : a paragraph with some text.
> I
> > > > would
> > > > > like generate PDF with this content:
> > > > >
> > > > > ----------------------------
> > > > > AAAA BBBB
> > > > > ----------------------------
> > > > >
> > > > > But not with one String but with 3 Strings (call 3 times
> > > > > contentStream.drawString(...);)
> > > > > The solution that I have found to manage that is to store the last
> X
> > of
> > > > the
> > > > > added Stringby using Stringlenght+Font + Font size. Here my code
> > > > >
> > > > > ------------------------------------------------------
> > > > > import java.io.IOException;
> > > > >
> > > > > import org.apache.pdfbox.exceptions.COSVisitorException;
> > > > > import org.apache.pdfbox.pdmodel.PDDocument;
> > > > > import org.apache.pdfbox.pdmodel.PDPage;
> > > > > import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
> > > > > import org.apache.pdfbox.pdmodel.font.PDFont;
> > > > > import org.apache.pdfbox.pdmodel.font.PDType1Font;
> > > > >
> > > > > public class Test3 {
> > > > >
> > > > >    private static float lastX = 0;
> > > > >
> > > > >    public static void main(String[] args) throws IOException,
> > > > >            COSVisitorException {
> > > > >        PDDocument doc = null;
> > > > >        try {
> > > > >            doc = new PDDocument();
> > > > >
> > > > >            PDPage page = new PDPage();
> > > > >            doc.addPage(page);
> > > > >
> > > > >            PDPageContentStream contentStream = new
> > > > PDPageContentStream(doc,
> > > > >                    page);
> > > > >
> > > > >            PDFont font = PDType1Font.HELVETICA_BOLD;
> > > > >            long fontSize = 5;
> > > > >            addText("AAAA", font, fontSize, page, contentStream);
> > > > >            addText(" ", font, fontSize, page, contentStream);
> > > > >            addText("BBBB", font, fontSize, page, contentStream);
> > > > >
> > > > >            contentStream.close();
> > > > >
> > > > >            doc.save("test.pdf");
> > > > >
> > > > >        } finally {
> > > > >            if (doc != null) {
> > > > >                doc.close();
> > > > >            }
> > > > >        }
> > > > >    }
> > > > >
> > > > >    public static void addText(String text, PDFont font, long
> > fontSize,
> > > > >            PDPage page, PDPageContentStream contentStream) throws
> > > > > IOException {
> > > > >
> > > > >        // Compute x
> > > > >        float x = lastX;
> > > > >        float nextX = lastX + font.getStringWidth(text) * fontSize /
> > > > 1000f;
> > > > >
> > > > >        // Compute Y
> > > > >        float y = page.getMediaBox().getHeight()
> > > > >                - (font.getFontHeight("A".getBytes(), 0, 1) *
> fontSize
> > /
> > > > > 1000f);
> > > > >
> > > > >        contentStream.beginText();
> > > > >        contentStream.setFont(font, fontSize);
> > > > >        contentStream.moveTextPositionByAmount(x, y);
> > > > >        contentStream.drawString(text);
> > > > >        contentStream.endText();
> > > > >
> > > > >        // Recompute lastX
> > > > >        lastX = nextX;
> > > > >    }
> > > > >
> > > > > }
> > > > > ------------------------------------------------------
> > > > >
> > > > > I would like know if it's the correct mean? If it's OK, I would
> like
> > > know
> > > > > if
> > > > > it's possible to retrieve the default Font of the document, because
> > in
> > > my
> > > > > case I have setted the Font?
> > > > >
> > > > > My code doesn't manage wrap text and I would like know how to
> manage
> > > > that?
> > > > >
> > > > > I'm very interested to provides and contribute Hight level API for
> > > PDFBox
> > > > > (paragraph, table...) but if I have no support I will give up my
> idea
> > > > (hope
> > > > > you will understand).
> > > > >
> > > > > Thank a lot for your help!
> > > > >
> > > > > Regards Angelo
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > 2011/9/5 Angelo zerr <an...@gmail.com>
> > > > >
> > > > > > Hi Jeremias,
> > > > > >
> > > > > > I'm sorry I have not seen your answer
> > > > > >
> > > > >
> > > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > > > > When I have studied FOP to manage PDF just with Java PDF widget I
> > > have
> > > > > not
> > > > > > found documentation so I believed that it was not possible, but
> it
> > > > seems
> > > > > > that is possible.
> > > > > > That's very cool. I will study that.
> > > > > >
> > > > > > Many thanks!
> > > > > >
> > > > > > Regards Angelo
> > > > > >
> > > > > >
> > > > > > 2011/9/5 Jeremias Maerki <de...@jeremias-maerki.ch>
> > > > > >
> > > > > >> Angelo,
> > > > > >> as I explained in [1], you don't have to use XSL-FO when using
> > > Apache
> > > > > >> FOP. It supports alternative means to create PDFs.
> > > > > >>
> > > > > >> [1]
> > > > > >>
> > > > >
> > > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > > > >>
> > > > > >> But of course, Apache PDFBox would profit a lot from a
> > higher-level
> > > > PDF
> > > > > >> production API. Any contributions are more than welcome.
> > > > > >>
> > > > > >> On 05.09.2011 10:56:20 Angelo zerr wrote:
> > > > > >> > Hi Jukka,
> > > > > >> >
> > > > > >> > Thank a lot for you answer. I have already implemented a
> > docx->PDF
> > > > and
> > > > > >> > odt->PDF converters with FOP but I decided to give up for :
> > > > > >> >
> > > > > >> > * performance reason. I have used XSLT cache, use xsl:key to
> > > compute
> > > > > the
> > > > > >> > odt/docx styles but the FOP implementation is less performant
> > than
> > > > > iText
> > > > > >> > implementation, because :
> > > > > >> >   * FOP process : odt -> XSLT -> FO -> FOP
> > > > > >> >   * iText process : odt -> ODFDOM (Java) -> iText
> > > > > >> > * xslt vs Java model : with the iText process, your model is
> > Java,
> > > > > >> although
> > > > > >> > with FOP your model is XML. I prefer develop Java instead of
> > XSLT.
> > > > > >> >
> > > > > >> > That's why I'm searching Java PDF API like PDFBox to replace
> > iText
> > > > to
> > > > > >> > provides our code to Apache.
> > > > > >> >
> > > > > >> > Regards Angelo
> > > > > >> >
> > > > > >> > 2011/9/5 Jukka Zitting <ju...@gmail.com>
> > > > > >> >
> > > > > >> > > Hi Angelo,
> > > > > >> > >
> > > > > >> > > On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <
> > > > angelo.zerr@gmail.com
> > > > > >
> > > > > >> > > wrote:
> > > > > >> > > > I suppose that my post was not well explained as I have no
> > > > answer.
> > > > > I
> > > > > >> will
> > > > > >> > > be
> > > > > >> > > > very happy to use PDFBox in our XDocReport converter
> (docx->
> > > PDF
> > > > > and
> > > > > >> > > odt->
> > > > > >> > > > PDF) but develop converter is a big work and I can not
> > > > investiaget
> > > > > >> time
> > > > > >> > > if I
> > > > > >> > > > have no support.
> > > > > >> > >
> > > > > >> > > There's been some interest in making it easier to use PDFBox
> > to
> > > > > >> > > generate complex new PDF documents, but so far the main use
> > > cases
> > > > > have
> > > > > >> > > been simpler. You might want to look at Apache FOP
> > > > > >> > > (http://xmlgraphics.apache.org/fop/) for a higher-level PDF
> > > > > >> generation
> > > > > >> > > tool.
> > > > > >> > >
> > > > > >> > > BR,
> > > > > >> > >
> > > > > >> > > Jukka Zitting
> > > > > >> > >
> > > > > >>
> > > > > >>
> > > > > >>
> > > > > >>
> > > > > >> Jeremias Maerki
> > > > > >>
> > > > > >>
> > > > > >
> > > > >
> > > >
> > >
> > > DISCLAIMER:
> > > This email (including any attachments) is intended for the sole use of
> > the
> > > intended recipient/s and may contain material that is CONFIDENTIAL AND
> > > PRIVATE COMPANY INFORMATION. Any review or reliance by others or
> copying
> > or
> > > distribution or forwarding of any or all of the contents in this
> message
> > is
> > > STRICTLY PROHIBITED. If you are not the intended recipient, please
> > contact
> > > the sender by email and delete all copies; your cooperation in this
> > regard
> > > is appreciated.
> > >
> >
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Kévin Sailly <ke...@gmail.com>.
Angelo,

My goal is to get some text like:
<p>some text</p>
<p style="margin-left: 30px;">this one positionned!</p>

And then produce the PDF with style applied:
some text
      this one positionned!

Regards,
Kéivn




2011/10/14 Angelo zerr <an...@gmail.com>

> Hi Srinivaas,
>
> At first my PDFBox-DOM like can be used without docx (I must manage odt
> too). And my idea is to use that for another application.
> Your idea to convert docx 2 PDF with FOP, I have already implemented but I
> don't like that :
>
> 1) FOP converter is very more slowly than iText converter. The explanation
> is simple :
> => FOP process :  docx -> XSLT -> XSL-FO -> PDF
> => iText process : docx -> (POI to get Java model) -> iText
>
> As you can notice with FOP process are more steps than IText process. FOP
> process for docx is less powerfull than iText process and I have a lot
> optimized my XSL (XSL Template is in a cahe, I'm using xsl:key, etc).
>
> 2) with FOP converter you manage the conversion with XSL. With IText
> converter you manage teh conversion with Java.
> IMHO, I prefer developping Java than XSL. Debug XSL is very hard compare
> debug Java code.
> More docx use  styles.xml where style A can extends style B. With XSL I
> compute style every time (how to manage some cache with XSL?) although with
> Java I compute one time.
>
> Our iText converter works great but for license problem we can give our
> code
> to Apacahe. So I'm investiagting PDFBox.
>
> Regards Angelo
>
> 2011/10/14 Srinivaas_Venkatarayan <
> Srinivaas_Venkatarayan@mahindrasatyam.com
> >
>
> > Hi Angelo, If the source is going to be docx file, can you not use xslt
> and
> > FOP to convert the xml (provided by docx file) to PDF?
> >
> > Srinivaas
> >
> > -----Original Message-----
> > From: Angelo zerr [mailto:angelo.zerr@gmail.com]
> > Sent: Friday, October 14, 2011 5:07 PM
> > To: users@pdfbox.apache.org
> > Subject: Re: Replace itext with PDFBox for XDocReport project?
> >
> > Hi Kevin,
> >
> > What do you mean with richtext? In my case I would like create a PDF from
> > scratch with PDF DOM-like with the same mean than iText.
> > I have started to create a project (not commited for the moment
> >
> > Here my (basic sample) to generate paragraph with several text content
> > (that
> > I have called run like docx)
> >
> >
> >
> ------------------------------------------------------------------------------------------------
> > PDFBoxDocument document = new PDFBoxDocument();
> >
> > PDFBoxParagraph paragraph = document.addParagraph();
> > paragraph.addRun("AAAA");
> > paragraph.addRun(" ");
> > paragraph.addRun("BBB");
> >
> > document.save("test.pdf");
> >
> >
> ------------------------------------------------------------------------------------------------
> >
> > This code generate a PDF with :
> >
> >
> >
> ------------------------------------------------------------------------------------------------
> > AAAA BBB
> >
> >
> ------------------------------------------------------------------------------------------------
> >
> > If you are interested (working together?) I could commit my work on our
> > XDocReport git.
> >
> > Regards Angelo
> >
> > 2011/10/14 Kévin Sailly <ke...@gmail.com>
> >
> > > Hello,
> > >
> > > I am planning to build some code to create text from richtext (text
> from
> > > rech text editor), is that what you are planning to do?
> > >
> > > Regards,
> > > Kévin
> > >
> > >
> > >
> > > 2011/10/13 Angelo zerr <an...@gmail.com>
> > >
> > > > Hi PDFBox Team,
> > > >
> > > > I have started to investigate time with PDFBox to try to provides
> > > > High-Level
> > > > API to manage paragraph, table widgets etc....
> > > > I recall my problem : we are using iText for our ODT->PDF and
> Docx->PDF
> > > > converter and we wish provides our code for Apache. Problem is iText
> > > > license.
> > > > So I'm searching PDF API (PDFBox?FOP?) to manage PDF with Java model
> > (not
> > > > with XSL-FO). It seems that FOP provides this feature, but it's very
> > hard
> > > > to
> > > > understand how to manage that?
> > > >
> > > > I have tried to manage a simple case : a paragraph with some text. I
> > > would
> > > > like generate PDF with this content:
> > > >
> > > > ----------------------------
> > > > AAAA BBBB
> > > > ----------------------------
> > > >
> > > > But not with one String but with 3 Strings (call 3 times
> > > > contentStream.drawString(...);)
> > > > The solution that I have found to manage that is to store the last X
> of
> > > the
> > > > added Stringby using Stringlenght+Font + Font size. Here my code
> > > >
> > > > ------------------------------------------------------
> > > > import java.io.IOException;
> > > >
> > > > import org.apache.pdfbox.exceptions.COSVisitorException;
> > > > import org.apache.pdfbox.pdmodel.PDDocument;
> > > > import org.apache.pdfbox.pdmodel.PDPage;
> > > > import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
> > > > import org.apache.pdfbox.pdmodel.font.PDFont;
> > > > import org.apache.pdfbox.pdmodel.font.PDType1Font;
> > > >
> > > > public class Test3 {
> > > >
> > > >    private static float lastX = 0;
> > > >
> > > >    public static void main(String[] args) throws IOException,
> > > >            COSVisitorException {
> > > >        PDDocument doc = null;
> > > >        try {
> > > >            doc = new PDDocument();
> > > >
> > > >            PDPage page = new PDPage();
> > > >            doc.addPage(page);
> > > >
> > > >            PDPageContentStream contentStream = new
> > > PDPageContentStream(doc,
> > > >                    page);
> > > >
> > > >            PDFont font = PDType1Font.HELVETICA_BOLD;
> > > >            long fontSize = 5;
> > > >            addText("AAAA", font, fontSize, page, contentStream);
> > > >            addText(" ", font, fontSize, page, contentStream);
> > > >            addText("BBBB", font, fontSize, page, contentStream);
> > > >
> > > >            contentStream.close();
> > > >
> > > >            doc.save("test.pdf");
> > > >
> > > >        } finally {
> > > >            if (doc != null) {
> > > >                doc.close();
> > > >            }
> > > >        }
> > > >    }
> > > >
> > > >    public static void addText(String text, PDFont font, long
> fontSize,
> > > >            PDPage page, PDPageContentStream contentStream) throws
> > > > IOException {
> > > >
> > > >        // Compute x
> > > >        float x = lastX;
> > > >        float nextX = lastX + font.getStringWidth(text) * fontSize /
> > > 1000f;
> > > >
> > > >        // Compute Y
> > > >        float y = page.getMediaBox().getHeight()
> > > >                - (font.getFontHeight("A".getBytes(), 0, 1) * fontSize
> /
> > > > 1000f);
> > > >
> > > >        contentStream.beginText();
> > > >        contentStream.setFont(font, fontSize);
> > > >        contentStream.moveTextPositionByAmount(x, y);
> > > >        contentStream.drawString(text);
> > > >        contentStream.endText();
> > > >
> > > >        // Recompute lastX
> > > >        lastX = nextX;
> > > >    }
> > > >
> > > > }
> > > > ------------------------------------------------------
> > > >
> > > > I would like know if it's the correct mean? If it's OK, I would like
> > know
> > > > if
> > > > it's possible to retrieve the default Font of the document, because
> in
> > my
> > > > case I have setted the Font?
> > > >
> > > > My code doesn't manage wrap text and I would like know how to manage
> > > that?
> > > >
> > > > I'm very interested to provides and contribute Hight level API for
> > PDFBox
> > > > (paragraph, table...) but if I have no support I will give up my idea
> > > (hope
> > > > you will understand).
> > > >
> > > > Thank a lot for your help!
> > > >
> > > > Regards Angelo
> > > >
> > > >
> > > >
> > > >
> > > > 2011/9/5 Angelo zerr <an...@gmail.com>
> > > >
> > > > > Hi Jeremias,
> > > > >
> > > > > I'm sorry I have not seen your answer
> > > > >
> > > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > > > When I have studied FOP to manage PDF just with Java PDF widget I
> > have
> > > > not
> > > > > found documentation so I believed that it was not possible, but it
> > > seems
> > > > > that is possible.
> > > > > That's very cool. I will study that.
> > > > >
> > > > > Many thanks!
> > > > >
> > > > > Regards Angelo
> > > > >
> > > > >
> > > > > 2011/9/5 Jeremias Maerki <de...@jeremias-maerki.ch>
> > > > >
> > > > >> Angelo,
> > > > >> as I explained in [1], you don't have to use XSL-FO when using
> > Apache
> > > > >> FOP. It supports alternative means to create PDFs.
> > > > >>
> > > > >> [1]
> > > > >>
> > > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > > >>
> > > > >> But of course, Apache PDFBox would profit a lot from a
> higher-level
> > > PDF
> > > > >> production API. Any contributions are more than welcome.
> > > > >>
> > > > >> On 05.09.2011 10:56:20 Angelo zerr wrote:
> > > > >> > Hi Jukka,
> > > > >> >
> > > > >> > Thank a lot for you answer. I have already implemented a
> docx->PDF
> > > and
> > > > >> > odt->PDF converters with FOP but I decided to give up for :
> > > > >> >
> > > > >> > * performance reason. I have used XSLT cache, use xsl:key to
> > compute
> > > > the
> > > > >> > odt/docx styles but the FOP implementation is less performant
> than
> > > > iText
> > > > >> > implementation, because :
> > > > >> >   * FOP process : odt -> XSLT -> FO -> FOP
> > > > >> >   * iText process : odt -> ODFDOM (Java) -> iText
> > > > >> > * xslt vs Java model : with the iText process, your model is
> Java,
> > > > >> although
> > > > >> > with FOP your model is XML. I prefer develop Java instead of
> XSLT.
> > > > >> >
> > > > >> > That's why I'm searching Java PDF API like PDFBox to replace
> iText
> > > to
> > > > >> > provides our code to Apache.
> > > > >> >
> > > > >> > Regards Angelo
> > > > >> >
> > > > >> > 2011/9/5 Jukka Zitting <ju...@gmail.com>
> > > > >> >
> > > > >> > > Hi Angelo,
> > > > >> > >
> > > > >> > > On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <
> > > angelo.zerr@gmail.com
> > > > >
> > > > >> > > wrote:
> > > > >> > > > I suppose that my post was not well explained as I have no
> > > answer.
> > > > I
> > > > >> will
> > > > >> > > be
> > > > >> > > > very happy to use PDFBox in our XDocReport converter (docx->
> > PDF
> > > > and
> > > > >> > > odt->
> > > > >> > > > PDF) but develop converter is a big work and I can not
> > > investiaget
> > > > >> time
> > > > >> > > if I
> > > > >> > > > have no support.
> > > > >> > >
> > > > >> > > There's been some interest in making it easier to use PDFBox
> to
> > > > >> > > generate complex new PDF documents, but so far the main use
> > cases
> > > > have
> > > > >> > > been simpler. You might want to look at Apache FOP
> > > > >> > > (http://xmlgraphics.apache.org/fop/) for a higher-level PDF
> > > > >> generation
> > > > >> > > tool.
> > > > >> > >
> > > > >> > > BR,
> > > > >> > >
> > > > >> > > Jukka Zitting
> > > > >> > >
> > > > >>
> > > > >>
> > > > >>
> > > > >>
> > > > >> Jeremias Maerki
> > > > >>
> > > > >>
> > > > >
> > > >
> > >
> >
> > DISCLAIMER:
> > This email (including any attachments) is intended for the sole use of
> the
> > intended recipient/s and may contain material that is CONFIDENTIAL AND
> > PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying
> or
> > distribution or forwarding of any or all of the contents in this message
> is
> > STRICTLY PROHIBITED. If you are not the intended recipient, please
> contact
> > the sender by email and delete all copies; your cooperation in this
> regard
> > is appreciated.
> >
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Angelo zerr <an...@gmail.com>.
Hi Srinivaas,

At first my PDFBox-DOM like can be used without docx (I must manage odt
too). And my idea is to use that for another application.
Your idea to convert docx 2 PDF with FOP, I have already implemented but I
don't like that :

1) FOP converter is very more slowly than iText converter. The explanation
is simple :
=> FOP process :  docx -> XSLT -> XSL-FO -> PDF
=> iText process : docx -> (POI to get Java model) -> iText

As you can notice with FOP process are more steps than IText process. FOP
process for docx is less powerfull than iText process and I have a lot
optimized my XSL (XSL Template is in a cahe, I'm using xsl:key, etc).

2) with FOP converter you manage the conversion with XSL. With IText
converter you manage teh conversion with Java.
IMHO, I prefer developping Java than XSL. Debug XSL is very hard compare
debug Java code.
More docx use  styles.xml where style A can extends style B. With XSL I
compute style every time (how to manage some cache with XSL?) although with
Java I compute one time.

Our iText converter works great but for license problem we can give our code
to Apacahe. So I'm investiagting PDFBox.

Regards Angelo

2011/10/14 Srinivaas_Venkatarayan <Srinivaas_Venkatarayan@mahindrasatyam.com
>

> Hi Angelo, If the source is going to be docx file, can you not use xslt and
> FOP to convert the xml (provided by docx file) to PDF?
>
> Srinivaas
>
> -----Original Message-----
> From: Angelo zerr [mailto:angelo.zerr@gmail.com]
> Sent: Friday, October 14, 2011 5:07 PM
> To: users@pdfbox.apache.org
> Subject: Re: Replace itext with PDFBox for XDocReport project?
>
> Hi Kevin,
>
> What do you mean with richtext? In my case I would like create a PDF from
> scratch with PDF DOM-like with the same mean than iText.
> I have started to create a project (not commited for the moment
>
> Here my (basic sample) to generate paragraph with several text content
> (that
> I have called run like docx)
>
>
> ------------------------------------------------------------------------------------------------
> PDFBoxDocument document = new PDFBoxDocument();
>
> PDFBoxParagraph paragraph = document.addParagraph();
> paragraph.addRun("AAAA");
> paragraph.addRun(" ");
> paragraph.addRun("BBB");
>
> document.save("test.pdf");
>
> ------------------------------------------------------------------------------------------------
>
> This code generate a PDF with :
>
>
> ------------------------------------------------------------------------------------------------
> AAAA BBB
>
> ------------------------------------------------------------------------------------------------
>
> If you are interested (working together?) I could commit my work on our
> XDocReport git.
>
> Regards Angelo
>
> 2011/10/14 Kévin Sailly <ke...@gmail.com>
>
> > Hello,
> >
> > I am planning to build some code to create text from richtext (text from
> > rech text editor), is that what you are planning to do?
> >
> > Regards,
> > Kévin
> >
> >
> >
> > 2011/10/13 Angelo zerr <an...@gmail.com>
> >
> > > Hi PDFBox Team,
> > >
> > > I have started to investigate time with PDFBox to try to provides
> > > High-Level
> > > API to manage paragraph, table widgets etc....
> > > I recall my problem : we are using iText for our ODT->PDF and Docx->PDF
> > > converter and we wish provides our code for Apache. Problem is iText
> > > license.
> > > So I'm searching PDF API (PDFBox?FOP?) to manage PDF with Java model
> (not
> > > with XSL-FO). It seems that FOP provides this feature, but it's very
> hard
> > > to
> > > understand how to manage that?
> > >
> > > I have tried to manage a simple case : a paragraph with some text. I
> > would
> > > like generate PDF with this content:
> > >
> > > ----------------------------
> > > AAAA BBBB
> > > ----------------------------
> > >
> > > But not with one String but with 3 Strings (call 3 times
> > > contentStream.drawString(...);)
> > > The solution that I have found to manage that is to store the last X of
> > the
> > > added Stringby using Stringlenght+Font + Font size. Here my code
> > >
> > > ------------------------------------------------------
> > > import java.io.IOException;
> > >
> > > import org.apache.pdfbox.exceptions.COSVisitorException;
> > > import org.apache.pdfbox.pdmodel.PDDocument;
> > > import org.apache.pdfbox.pdmodel.PDPage;
> > > import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
> > > import org.apache.pdfbox.pdmodel.font.PDFont;
> > > import org.apache.pdfbox.pdmodel.font.PDType1Font;
> > >
> > > public class Test3 {
> > >
> > >    private static float lastX = 0;
> > >
> > >    public static void main(String[] args) throws IOException,
> > >            COSVisitorException {
> > >        PDDocument doc = null;
> > >        try {
> > >            doc = new PDDocument();
> > >
> > >            PDPage page = new PDPage();
> > >            doc.addPage(page);
> > >
> > >            PDPageContentStream contentStream = new
> > PDPageContentStream(doc,
> > >                    page);
> > >
> > >            PDFont font = PDType1Font.HELVETICA_BOLD;
> > >            long fontSize = 5;
> > >            addText("AAAA", font, fontSize, page, contentStream);
> > >            addText(" ", font, fontSize, page, contentStream);
> > >            addText("BBBB", font, fontSize, page, contentStream);
> > >
> > >            contentStream.close();
> > >
> > >            doc.save("test.pdf");
> > >
> > >        } finally {
> > >            if (doc != null) {
> > >                doc.close();
> > >            }
> > >        }
> > >    }
> > >
> > >    public static void addText(String text, PDFont font, long fontSize,
> > >            PDPage page, PDPageContentStream contentStream) throws
> > > IOException {
> > >
> > >        // Compute x
> > >        float x = lastX;
> > >        float nextX = lastX + font.getStringWidth(text) * fontSize /
> > 1000f;
> > >
> > >        // Compute Y
> > >        float y = page.getMediaBox().getHeight()
> > >                - (font.getFontHeight("A".getBytes(), 0, 1) * fontSize /
> > > 1000f);
> > >
> > >        contentStream.beginText();
> > >        contentStream.setFont(font, fontSize);
> > >        contentStream.moveTextPositionByAmount(x, y);
> > >        contentStream.drawString(text);
> > >        contentStream.endText();
> > >
> > >        // Recompute lastX
> > >        lastX = nextX;
> > >    }
> > >
> > > }
> > > ------------------------------------------------------
> > >
> > > I would like know if it's the correct mean? If it's OK, I would like
> know
> > > if
> > > it's possible to retrieve the default Font of the document, because in
> my
> > > case I have setted the Font?
> > >
> > > My code doesn't manage wrap text and I would like know how to manage
> > that?
> > >
> > > I'm very interested to provides and contribute Hight level API for
> PDFBox
> > > (paragraph, table...) but if I have no support I will give up my idea
> > (hope
> > > you will understand).
> > >
> > > Thank a lot for your help!
> > >
> > > Regards Angelo
> > >
> > >
> > >
> > >
> > > 2011/9/5 Angelo zerr <an...@gmail.com>
> > >
> > > > Hi Jeremias,
> > > >
> > > > I'm sorry I have not seen your answer
> > > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > > When I have studied FOP to manage PDF just with Java PDF widget I
> have
> > > not
> > > > found documentation so I believed that it was not possible, but it
> > seems
> > > > that is possible.
> > > > That's very cool. I will study that.
> > > >
> > > > Many thanks!
> > > >
> > > > Regards Angelo
> > > >
> > > >
> > > > 2011/9/5 Jeremias Maerki <de...@jeremias-maerki.ch>
> > > >
> > > >> Angelo,
> > > >> as I explained in [1], you don't have to use XSL-FO when using
> Apache
> > > >> FOP. It supports alternative means to create PDFs.
> > > >>
> > > >> [1]
> > > >>
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > >>
> > > >> But of course, Apache PDFBox would profit a lot from a higher-level
> > PDF
> > > >> production API. Any contributions are more than welcome.
> > > >>
> > > >> On 05.09.2011 10:56:20 Angelo zerr wrote:
> > > >> > Hi Jukka,
> > > >> >
> > > >> > Thank a lot for you answer. I have already implemented a docx->PDF
> > and
> > > >> > odt->PDF converters with FOP but I decided to give up for :
> > > >> >
> > > >> > * performance reason. I have used XSLT cache, use xsl:key to
> compute
> > > the
> > > >> > odt/docx styles but the FOP implementation is less performant than
> > > iText
> > > >> > implementation, because :
> > > >> >   * FOP process : odt -> XSLT -> FO -> FOP
> > > >> >   * iText process : odt -> ODFDOM (Java) -> iText
> > > >> > * xslt vs Java model : with the iText process, your model is Java,
> > > >> although
> > > >> > with FOP your model is XML. I prefer develop Java instead of XSLT.
> > > >> >
> > > >> > That's why I'm searching Java PDF API like PDFBox to replace iText
> > to
> > > >> > provides our code to Apache.
> > > >> >
> > > >> > Regards Angelo
> > > >> >
> > > >> > 2011/9/5 Jukka Zitting <ju...@gmail.com>
> > > >> >
> > > >> > > Hi Angelo,
> > > >> > >
> > > >> > > On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <
> > angelo.zerr@gmail.com
> > > >
> > > >> > > wrote:
> > > >> > > > I suppose that my post was not well explained as I have no
> > answer.
> > > I
> > > >> will
> > > >> > > be
> > > >> > > > very happy to use PDFBox in our XDocReport converter (docx->
> PDF
> > > and
> > > >> > > odt->
> > > >> > > > PDF) but develop converter is a big work and I can not
> > investiaget
> > > >> time
> > > >> > > if I
> > > >> > > > have no support.
> > > >> > >
> > > >> > > There's been some interest in making it easier to use PDFBox to
> > > >> > > generate complex new PDF documents, but so far the main use
> cases
> > > have
> > > >> > > been simpler. You might want to look at Apache FOP
> > > >> > > (http://xmlgraphics.apache.org/fop/) for a higher-level PDF
> > > >> generation
> > > >> > > tool.
> > > >> > >
> > > >> > > BR,
> > > >> > >
> > > >> > > Jukka Zitting
> > > >> > >
> > > >>
> > > >>
> > > >>
> > > >>
> > > >> Jeremias Maerki
> > > >>
> > > >>
> > > >
> > >
> >
>
> DISCLAIMER:
> This email (including any attachments) is intended for the sole use of the
> intended recipient/s and may contain material that is CONFIDENTIAL AND
> PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or
> distribution or forwarding of any or all of the contents in this message is
> STRICTLY PROHIBITED. If you are not the intended recipient, please contact
> the sender by email and delete all copies; your cooperation in this regard
> is appreciated.
>

RE: Replace itext with PDFBox for XDocReport project?

Posted by Srinivaas_Venkatarayan <Sr...@mahindrasatyam.com>.
Hi Angelo, If the source is going to be docx file, can you not use xslt and FOP to convert the xml (provided by docx file) to PDF?

Srinivaas

-----Original Message-----
From: Angelo zerr [mailto:angelo.zerr@gmail.com]
Sent: Friday, October 14, 2011 5:07 PM
To: users@pdfbox.apache.org
Subject: Re: Replace itext with PDFBox for XDocReport project?

Hi Kevin,

What do you mean with richtext? In my case I would like create a PDF from
scratch with PDF DOM-like with the same mean than iText.
I have started to create a project (not commited for the moment

Here my (basic sample) to generate paragraph with several text content (that
I have called run like docx)

------------------------------------------------------------------------------------------------
PDFBoxDocument document = new PDFBoxDocument();

PDFBoxParagraph paragraph = document.addParagraph();
paragraph.addRun("AAAA");
paragraph.addRun(" ");
paragraph.addRun("BBB");

document.save("test.pdf");
------------------------------------------------------------------------------------------------

This code generate a PDF with :

------------------------------------------------------------------------------------------------
AAAA BBB
------------------------------------------------------------------------------------------------

If you are interested (working together?) I could commit my work on our
XDocReport git.

Regards Angelo

2011/10/14 Kévin Sailly <ke...@gmail.com>

> Hello,
>
> I am planning to build some code to create text from richtext (text from
> rech text editor), is that what you are planning to do?
>
> Regards,
> Kévin
>
>
>
> 2011/10/13 Angelo zerr <an...@gmail.com>
>
> > Hi PDFBox Team,
> >
> > I have started to investigate time with PDFBox to try to provides
> > High-Level
> > API to manage paragraph, table widgets etc....
> > I recall my problem : we are using iText for our ODT->PDF and Docx->PDF
> > converter and we wish provides our code for Apache. Problem is iText
> > license.
> > So I'm searching PDF API (PDFBox?FOP?) to manage PDF with Java model (not
> > with XSL-FO). It seems that FOP provides this feature, but it's very hard
> > to
> > understand how to manage that?
> >
> > I have tried to manage a simple case : a paragraph with some text. I
> would
> > like generate PDF with this content:
> >
> > ----------------------------
> > AAAA BBBB
> > ----------------------------
> >
> > But not with one String but with 3 Strings (call 3 times
> > contentStream.drawString(...);)
> > The solution that I have found to manage that is to store the last X of
> the
> > added Stringby using Stringlenght+Font + Font size. Here my code
> >
> > ------------------------------------------------------
> > import java.io.IOException;
> >
> > import org.apache.pdfbox.exceptions.COSVisitorException;
> > import org.apache.pdfbox.pdmodel.PDDocument;
> > import org.apache.pdfbox.pdmodel.PDPage;
> > import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
> > import org.apache.pdfbox.pdmodel.font.PDFont;
> > import org.apache.pdfbox.pdmodel.font.PDType1Font;
> >
> > public class Test3 {
> >
> >    private static float lastX = 0;
> >
> >    public static void main(String[] args) throws IOException,
> >            COSVisitorException {
> >        PDDocument doc = null;
> >        try {
> >            doc = new PDDocument();
> >
> >            PDPage page = new PDPage();
> >            doc.addPage(page);
> >
> >            PDPageContentStream contentStream = new
> PDPageContentStream(doc,
> >                    page);
> >
> >            PDFont font = PDType1Font.HELVETICA_BOLD;
> >            long fontSize = 5;
> >            addText("AAAA", font, fontSize, page, contentStream);
> >            addText(" ", font, fontSize, page, contentStream);
> >            addText("BBBB", font, fontSize, page, contentStream);
> >
> >            contentStream.close();
> >
> >            doc.save("test.pdf");
> >
> >        } finally {
> >            if (doc != null) {
> >                doc.close();
> >            }
> >        }
> >    }
> >
> >    public static void addText(String text, PDFont font, long fontSize,
> >            PDPage page, PDPageContentStream contentStream) throws
> > IOException {
> >
> >        // Compute x
> >        float x = lastX;
> >        float nextX = lastX + font.getStringWidth(text) * fontSize /
> 1000f;
> >
> >        // Compute Y
> >        float y = page.getMediaBox().getHeight()
> >                - (font.getFontHeight("A".getBytes(), 0, 1) * fontSize /
> > 1000f);
> >
> >        contentStream.beginText();
> >        contentStream.setFont(font, fontSize);
> >        contentStream.moveTextPositionByAmount(x, y);
> >        contentStream.drawString(text);
> >        contentStream.endText();
> >
> >        // Recompute lastX
> >        lastX = nextX;
> >    }
> >
> > }
> > ------------------------------------------------------
> >
> > I would like know if it's the correct mean? If it's OK, I would like know
> > if
> > it's possible to retrieve the default Font of the document, because in my
> > case I have setted the Font?
> >
> > My code doesn't manage wrap text and I would like know how to manage
> that?
> >
> > I'm very interested to provides and contribute Hight level API for PDFBox
> > (paragraph, table...) but if I have no support I will give up my idea
> (hope
> > you will understand).
> >
> > Thank a lot for your help!
> >
> > Regards Angelo
> >
> >
> >
> >
> > 2011/9/5 Angelo zerr <an...@gmail.com>
> >
> > > Hi Jeremias,
> > >
> > > I'm sorry I have not seen your answer
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > When I have studied FOP to manage PDF just with Java PDF widget I have
> > not
> > > found documentation so I believed that it was not possible, but it
> seems
> > > that is possible.
> > > That's very cool. I will study that.
> > >
> > > Many thanks!
> > >
> > > Regards Angelo
> > >
> > >
> > > 2011/9/5 Jeremias Maerki <de...@jeremias-maerki.ch>
> > >
> > >> Angelo,
> > >> as I explained in [1], you don't have to use XSL-FO when using Apache
> > >> FOP. It supports alternative means to create PDFs.
> > >>
> > >> [1]
> > >>
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > >>
> > >> But of course, Apache PDFBox would profit a lot from a higher-level
> PDF
> > >> production API. Any contributions are more than welcome.
> > >>
> > >> On 05.09.2011 10:56:20 Angelo zerr wrote:
> > >> > Hi Jukka,
> > >> >
> > >> > Thank a lot for you answer. I have already implemented a docx->PDF
> and
> > >> > odt->PDF converters with FOP but I decided to give up for :
> > >> >
> > >> > * performance reason. I have used XSLT cache, use xsl:key to compute
> > the
> > >> > odt/docx styles but the FOP implementation is less performant than
> > iText
> > >> > implementation, because :
> > >> >   * FOP process : odt -> XSLT -> FO -> FOP
> > >> >   * iText process : odt -> ODFDOM (Java) -> iText
> > >> > * xslt vs Java model : with the iText process, your model is Java,
> > >> although
> > >> > with FOP your model is XML. I prefer develop Java instead of XSLT.
> > >> >
> > >> > That's why I'm searching Java PDF API like PDFBox to replace iText
> to
> > >> > provides our code to Apache.
> > >> >
> > >> > Regards Angelo
> > >> >
> > >> > 2011/9/5 Jukka Zitting <ju...@gmail.com>
> > >> >
> > >> > > Hi Angelo,
> > >> > >
> > >> > > On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <
> angelo.zerr@gmail.com
> > >
> > >> > > wrote:
> > >> > > > I suppose that my post was not well explained as I have no
> answer.
> > I
> > >> will
> > >> > > be
> > >> > > > very happy to use PDFBox in our XDocReport converter (docx-> PDF
> > and
> > >> > > odt->
> > >> > > > PDF) but develop converter is a big work and I can not
> investiaget
> > >> time
> > >> > > if I
> > >> > > > have no support.
> > >> > >
> > >> > > There's been some interest in making it easier to use PDFBox to
> > >> > > generate complex new PDF documents, but so far the main use cases
> > have
> > >> > > been simpler. You might want to look at Apache FOP
> > >> > > (http://xmlgraphics.apache.org/fop/) for a higher-level PDF
> > >> generation
> > >> > > tool.
> > >> > >
> > >> > > BR,
> > >> > >
> > >> > > Jukka Zitting
> > >> > >
> > >>
> > >>
> > >>
> > >>
> > >> Jeremias Maerki
> > >>
> > >>
> > >
> >
>

DISCLAIMER:
This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.

Re: Replace itext with PDFBox for XDocReport project?

Posted by Angelo zerr <an...@gmail.com>.
Hi Kevin,

What do you mean with richtext? In my case I would like create a PDF from
scratch with PDF DOM-like with the same mean than iText.
I have started to create a project (not commited for the moment

Here my (basic sample) to generate paragraph with several text content (that
I have called run like docx)

------------------------------------------------------------------------------------------------
PDFBoxDocument document = new PDFBoxDocument();

PDFBoxParagraph paragraph = document.addParagraph();
paragraph.addRun("AAAA");
paragraph.addRun(" ");
paragraph.addRun("BBB");

document.save("test.pdf");
------------------------------------------------------------------------------------------------

This code generate a PDF with :

------------------------------------------------------------------------------------------------
AAAA BBB
------------------------------------------------------------------------------------------------

If you are interested (working together?) I could commit my work on our
XDocReport git.

Regards Angelo

2011/10/14 Kévin Sailly <ke...@gmail.com>

> Hello,
>
> I am planning to build some code to create text from richtext (text from
> rech text editor), is that what you are planning to do?
>
> Regards,
> Kévin
>
>
>
> 2011/10/13 Angelo zerr <an...@gmail.com>
>
> > Hi PDFBox Team,
> >
> > I have started to investigate time with PDFBox to try to provides
> > High-Level
> > API to manage paragraph, table widgets etc....
> > I recall my problem : we are using iText for our ODT->PDF and Docx->PDF
> > converter and we wish provides our code for Apache. Problem is iText
> > license.
> > So I'm searching PDF API (PDFBox?FOP?) to manage PDF with Java model (not
> > with XSL-FO). It seems that FOP provides this feature, but it's very hard
> > to
> > understand how to manage that?
> >
> > I have tried to manage a simple case : a paragraph with some text. I
> would
> > like generate PDF with this content:
> >
> > ----------------------------
> > AAAA BBBB
> > ----------------------------
> >
> > But not with one String but with 3 Strings (call 3 times
> > contentStream.drawString(...);)
> > The solution that I have found to manage that is to store the last X of
> the
> > added Stringby using Stringlenght+Font + Font size. Here my code
> >
> > ------------------------------------------------------
> > import java.io.IOException;
> >
> > import org.apache.pdfbox.exceptions.COSVisitorException;
> > import org.apache.pdfbox.pdmodel.PDDocument;
> > import org.apache.pdfbox.pdmodel.PDPage;
> > import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
> > import org.apache.pdfbox.pdmodel.font.PDFont;
> > import org.apache.pdfbox.pdmodel.font.PDType1Font;
> >
> > public class Test3 {
> >
> >    private static float lastX = 0;
> >
> >    public static void main(String[] args) throws IOException,
> >            COSVisitorException {
> >        PDDocument doc = null;
> >        try {
> >            doc = new PDDocument();
> >
> >            PDPage page = new PDPage();
> >            doc.addPage(page);
> >
> >            PDPageContentStream contentStream = new
> PDPageContentStream(doc,
> >                    page);
> >
> >            PDFont font = PDType1Font.HELVETICA_BOLD;
> >            long fontSize = 5;
> >            addText("AAAA", font, fontSize, page, contentStream);
> >            addText(" ", font, fontSize, page, contentStream);
> >            addText("BBBB", font, fontSize, page, contentStream);
> >
> >            contentStream.close();
> >
> >            doc.save("test.pdf");
> >
> >        } finally {
> >            if (doc != null) {
> >                doc.close();
> >            }
> >        }
> >    }
> >
> >    public static void addText(String text, PDFont font, long fontSize,
> >            PDPage page, PDPageContentStream contentStream) throws
> > IOException {
> >
> >        // Compute x
> >        float x = lastX;
> >        float nextX = lastX + font.getStringWidth(text) * fontSize /
> 1000f;
> >
> >        // Compute Y
> >        float y = page.getMediaBox().getHeight()
> >                - (font.getFontHeight("A".getBytes(), 0, 1) * fontSize /
> > 1000f);
> >
> >        contentStream.beginText();
> >        contentStream.setFont(font, fontSize);
> >        contentStream.moveTextPositionByAmount(x, y);
> >        contentStream.drawString(text);
> >        contentStream.endText();
> >
> >        // Recompute lastX
> >        lastX = nextX;
> >    }
> >
> > }
> > ------------------------------------------------------
> >
> > I would like know if it's the correct mean? If it's OK, I would like know
> > if
> > it's possible to retrieve the default Font of the document, because in my
> > case I have setted the Font?
> >
> > My code doesn't manage wrap text and I would like know how to manage
> that?
> >
> > I'm very interested to provides and contribute Hight level API for PDFBox
> > (paragraph, table...) but if I have no support I will give up my idea
> (hope
> > you will understand).
> >
> > Thank a lot for your help!
> >
> > Regards Angelo
> >
> >
> >
> >
> > 2011/9/5 Angelo zerr <an...@gmail.com>
> >
> > > Hi Jeremias,
> > >
> > > I'm sorry I have not seen your answer
> > >
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > > When I have studied FOP to manage PDF just with Java PDF widget I have
> > not
> > > found documentation so I believed that it was not possible, but it
> seems
> > > that is possible.
> > > That's very cool. I will study that.
> > >
> > > Many thanks!
> > >
> > > Regards Angelo
> > >
> > >
> > > 2011/9/5 Jeremias Maerki <de...@jeremias-maerki.ch>
> > >
> > >> Angelo,
> > >> as I explained in [1], you don't have to use XSL-FO when using Apache
> > >> FOP. It supports alternative means to create PDFs.
> > >>
> > >> [1]
> > >>
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > >>
> > >> But of course, Apache PDFBox would profit a lot from a higher-level
> PDF
> > >> production API. Any contributions are more than welcome.
> > >>
> > >> On 05.09.2011 10:56:20 Angelo zerr wrote:
> > >> > Hi Jukka,
> > >> >
> > >> > Thank a lot for you answer. I have already implemented a docx->PDF
> and
> > >> > odt->PDF converters with FOP but I decided to give up for :
> > >> >
> > >> > * performance reason. I have used XSLT cache, use xsl:key to compute
> > the
> > >> > odt/docx styles but the FOP implementation is less performant than
> > iText
> > >> > implementation, because :
> > >> >   * FOP process : odt -> XSLT -> FO -> FOP
> > >> >   * iText process : odt -> ODFDOM (Java) -> iText
> > >> > * xslt vs Java model : with the iText process, your model is Java,
> > >> although
> > >> > with FOP your model is XML. I prefer develop Java instead of XSLT.
> > >> >
> > >> > That's why I'm searching Java PDF API like PDFBox to replace iText
> to
> > >> > provides our code to Apache.
> > >> >
> > >> > Regards Angelo
> > >> >
> > >> > 2011/9/5 Jukka Zitting <ju...@gmail.com>
> > >> >
> > >> > > Hi Angelo,
> > >> > >
> > >> > > On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <
> angelo.zerr@gmail.com
> > >
> > >> > > wrote:
> > >> > > > I suppose that my post was not well explained as I have no
> answer.
> > I
> > >> will
> > >> > > be
> > >> > > > very happy to use PDFBox in our XDocReport converter (docx-> PDF
> > and
> > >> > > odt->
> > >> > > > PDF) but develop converter is a big work and I can not
> investiaget
> > >> time
> > >> > > if I
> > >> > > > have no support.
> > >> > >
> > >> > > There's been some interest in making it easier to use PDFBox to
> > >> > > generate complex new PDF documents, but so far the main use cases
> > have
> > >> > > been simpler. You might want to look at Apache FOP
> > >> > > (http://xmlgraphics.apache.org/fop/) for a higher-level PDF
> > >> generation
> > >> > > tool.
> > >> > >
> > >> > > BR,
> > >> > >
> > >> > > Jukka Zitting
> > >> > >
> > >>
> > >>
> > >>
> > >>
> > >> Jeremias Maerki
> > >>
> > >>
> > >
> >
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Kévin Sailly <ke...@gmail.com>.
Hello,

I am planning to build some code to create text from richtext (text from
rech text editor), is that what you are planning to do?

Regards,
Kévin



2011/10/13 Angelo zerr <an...@gmail.com>

> Hi PDFBox Team,
>
> I have started to investigate time with PDFBox to try to provides
> High-Level
> API to manage paragraph, table widgets etc....
> I recall my problem : we are using iText for our ODT->PDF and Docx->PDF
> converter and we wish provides our code for Apache. Problem is iText
> license.
> So I'm searching PDF API (PDFBox?FOP?) to manage PDF with Java model (not
> with XSL-FO). It seems that FOP provides this feature, but it's very hard
> to
> understand how to manage that?
>
> I have tried to manage a simple case : a paragraph with some text. I would
> like generate PDF with this content:
>
> ----------------------------
> AAAA BBBB
> ----------------------------
>
> But not with one String but with 3 Strings (call 3 times
> contentStream.drawString(...);)
> The solution that I have found to manage that is to store the last X of the
> added Stringby using Stringlenght+Font + Font size. Here my code
>
> ------------------------------------------------------
> import java.io.IOException;
>
> import org.apache.pdfbox.exceptions.COSVisitorException;
> import org.apache.pdfbox.pdmodel.PDDocument;
> import org.apache.pdfbox.pdmodel.PDPage;
> import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
> import org.apache.pdfbox.pdmodel.font.PDFont;
> import org.apache.pdfbox.pdmodel.font.PDType1Font;
>
> public class Test3 {
>
>    private static float lastX = 0;
>
>    public static void main(String[] args) throws IOException,
>            COSVisitorException {
>        PDDocument doc = null;
>        try {
>            doc = new PDDocument();
>
>            PDPage page = new PDPage();
>            doc.addPage(page);
>
>            PDPageContentStream contentStream = new PDPageContentStream(doc,
>                    page);
>
>            PDFont font = PDType1Font.HELVETICA_BOLD;
>            long fontSize = 5;
>            addText("AAAA", font, fontSize, page, contentStream);
>            addText(" ", font, fontSize, page, contentStream);
>            addText("BBBB", font, fontSize, page, contentStream);
>
>            contentStream.close();
>
>            doc.save("test.pdf");
>
>        } finally {
>            if (doc != null) {
>                doc.close();
>            }
>        }
>    }
>
>    public static void addText(String text, PDFont font, long fontSize,
>            PDPage page, PDPageContentStream contentStream) throws
> IOException {
>
>        // Compute x
>        float x = lastX;
>        float nextX = lastX + font.getStringWidth(text) * fontSize / 1000f;
>
>        // Compute Y
>        float y = page.getMediaBox().getHeight()
>                - (font.getFontHeight("A".getBytes(), 0, 1) * fontSize /
> 1000f);
>
>        contentStream.beginText();
>        contentStream.setFont(font, fontSize);
>        contentStream.moveTextPositionByAmount(x, y);
>        contentStream.drawString(text);
>        contentStream.endText();
>
>        // Recompute lastX
>        lastX = nextX;
>    }
>
> }
> ------------------------------------------------------
>
> I would like know if it's the correct mean? If it's OK, I would like know
> if
> it's possible to retrieve the default Font of the document, because in my
> case I have setted the Font?
>
> My code doesn't manage wrap text and I would like know how to manage that?
>
> I'm very interested to provides and contribute Hight level API for PDFBox
> (paragraph, table...) but if I have no support I will give up my idea (hope
> you will understand).
>
> Thank a lot for your help!
>
> Regards Angelo
>
>
>
>
> 2011/9/5 Angelo zerr <an...@gmail.com>
>
> > Hi Jeremias,
> >
> > I'm sorry I have not seen your answer
> >
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> > When I have studied FOP to manage PDF just with Java PDF widget I have
> not
> > found documentation so I believed that it was not possible, but it seems
> > that is possible.
> > That's very cool. I will study that.
> >
> > Many thanks!
> >
> > Regards Angelo
> >
> >
> > 2011/9/5 Jeremias Maerki <de...@jeremias-maerki.ch>
> >
> >> Angelo,
> >> as I explained in [1], you don't have to use XSL-FO when using Apache
> >> FOP. It supports alternative means to create PDFs.
> >>
> >> [1]
> >>
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> >>
> >> But of course, Apache PDFBox would profit a lot from a higher-level PDF
> >> production API. Any contributions are more than welcome.
> >>
> >> On 05.09.2011 10:56:20 Angelo zerr wrote:
> >> > Hi Jukka,
> >> >
> >> > Thank a lot for you answer. I have already implemented a docx->PDF and
> >> > odt->PDF converters with FOP but I decided to give up for :
> >> >
> >> > * performance reason. I have used XSLT cache, use xsl:key to compute
> the
> >> > odt/docx styles but the FOP implementation is less performant than
> iText
> >> > implementation, because :
> >> >   * FOP process : odt -> XSLT -> FO -> FOP
> >> >   * iText process : odt -> ODFDOM (Java) -> iText
> >> > * xslt vs Java model : with the iText process, your model is Java,
> >> although
> >> > with FOP your model is XML. I prefer develop Java instead of XSLT.
> >> >
> >> > That's why I'm searching Java PDF API like PDFBox to replace iText to
> >> > provides our code to Apache.
> >> >
> >> > Regards Angelo
> >> >
> >> > 2011/9/5 Jukka Zitting <ju...@gmail.com>
> >> >
> >> > > Hi Angelo,
> >> > >
> >> > > On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <angelo.zerr@gmail.com
> >
> >> > > wrote:
> >> > > > I suppose that my post was not well explained as I have no answer.
> I
> >> will
> >> > > be
> >> > > > very happy to use PDFBox in our XDocReport converter (docx-> PDF
> and
> >> > > odt->
> >> > > > PDF) but develop converter is a big work and I can not investiaget
> >> time
> >> > > if I
> >> > > > have no support.
> >> > >
> >> > > There's been some interest in making it easier to use PDFBox to
> >> > > generate complex new PDF documents, but so far the main use cases
> have
> >> > > been simpler. You might want to look at Apache FOP
> >> > > (http://xmlgraphics.apache.org/fop/) for a higher-level PDF
> >> generation
> >> > > tool.
> >> > >
> >> > > BR,
> >> > >
> >> > > Jukka Zitting
> >> > >
> >>
> >>
> >>
> >>
> >> Jeremias Maerki
> >>
> >>
> >
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Angelo zerr <an...@gmail.com>.
Hi PDFBox Team,

I have started to investigate time with PDFBox to try to provides High-Level
API to manage paragraph, table widgets etc....
I recall my problem : we are using iText for our ODT->PDF and Docx->PDF
converter and we wish provides our code for Apache. Problem is iText
license.
So I'm searching PDF API (PDFBox?FOP?) to manage PDF with Java model (not
with XSL-FO). It seems that FOP provides this feature, but it's very hard to
understand how to manage that?

I have tried to manage a simple case : a paragraph with some text. I would
like generate PDF with this content:

----------------------------
AAAA BBBB
----------------------------

But not with one String but with 3 Strings (call 3 times
contentStream.drawString(...);)
The solution that I have found to manage that is to store the last X of the
added Stringby using Stringlenght+Font + Font size. Here my code

------------------------------------------------------
import java.io.IOException;

import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;

public class Test3 {

    private static float lastX = 0;

    public static void main(String[] args) throws IOException,
            COSVisitorException {
        PDDocument doc = null;
        try {
            doc = new PDDocument();

            PDPage page = new PDPage();
            doc.addPage(page);

            PDPageContentStream contentStream = new PDPageContentStream(doc,
                    page);

            PDFont font = PDType1Font.HELVETICA_BOLD;
            long fontSize = 5;
            addText("AAAA", font, fontSize, page, contentStream);
            addText(" ", font, fontSize, page, contentStream);
            addText("BBBB", font, fontSize, page, contentStream);

            contentStream.close();

            doc.save("test.pdf");

        } finally {
            if (doc != null) {
                doc.close();
            }
        }
    }

    public static void addText(String text, PDFont font, long fontSize,
            PDPage page, PDPageContentStream contentStream) throws
IOException {

        // Compute x
        float x = lastX;
        float nextX = lastX + font.getStringWidth(text) * fontSize / 1000f;

        // Compute Y
        float y = page.getMediaBox().getHeight()
                - (font.getFontHeight("A".getBytes(), 0, 1) * fontSize /
1000f);

        contentStream.beginText();
        contentStream.setFont(font, fontSize);
        contentStream.moveTextPositionByAmount(x, y);
        contentStream.drawString(text);
        contentStream.endText();

        // Recompute lastX
        lastX = nextX;
    }

}
------------------------------------------------------

I would like know if it's the correct mean? If it's OK, I would like know if
it's possible to retrieve the default Font of the document, because in my
case I have setted the Font?

My code doesn't manage wrap text and I would like know how to manage that?

I'm very interested to provides and contribute Hight level API for PDFBox
(paragraph, table...) but if I have no support I will give up my idea (hope
you will understand).

Thank a lot for your help!

Regards Angelo




2011/9/5 Angelo zerr <an...@gmail.com>

> Hi Jeremias,
>
> I'm sorry I have not seen your answer
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
> When I have studied FOP to manage PDF just with Java PDF widget I have not
> found documentation so I believed that it was not possible, but it seems
> that is possible.
> That's very cool. I will study that.
>
> Many thanks!
>
> Regards Angelo
>
>
> 2011/9/5 Jeremias Maerki <de...@jeremias-maerki.ch>
>
>> Angelo,
>> as I explained in [1], you don't have to use XSL-FO when using Apache
>> FOP. It supports alternative means to create PDFs.
>>
>> [1]
>> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
>>
>> But of course, Apache PDFBox would profit a lot from a higher-level PDF
>> production API. Any contributions are more than welcome.
>>
>> On 05.09.2011 10:56:20 Angelo zerr wrote:
>> > Hi Jukka,
>> >
>> > Thank a lot for you answer. I have already implemented a docx->PDF and
>> > odt->PDF converters with FOP but I decided to give up for :
>> >
>> > * performance reason. I have used XSLT cache, use xsl:key to compute the
>> > odt/docx styles but the FOP implementation is less performant than iText
>> > implementation, because :
>> >   * FOP process : odt -> XSLT -> FO -> FOP
>> >   * iText process : odt -> ODFDOM (Java) -> iText
>> > * xslt vs Java model : with the iText process, your model is Java,
>> although
>> > with FOP your model is XML. I prefer develop Java instead of XSLT.
>> >
>> > That's why I'm searching Java PDF API like PDFBox to replace iText to
>> > provides our code to Apache.
>> >
>> > Regards Angelo
>> >
>> > 2011/9/5 Jukka Zitting <ju...@gmail.com>
>> >
>> > > Hi Angelo,
>> > >
>> > > On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <an...@gmail.com>
>> > > wrote:
>> > > > I suppose that my post was not well explained as I have no answer. I
>> will
>> > > be
>> > > > very happy to use PDFBox in our XDocReport converter (docx-> PDF and
>> > > odt->
>> > > > PDF) but develop converter is a big work and I can not investiaget
>> time
>> > > if I
>> > > > have no support.
>> > >
>> > > There's been some interest in making it easier to use PDFBox to
>> > > generate complex new PDF documents, but so far the main use cases have
>> > > been simpler. You might want to look at Apache FOP
>> > > (http://xmlgraphics.apache.org/fop/) for a higher-level PDF
>> generation
>> > > tool.
>> > >
>> > > BR,
>> > >
>> > > Jukka Zitting
>> > >
>>
>>
>>
>>
>> Jeremias Maerki
>>
>>
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Angelo zerr <an...@gmail.com>.
Hi Jeremias,

I'm sorry I have not seen your answer
http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
When I have studied FOP to manage PDF just with Java PDF widget I have not
found documentation so I believed that it was not possible, but it seems
that is possible.
That's very cool. I will study that.

Many thanks!

Regards Angelo

2011/9/5 Jeremias Maerki <de...@jeremias-maerki.ch>

> Angelo,
> as I explained in [1], you don't have to use XSL-FO when using Apache
> FOP. It supports alternative means to create PDFs.
>
> [1]
> http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E
>
> But of course, Apache PDFBox would profit a lot from a higher-level PDF
> production API. Any contributions are more than welcome.
>
> On 05.09.2011 10:56:20 Angelo zerr wrote:
> > Hi Jukka,
> >
> > Thank a lot for you answer. I have already implemented a docx->PDF and
> > odt->PDF converters with FOP but I decided to give up for :
> >
> > * performance reason. I have used XSLT cache, use xsl:key to compute the
> > odt/docx styles but the FOP implementation is less performant than iText
> > implementation, because :
> >   * FOP process : odt -> XSLT -> FO -> FOP
> >   * iText process : odt -> ODFDOM (Java) -> iText
> > * xslt vs Java model : with the iText process, your model is Java,
> although
> > with FOP your model is XML. I prefer develop Java instead of XSLT.
> >
> > That's why I'm searching Java PDF API like PDFBox to replace iText to
> > provides our code to Apache.
> >
> > Regards Angelo
> >
> > 2011/9/5 Jukka Zitting <ju...@gmail.com>
> >
> > > Hi Angelo,
> > >
> > > On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <an...@gmail.com>
> > > wrote:
> > > > I suppose that my post was not well explained as I have no answer. I
> will
> > > be
> > > > very happy to use PDFBox in our XDocReport converter (docx-> PDF and
> > > odt->
> > > > PDF) but develop converter is a big work and I can not investiaget
> time
> > > if I
> > > > have no support.
> > >
> > > There's been some interest in making it easier to use PDFBox to
> > > generate complex new PDF documents, but so far the main use cases have
> > > been simpler. You might want to look at Apache FOP
> > > (http://xmlgraphics.apache.org/fop/) for a higher-level PDF generation
> > > tool.
> > >
> > > BR,
> > >
> > > Jukka Zitting
> > >
>
>
>
>
> Jeremias Maerki
>
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Angelo,
as I explained in [1], you don't have to use XSL-FO when using Apache
FOP. It supports alternative means to create PDFs.

[1] http://mail-archives.apache.org/mod_mbox/incubator-odf-dev/201108.mbox/%3C20110823085249.B299.60BA733C@jeremias-maerki.ch%3E

But of course, Apache PDFBox would profit a lot from a higher-level PDF
production API. Any contributions are more than welcome.

On 05.09.2011 10:56:20 Angelo zerr wrote:
> Hi Jukka,
> 
> Thank a lot for you answer. I have already implemented a docx->PDF and
> odt->PDF converters with FOP but I decided to give up for :
> 
> * performance reason. I have used XSLT cache, use xsl:key to compute the
> odt/docx styles but the FOP implementation is less performant than iText
> implementation, because :
>   * FOP process : odt -> XSLT -> FO -> FOP
>   * iText process : odt -> ODFDOM (Java) -> iText
> * xslt vs Java model : with the iText process, your model is Java, although
> with FOP your model is XML. I prefer develop Java instead of XSLT.
> 
> That's why I'm searching Java PDF API like PDFBox to replace iText to
> provides our code to Apache.
> 
> Regards Angelo
> 
> 2011/9/5 Jukka Zitting <ju...@gmail.com>
> 
> > Hi Angelo,
> >
> > On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <an...@gmail.com>
> > wrote:
> > > I suppose that my post was not well explained as I have no answer. I will
> > be
> > > very happy to use PDFBox in our XDocReport converter (docx-> PDF and
> > odt->
> > > PDF) but develop converter is a big work and I can not investiaget time
> > if I
> > > have no support.
> >
> > There's been some interest in making it easier to use PDFBox to
> > generate complex new PDF documents, but so far the main use cases have
> > been simpler. You might want to look at Apache FOP
> > (http://xmlgraphics.apache.org/fop/) for a higher-level PDF generation
> > tool.
> >
> > BR,
> >
> > Jukka Zitting
> >




Jeremias Maerki


Re: Replace itext with PDFBox for XDocReport project?

Posted by Angelo zerr <an...@gmail.com>.
Hi Jukka,

Thank a lot for you answer. I have already implemented a docx->PDF and
odt->PDF converters with FOP but I decided to give up for :

* performance reason. I have used XSLT cache, use xsl:key to compute the
odt/docx styles but the FOP implementation is less performant than iText
implementation, because :
  * FOP process : odt -> XSLT -> FO -> FOP
  * iText process : odt -> ODFDOM (Java) -> iText
* xslt vs Java model : with the iText process, your model is Java, although
with FOP your model is XML. I prefer develop Java instead of XSLT.

That's why I'm searching Java PDF API like PDFBox to replace iText to
provides our code to Apache.

Regards Angelo

2011/9/5 Jukka Zitting <ju...@gmail.com>

> Hi Angelo,
>
> On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <an...@gmail.com>
> wrote:
> > I suppose that my post was not well explained as I have no answer. I will
> be
> > very happy to use PDFBox in our XDocReport converter (docx-> PDF and
> odt->
> > PDF) but develop converter is a big work and I can not investiaget time
> if I
> > have no support.
>
> There's been some interest in making it easier to use PDFBox to
> generate complex new PDF documents, but so far the main use cases have
> been simpler. You might want to look at Apache FOP
> (http://xmlgraphics.apache.org/fop/) for a higher-level PDF generation
> tool.
>
> BR,
>
> Jukka Zitting
>

Re: Replace itext with PDFBox for XDocReport project?

Posted by Jukka Zitting <ju...@gmail.com>.
Hi Angelo,

On Mon, Sep 5, 2011 at 10:11 AM, Angelo zerr <an...@gmail.com> wrote:
> I suppose that my post was not well explained as I have no answer. I will be
> very happy to use PDFBox in our XDocReport converter (docx-> PDF and odt->
> PDF) but develop converter is a big work and I can not investiaget time if I
> have no support.

There's been some interest in making it easier to use PDFBox to
generate complex new PDF documents, but so far the main use cases have
been simpler. You might want to look at Apache FOP
(http://xmlgraphics.apache.org/fop/) for a higher-level PDF generation
tool.

BR,

Jukka Zitting