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 <[email protected]>

> 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 <[email protected]>
>
> > 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 <[email protected]>
> >
> > > 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 <[email protected]>
> > > >
> > > > > 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
> > > [email protected]
> > > > > from here.
> > > > >
> > > > > On 14.10.2011 23:54:56 Angelo zerr wrote:
> > > > > > Hi Steve
> > > > > >
> > > > > > 2011/10/14 Steve Hannah <[email protected]>
> > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > 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
> > >
> > >
> >
>

Reply via email to