You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Glenn Brand <gb...@odprofessional.com> on 2008/01/24 10:40:58 UTC
Need conversion from .20 to .94 for HTML to PDF conversion
I am converting from HTML to XSL-FO and then to fop. If anybody has a
good way to do this I would like to know.
How do I convert the following fo2PDF method .20 fop calls to .94 fop
calls?
private static byte[] fo2PDF(Document foDocument) {
DocumentInputSource fopInputSource = new DocumentInputSource(
foDocument);
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Logger log = new ConsoleLogger(ConsoleLogger.LEVEL_WARN);
Driver driver = new Driver(fopInputSource, out);
driver.setLogger(log);
driver.setRenderer(Driver.RENDER_PDF);
driver.run();
return out.toByteArray();
} catch (Exception ex) {
return null;
}
}
public static void main(String[] args) {
// open file
if (args.length != 2) {
System.out.println("Usage: Html2Pdf htmlFile
styleSheet");
System.exit(1);
}
FileInputStream input = null;
String htmlFileName = args[0];
try {
input = new
FileInputStream(htmlFileName);
}
catch (java.io.FileNotFoundException e) {
System.out.println("File not found: " +
htmlFileName);
}
Tidy tidy = new Tidy();
Document xmlDoc = tidy.parseDOM(input, null);
Document foDoc = xml2FO(xmlDoc, args[1]);
String pdfFileName = htmlFileName.substring(0,
htmlFileName.indexOf(".")) + ".pdf";
String xslFileName = htmlFileName.substring(0,
htmlFileName.indexOf(".")) + ".fo";
writeXmlFile(foDoc,xslFileName);
try {
OutputStream pdf = new FileOutputStream(new
File(pdfFileName));
OutputStream xsl = new FileOutputStream(new
File(xslFileName));
pdf.write(fo2PDF(foDoc));
}
catch (java.io.FileNotFoundException e) {
System.out.println("Error creating PDF: " +
pdfFileName);
}
catch (java.io.IOException e) {
System.out.println("Error writing PDF: " +
pdfFileName);
}
}
/*
* Applies stylesheet to input.
*
* @param xml The xml input Document
*
* @param stylesheet Name of the stylesheet
*
* @return Document Result of the transform
*/
private static Document xml2FO(Document xml, String styleSheet) {
DOMSource xmlDomSource = new DOMSource(xml);
DOMResult domResult = new DOMResult();
Transformer transformer = getTransformer(styleSheet);
if (transformer == null) {
System.out.println("Error creating transformer for "
+ styleSheet);
System.exit(1);
}
try {
transformer.transform(xmlDomSource, domResult);
}
catch (javax.xml.transform.TransformerException e) {
return null;
}
return (Document) domResult.getNode();
}
Re: Need conversion from .20 to .94 for HTML to PDF conversion
Posted by Andreas Delmelle <an...@telenet.be>.
On Jan 24, 2008, at 10:40, Glenn Brand wrote:
> I am converting from HTML to XSL-FO and then to fop. If anybody has
> a good way to do this I would like to know.
>
> How do I convert the following fo2PDF method .20 fop calls to .94
> fop calls?
Maybe I've missed someone's reply on this, but on my side this post
still appeared unanswered.
This may have its reasons, mind you... ;-)
Seriously, browse around some on the FOP website, until you end up on:
http://xmlgraphics.apache.org/fop/0.94/embedding.html
This should get you started with the conversion. If you run into any
particular issues, just yell.
HTH!
Cheers
Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
RE: Need conversion from .20 to .94 for HTML to PDF conversion
Posted by Glenn Brand <gb...@odprofessional.com>.
Thanks Andreas, I will take a look.
-----Original Message-----
From: Andreas Delmelle [mailto:adelmelle@apache.org]
Sent: January 24, 2008 11:05 AM
To: fop-users@xmlgraphics.apache.org
Subject: Re: Need conversion from .20 to .94 for HTML to PDF conversion
On Jan 24, 2008, at 10:40, Glenn Brand wrote:
Hi
> I am converting from HTML to XSL-FO and then to fop. If anybody has
> a good way to do this I would like to know.
>
> How do I convert the following fo2PDF method .20 fop calls to .94
> fop calls?
>
Maybe I've missed someone's reply on this, but on my side this post
still appeared unanswered.
This may have its reasons, mind you... ;-)
Seriously, browse around some on the FOP website, until you end up on:
http://xmlgraphics.apache.org/fop/0.94/embedding.html
This should get you started with the conversion. If you run into any
particular issues, just yell.
HTH!
Cheers
Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
Re: Need conversion from .20 to .94 for HTML to PDF conversion
Posted by Andreas Delmelle <ad...@apache.org>.
On Jan 24, 2008, at 10:40, Glenn Brand wrote:
Hi
> I am converting from HTML to XSL-FO and then to fop. If anybody has
> a good way to do this I would like to know.
>
> How do I convert the following fo2PDF method .20 fop calls to .94
> fop calls?
>
Maybe I've missed someone's reply on this, but on my side this post
still appeared unanswered.
This may have its reasons, mind you... ;-)
Seriously, browse around some on the FOP website, until you end up on:
http://xmlgraphics.apache.org/fop/0.94/embedding.html
This should get you started with the conversion. If you run into any
particular issues, just yell.
HTH!
Cheers
Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org