Support for external CSS file from Apache FOP PDF Generation - java

Does the apache FOP supports external CSS file for generating PDF from html document? I am specifying the css file path html file but styles are not applied on pdf report generated. Also I tried copy pasting the entire style content inside tag in html document. Still generated report does not the style applied. Since I am the beginner for FOP, I would be really great if someone tells me What am I missing here?
Another fundamental question would be.. does the Apache FOP supports external css file?

To use CSS with XSL FO you would need something that processes CSS into XSL FO. You can look at the link below which is not Apache FOP but uses RenderX XEP behind the scenes. It allows for XML and/or HTML with CSS internal and external, leveraging XSL FO technology to format content.
http://www.cloudformatter.com/CSS2Pdf

Related

Having Freemarker-like templates for PDF generation (with itext)

In Java Project, i would like to use a Freemarker or something similar to it
(Quick start guide), but to generate a PDF file (textual), with IText for example.
Of cource, the workflow could be like that:
Template (Freemarker) -> Text (IText) -> PDF
...but I feel it is kind of a naive approach. I want to have in the PDF some formattings, tables, etc.
Anyone knows how to design it properly?
As PDF is a binary format, the best seems to generate some standard text format for which there exists a PDF conversion.
Texts --[FreeMarker]--> HTML or --[HTML-to-iText]--> PDF
DocBook XML
This also allows validation of the FreeMarker templates.

How to generate a xslt file from xml

I'm beginner with xml and xsl. I'm looking for the way to generate or understanding how is the using of xsl stylesheet. In my particular case, I'm using a html file which it converts to xhtml. The next step I want to convert is the file generated to xsl-fo but I've seen I have to use a xslt stylesheet to do that. My question is about this file. How is it generate this xsl file? Is generated from the xhtml file?
Thanks!
Antenna House provides a sample XHTML to XSL-FO stylesheet under the 'XHTML to XSL-FO' tab at http://www.antennahouse.com/antenna1/xml-to-xsl-fo-stylesheets/. There's also an XSL-FO tutorial available under the 'XML to XSL-FO' tab.
Generally, the XSL file for an XSL-FO conversion is not generated. You'll have to create this file yourself. It contains a lot of information not present in the XHTML, for example page layouts.
XSL-FO is a bit like CSS, yes. The difference is that XSL-FO has lots more options, so an XSL-FO file is 100 times longer than a CSS file.
Here's an introduction to XSL-FO.
And another tutorial.
Okay this site can give you some helps to generate xslfo site.
Abd if you wont the contrary this site is fine
XSL FO to HTML Converter

xsl stylesheet for generating word documents from Java

I was wondering if there is any Java API which allows to generate Word document similarly Apache FOP does.
With FOP, it is possible to specify a style sheet which defines the layout of the page in which the data (stored in an xml file) are printed.
The Transformer object within FOP library is in charge of that.
Is there any equivalent API for word document?
With FOP, you can try XML to RTF, which Word accepts.
From their webpage, XMLmind XSL-FO Converter apparently generates:
RTF (can be opened in Word 2000+),
WordprocessingML (can be opened inWord 2003+),
Office Open XML (.docx, can be opened in Word 2007+),
Putting FO to one side, here are 2 different approaches:
The first would be to write an XSLT to convert your XML to Flat OPC XML. Most parts in the Flat OPC XML would simply be copied there by your XSLT. (Generate that template content in Word, using "save as XML"). You'll be focusing mainly on populating the document.xml part. Word can open a Flat OPC XML file, or you can use docx4j (a project I work on) to convert Flat OPC XML to docx.
The second would be to use the docx4j Flying Saucer fork to convert your XML + CSS to docx content. See the code samples. You may need to customise it a bit; one way of feeding it CSS is this file. This actually ought to work pretty well; there is stuff there for mapping class attributes to Word styles, so if you could adorn your XML with class attributes, you could get even better results.
I will assume that your input is an XML document, or at least a CSV file.
1) Create an XSLT stylesheet to transform your input into the Word document format. The result will be a file we will call content.xml. You can apply the stylesheet to the input from Java.
2) Create a MS Word shell and put the content.xml into the shell. There are tools within Apache POI to do this.
I may have taken your question too literally. You might also be able to generate the document using Apache POI API. Also, if your MS Word document doesn't have tables, you can use Apache FOP to generate an RTF document, which can then be easily translated to a .docx file.
Apache POI provides Java APIs for reading and writing Microsoft Excel, Word, and PowerPoint files.
You can checkout POI's Javadocs here.

Generate PDF files using iText and apache velocity template(.vm)

What is the general workflow to generate a PDF using iText and an Apache Velocity template file (.vm) in Java?
I am interested in knowing steps like: parse template file, put Java object in context and steps to be performed to generate pdf etc.
I know this is a very basic question. But I am not able to find even a single example of this type on the web. I found XDocReport, but I am interested to know other alternatives as well.
Please help me with some sample project link or at least the steps to get started.
Yes, you can.
It all depends on how complex you want the PDFs to be.
Here are the steps for basic functionality
Generate a HTML file using Apache Velocity template file (.vm).
Use com.itextpdf.text.html.simpleparser.HTMLWorker (deprecated) to parse/convert that HTML file into a PDF.
Additionally, you can use com.itextpdf.text.pdf.PdfCopy.PageStamp to add content (borders, stamps, notes, annotations etc) to an existing PDF.
There is also com.itextpdf.tool.xml.XMLWorker for more advanced HTML conversion (adding style sheets etc)
Generating PDF using iText and an Apache Velocity template file (.vm) in Java directly is not possible because:
PDF is binary format,
Velocity generates plain text content.
On other words, Velocity cannot generate PDF.
XDocReport is able to generate a docx/odt report by merging a docx/odt template which contains some Velocity/Freemarker syntax with Java context. The generated docx/odt report can be convert it to pdf/xhtml.
It works because docx/odt are a zip which contains several xml entries. If you unzip a docx you will see word/document.xml. In this entry, you will see the content that you have typed with MS Word. word/document.xml is a plain text, so Velocity can be used in this case.
Here the XDocReport process to generate pdf from a docx template which uses Velocity:
Load docx template. this step consist to unzip the docx and stores in a map each xml entries (name entry as key and byte array as value). For instance map contains a key with word/document.xml and the xml content of this entry as value.
Loop for each xml entries which must be merged with Java context. For instance word/document.xml is merged with Java context by using Velocity and the result of merge replace the word/document.xml value of the map
Rebuild a new docx by zipping each entries of the map.
At this step we have a generated docx (the report).
To convert it to another format, XDocReport provides a docx-to-pdf converter based on Apache POI and iText. Here the XDocReport process to convert a docx to pdf:
Load docx with Apache POI
Loop for each structures of POI (XWPFParagraph, etc.) to create iText structure (iText Paragraph).
Note that XDocReport is modular and you can use other converters as well.
At first,we use freemarker template to generate a html file,and then render html to a pdf file by IItextRender .Finally, we can view pdf file in browser,there has a very useful javascript tools called pdfjs. Maybe you can try it.

Java api for pdf

Which APIs in java help in extracting table metadata from a pdf, and presenting that table in a web page?
The result should be that when the source of page is viewed it will show the html code of that table.
Itext is usefull in this context
http://itextpdf.com/
I assume that, you need a PDF library for Java.
PDFBox is one of the popular libraries created to PDF manipulation and I think it is worth to look at it.
try The Metadata Extract Tool which extracts metadata from specific file types including PDF. Then you can parse the xml output with any Java XML parser. Once you're able to parse it, elements can be easily laid down in your view page.

Categories

Resources