PDF Generation form HTML using ITextRenderer - java

I am using ITextRenderer to generate PDF from html. However I am getting following exception:
Error Can't load the XML resource (using TRaX transformer). org.xml.sax.SAXParseException: Content is not allowed in prolog.
Could you please help me?
Any help will be appreciated.
Thanks in advance.

It is probably caused by lack of encoding declaration in your xml file
XML file header: <?xml version='1.0' encoding='utf-8'?>
You should have something like this ( or other encoding type ) at the very top of your xml file.
OR
You do not escape special characters

You haven't mentioned that in which programming language you are working.
I am assuming that you are doing this in Java.
writeNextDocument() lets you render multiple X/HTML documents onto the
same PDF. It doesn't let you paste PDFs together. The error comes
from the XML parser trying to parse the PDF document as an XML
document. The easiest way to do what you want is to render the X/HTML
to a PDF with FS and then use iText directly to paste them together
(Google will turn up examples of this).
https://code.google.com/p/flying-saucer/wiki/FAQPDF#How_can_I_print_multiple_pages_on_to_one_PDF,_if_they_come_from_multiple_documents

Related

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

Support for external CSS file from Apache FOP PDF Generation

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

Jsoup XML parse from File

I need to transform an XML file to parse XML in Jsoup.
I have an XML file that the way it is now, is to parse HTML and not XML.
Anyone know a way?
In HTML, the jsoup works very well, I have no idea how to include a file and use XML Parse this file.
Anyone know how to do, because the site Jsoup not think anything related to XML or XML file conversion.
Thank you.
You should use a proper XML parser such as JDom instead of Jsoup, which is, as you say, an HTML parser.

how to convert xml to html and send it to fax machine with images ?

I have an XML file. I have to read the contents of this xml file and put it in html format and send it to fax with some images in java.
I cannot edit the xml file. not even to link it to the XSLT.
any ideas how i can achieve this ?
Thanks for your help in advance.
You can use a Transformer to apply arbitrary XSLT to a document (XML or otherwise) using java. Actual examples abound on this site and the rest of the internet.
As for the FAXing part, there are a lot of interesting hits on google for "java fax".

How to add metadata to html file

I am using Apache Tika to convert RTF documents to HTML.
In Tika's RTFParser class I made changes to generate HTML file using HTMLEditorKit and now I'm able to generate the HTML file.
I want to add the metadata tags into the head tag of the generated HTML file.
Can anybody give me an idea to how to proceed?
Check this out:
Add Metadata
I'm not sure that this will help, but I think it is worth to check out.

Categories

Resources