urgent help with pdf rendering
- Hello I have been able to successfully render a pdf from a specified
xsl and xml file. However only the static information within the pdf
is shown. I am suspicious that maybe the xml is empty. Can someone
please verfiy that the following code is correct, specifically the
line: byte xmlSrc = xml.getBytes();. I think that this might be
causing the problem. If it is how can I convert the string to a
byte and then convert that byte to a StreamSource?
This is quite urgent. I hope someone can help and thank you in
The code is below:
public byte print(String xsl, String xml)
String xslSrc = xsl;
byte xmlSrc = xml.getBytes();
for (int i = 0; i < xmlSrc.length; i++)
com.hp.nimius.util.trace.Trace.debug("xmlSrc from FopToPDF is:
" + xmlSrc);
byte pdfResult = null;
int renderType = getRenderType("pdf");
//Construct a Driver
Driver driver = new Driver();
//Setup Renderer (output format)
//Render the xslt/xml to create a fo file and pipe through
StringBuffer fo = renderXSL(xslSrc, xmlSrc);
//Render the FO file with FOP
pdfResult = renderFOP(fo, renderType);
catch (Exception ex)
System.err.println("*** exception in PrinterFOP: " +
* call the FOP parser to render a fo to a printout
* @param fo java.lang.StringBuffer
* @param renderType int
* @return byte
private byte renderFOP(StringBuffer fo, int renderType) throws
ByteArrayOutputStream out = new ByteArrayOutputStream();
StringReader inReader = null;
inReader = new StringReader(fo.toString());
InputSource in = new InputSource(inReader);
Driver driver = new Driver(in, out);
if (inReader != null)
* render a XML against an xslFile to create a fo file to be later
* render PDF.
* @param xmlFile java.lang.String
* @param xslFile java.lang.String
* @return StringBuffer
public StringBuffer renderXSL(String xslFile, byte xmlFile)
TransformerConfigurationException, JBSException, Exception
StringWriter outWriter = new StringWriter();
StreamSource xslResult = new StreamSource(xslFile);
StreamSource xmlSource = new StreamSource(new
TransformerFactory tFactory =
Transformer transformer = tFactory.newTransformer(xslResult);
transformer.transform(xmlSource, new StreamResult(outWriter));
>From: "soken78" <soken78@...>What XSL-FO formatter are you using?
>Hello I have been able to successfully render a pdf from a specified
>xsl and xml file.
>However only the static information within the pdfTo convert string to byte array use the getBytes() method on String.
>is shown. I am suspicious that maybe the xml is empty. Can someone
>please verfiy that the following code is correct, specifically the
>line: byte xmlSrc = xml.getBytes();. I think that this might be
>causing the problem. If it is how can I convert the string to a
>byte and then convert that byte to a StreamSource?
StreamSource takes InputStream as argument to its contructor, so create a
ByteArrayInputStream based on your byte array, e.g.
new StreamSource(new ByteArrayInputStream(yourString.getBytes()));
>This is quite urgent. I hope someone can help and thank you in
I had a quick look at your code and noticed that you don't close the output
stream in your renderFOP method. You need to close the ByteArrayOutputStream
to ensure all data is flushed to the array.
The problem could also be in your stylesheet, post small snippets of your
XSL and XML files if you still have no luck.
Use MSN Messenger to send music and pics to your friends