java - Apache FOP generating blank page -
i trying generate pdf using apache fop , java. using valid xsl-fo file can create pdf using command line fop.
my problem occurs when try run fop using apache fop libraries. running across java/php bridge. bride configured , java / php communicate. on java side have function takes in string containing xsl-fo , returns string contains pdf. when execute function , redirect output stdout file, or across java / php bridge, pdf appears blank , size double of correct pdf retrieve via command line. assume having kind of encoding problem.
has seen issue before?
here java code
public string convertfotopdf(string fo) { // contain results after transformation. bytearrayoutputstream out = new bytearrayoutputstream(); // input string stringreader sr = new stringreader(fo); // should utf-8; string strencoding = charset.defaultcharset().name(); // resulting string. string pdfresult = ""; try { // instance of fop factory fopfactory fopfactory = fopfactory.newinstance(); fouseragent fouseragent = fopfactory.newfouseragent(); // construct fop desired output format fop fop = fopfactory.newfop(mimeconstants.mime_pdf, fouseragent, out); // setup jaxp using identity transformer transformerfactory factory = transformerfactory.newinstance(); transformer transformer = factory.newtransformer(); // setup input stream source src = new streamsource(sr); // resulting sax events (the generated fo) must piped through fop result res = new saxresult(fop.getdefaulthandler()); // set encoding on transformer. transformer.setoutputproperty(outputkeys.encoding, strencoding); // start xslt transformation , fop processing transformer.transform(src, res); // put byte array stream string pdfresult = out.tostring(strencoding); } // catch exceptions simplicities sake. catch (exception e){ // log } return pdfresult; }
Comments
Post a Comment