RE: Problem that could lose me my job
OK I think I have sorted out the image url issue now when I run the pdf it shows the following warnings 2012-02-08 09:37:39,131 [pool-1-thread-1] WARN uk.co.inbrand.fopengine.FopEngine - Before Instantiation 2012-02-08 09:37:39,156 [pool-1-thread-1] WARN uk.co.inbrand.fopengine.FopEngine - After Instantiation 2012-02-08 09:37:54,758 [pool-1-thread-2] WARN org.apache.fop.apps.FOUserAgent - Line 1 of a paragraph overflows the available area by 11339 millipoints. (See position 51:11) 2012-02-08 09:37:54,768 [pool-1-thread-2] WARN org.apache.fop.apps.FOUserAgent - Content overflows the viewport of an fo:block-container in block-progression direction by 17123 millipoints. (See position 50:90) 2012-02-08 09:37:54,794 [pool-1-thread-2] WARN org.apache.fop.apps.FOUserAgent - Content overflows the viewport of an fo:block-container in block-progression direction by 5784 millipoints. (See position 637:92) 2012-02-08 09:37:57,192 [pool-1-thread-2] WARN org.apache.fop.apps.FOUserAgent - Line 1 of a paragraph overflows the available area by 11339 millipoints. (See position 682:11) 2012-02-08 09:37:57,193 [pool-1-thread-2] WARN org.apache.fop.apps.FOUserAgent - Content overflows the viewport of an fo:block-container in block-progression direction by 17123 millipoints. (See position 681:91) 2012-02-08 09:37:57,487 [pool-1-thread-2] WARN org.apache.fop.apps.FOUserAgent - Line 1 of a paragraph overflows the available area by 11339 millipoints. (See position 1358:11) 2012-02-08 09:37:57,488 [pool-1-thread-2] WARN org.apache.fop.apps.FOUserAgent - Content overflows the viewport of an fo:block-container in block-progression direction by 17123 millipoints. (See position 1357:91) But it is still not creating a valid PDF I am getting image errors in the info log still where it can’t find an importer or convertor. What jars do I need for jpg files? I have batik and XMLGraphics-Commons-1.4 Is there any other jar I need – like JAI? And if so what are the maven dependencies I need? Kindest regards Theresa Forster Senior Software Developer From: Craig Ringer [mailto:ring...@ringerc.id.au] Sent: 08 February 2012 03:56 To: fop-users@xmlgraphics.apache.org Cc: Luis Ferro Subject: Re: Problem that could lose me my job On 08/02/12 03:23, Luis Ferro wrote: Hmmm... why not installing those files in a local webserver? That way you would have a proper uri (http://localhost/etc...) file:/// file:///\\ is a proper URI, it's just not a URL. Fop only requires resolvable URIs and doesn't really care where they come from. Using HTTP would add transfer overhead and slow things down for little if any benefit. I don't really see the point, when fixing the URI syntax to conform to correct file URI syntax is all that's required here. -- Craig Ringer
Re: Problem that could lose me my job
On 08/02/2012 09:51, Theresa Jayne Forster wrote: Hi Theresa, But it is still not creating a valid PDF I am getting image errors in the info log still where it can’t find an importer or convertor. What jars do I need for jpg files? I have batik and XMLGraphics-Commons-1.4 Is there any other jar I need – like JAI? And if so what are the maven dependencies I need? FOP needs jai-imageio.jar for most image formats. Add that to your classpath to fix the errors about no preloader found. Chris Kindest regards Theresa Forster Senior Software Developer *From:*Craig Ringer [mailto:ring...@ringerc.id.au] *Sent:* 08 February 2012 03:56 *To:* fop-users@xmlgraphics.apache.org *Cc:* Luis Ferro *Subject:* Re: Problem that could lose me my job On 08/02/12 03:23, Luis Ferro wrote: Hmmm... why not installing those files in a local webserver? That way you would have a proper uri (http://localhost/etc...) file:/// file:///%5C%5C is a proper URI, it's just not a URL. Fop only requires resolvable URIs and doesn't really care where they come from. Using HTTP would add transfer overhead and slow things down for little if any benefit. I don't really see the point, when fixing the URI syntax to conform to correct file URI syntax is all that's required here. -- Craig Ringer - To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
Re: Problem that could lose me my job
On 8/02/2012 5:51 PM, Theresa Jayne Forster wrote: OK I think I have sorted out the image url issue now when I run the pdf it shows the following warnings [snip] But it is still not creating a valid PDF I am getting image errors in the info log still where it can’t find an importer or convertor. What jars do I need for jpg files? You show the other, unrelated errors but NOT the errors that are causing you problems. Why? Is there any other jar I need – like JAI? And if so what are the maven dependencies I need? If you're using Maven, everything should be pulled in for you unless you've explicitly excluded the appropriate dependencies or overridden their versions. -- Craig Ringer
RE: Problem that could lose me my job
Thank you for all your time guys, I was being a clutz, Unbeknown to me all ERRORS were being pushed into a separate file - (I didn't put together the log.properties ) In the error log I am getting an exception as below. So it is having problems getting the images, so at least I have somewhere to look 2012-02-03 15:20:41,503 [pool-1-thread-2] ERROR org.apache.fop.apps.FopFactory - Attempt to resolve URI 'C:\InBrand\preprocessor\filestore\img3525450795559698480.jpg' failed: javax.xml.transform.TransformerException: Error with URL; base 'file:/C:/InBrand/preprocessor/filestore/' href 'C:\InBrand\preprocessor\filestore\img3525450795559698480.jpg' at org.apache.fop.apps.FOURIResolver.handleException(FOURIResolver.java:141) at org.apache.fop.apps.FOURIResolver.resolve(FOURIResolver.java:272) at org.apache.fop.apps.FopFactory.resolveURI(FopFactory.java:753) at org.apache.fop.apps.FOUserAgent.resolveURI(FOUserAgent.java:425) at org.apache.fop.apps.FOUserAgent.resolveURI(FOUserAgent.java:398) at org.apache.fop.apps.FOUserAgent$1.resolveURI(FOUserAgent.java:141) at org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.newSour ce(AbstractImageSessionContext.java:77) at org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.needSou rce(AbstractImageSessionContext.java:280) at org.apache.xmlgraphics.image.loader.cache.ImageCache.needImageInfo(ImageCach e.java:123) at org.apache.xmlgraphics.image.loader.ImageManager.getImageInfo(ImageManager.j ava:122) at org.apache.fop.fo.flow.ExternalGraphic.bind(ExternalGraphic.java:81) at org.apache.fop.fo.FObj.processNode(FObj.java:123) at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.jav a:282) at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171) at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(Transforme rIdentityImpl.java:1072) at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source) at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatc her.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerId entityImpl.java:484) at uk.co.inbrand.fopengine.FopEngine.generatePDFromFO(FopEngine.java:197) at uk.co.inbrand.fopengine.FopProcessor.run(FopProcessor.java:50) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.ja va:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:9 08) at java.lang.Thread.run(Thread.java:619) Caused by: java.net.MalformedURLException: unknown protocol: c at java.net.URL.init(URL.java:574) at java.net.URL.init(URL.java:464) at org.apache.fop.apps.FOURIResolver.resolve(FOURIResolver.java:270) ... 28 more - java.net.MalformedURLException: unknown protocol: c at java.net.URL.init(URL.java:574) at java.net.URL.init(URL.java:464) at org.apache.fop.apps.FOURIResolver.resolve(FOURIResolver.java:270) at org.apache.fop.apps.FopFactory.resolveURI(FopFactory.java:753) at org.apache.fop.apps.FOUserAgent.resolveURI(FOUserAgent.java:425) at org.apache.fop.apps.FOUserAgent.resolveURI(FOUserAgent.java:398) at org.apache.fop.apps.FOUserAgent$1.resolveURI(FOUserAgent.java:141) at org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.newSour ce(AbstractImageSessionContext.java:77) at org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.needSou rce(AbstractImageSessionContext.java:280) at org.apache.xmlgraphics.image.loader.cache.ImageCache.needImageInfo(ImageCach e.java:123) at org.apache.xmlgraphics.image.loader.ImageManager.getImageInfo(ImageManager.j ava:122) at
Re: Problem that could lose me my job
On Tue, 7 Feb 2012, Rob Sargent wrote: Still looks to me as though your image handling is amiss. What image loaders have you defined? Are they available in deployment? All assuming the fixed (DOS?) paths are correct. I think it's more straightforward than that. The URL is invalid. Theresa, did you try fixing the urls? file:/C:/InBrand/preprocessor/filestore/ should be file://C:/InBrand/preprocessor/filestore/ (two slashes). The message java.net.MalformedURLException: unknown protocol: c leads me to think you also have bare DOS paths in there, they also should be file://c:/... And for heaven's sake, dump windows. Steve On Feb 7, 2012, at 3:09 AM, Theresa Jayne Forster ther...@inbrand.co.uk wrote: Thank you for all your time guys, I was being a clutz, Unbeknown to me all ERRORS were being pushed into a separate file ? (I didn?t put together the log.properties ) In the error log I am getting an exception as below. So it is having problems getting the images, so at least I have somewhere to look 2012-02-03 15:20:41,503 [pool-1-thread-2] ERROR org.apache.fop.apps.FopFactory - Attempt to resolve URI 'C:\InBrand\preprocessor\filestore\img3525450795559698480.jpg' failed: javax.xml.transform.TransformerException: Error with URL; base 'file:/C:/InBrand/preprocessor/filestore/' href 'C:\InBrand\preprocessor\filestore\img3525450795559698480.jpg' at org.apache.fop.apps.FOURIResolver.handleException(FOURIResolver.java:141) at org.apache.fop.apps.FOURIResolver.resolve(FOURIResolver.java:272) at org.apache.fop.apps.FopFactory.resolveURI(FopFactory.java:753) at org.apache.fop.apps.FOUserAgent.resolveURI(FOUserAgent.java:425) at org.apache.fop.apps.FOUserAgent.resolveURI(FOUserAgent.java:398) at org.apache.fop.apps.FOUserAgent$1.resolveURI(FOUserAgent.java:141) at org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.newSource(AbstractImageSessionContext.java:77) at org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.needSource(AbstractImageSessionContext.java:280) at org.apache.xmlgraphics.image.loader.cache.ImageCache.needImageInfo(ImageCache.java:123) at org.apache.xmlgraphics.image.loader.ImageManager.getImageInfo(ImageManager.java:122) at org.apache.fop.fo.flow.ExternalGraphic.bind(ExternalGraphic.java:81) at org.apache.fop.fo.FObj.processNode(FObj.java:123) at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:282) at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171) at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072) at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source) at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484) at uk.co.inbrand.fopengine.FopEngine.generatePDFromFO(FopEngine.java:197) at uk.co.inbrand.fopengine.FopProcessor.run(FopProcessor.java:50) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Caused by: java.net.MalformedURLException: unknown protocol: c at java.net.URL.init(URL.java:574) at java.net.URL.init(URL.java:464) at org.apache.fop.apps.FOURIResolver.resolve(FOURIResolver.java:270) ... 28 more - java.net.MalformedURLException: unknown protocol: c
Re: Problem that could lose me my job
On 08/02/12 03:23, Luis Ferro wrote: Hmmm... why not installing those files in a local webserver? That way you would have a proper uri (http://localhost/etc...) file:/// is a proper URI, it's just not a URL. Fop only requires resolvable URIs and doesn't really care where they come from. Using HTTP would add transfer overhead and slow things down for little if any benefit. I don't really see the point, when fixing the URI syntax to conform to correct file URI syntax is all that's required here. -- Craig Ringer
Problem that could lose me my job
I have just come across a problem that may lose me my job unless I can resolve it. 1. I am using Fop-1.0 2. I create PDFs and then view them in Sumatra PDF - perfectly fine 3. Try to open the same file in Adobe Acrobat - it reports that the file is corrupt and cannot be repaired.. Help please. Kindest regards Theresa Forster Senior Software Developer
Re: Problem that could lose me my job
On 3/02/2012 8:14 PM, Theresa Jayne Forster wrote: I have just come across a problem that may lose me my job unless I can resolve it. 1.I am using Fop-1.0 2.I create PDFs and then view them in Sumatra PDF -- perfectly fine 3.Try to open the same file in Adobe Acrobat -- it reports that the file is corrupt and cannot be repaired.. As a senior software developer, I'm sure you're aware that reports like this really need to be accompanied by details like: - Sample files or reliable procedures for generating them; - Sample input used to generate the problem files; - Information about your environment (Java and OS version etc); - Details about fonts, configuration, etc; and - if at all possible a self-contained test case. -- Craig Ringer
RE: Problem that could lose me my job
Sorry, I was under pressure to roll back the servers that we had just upgraded to use the fop 1.0 system. One of the failing PDFs is at http://www.inbrand1.co.uk/failsinadobe.pdf The FO that generated it is at http://www.inbrand1.co.uk/failsinadobe.fo The fopconfig has nothing except font configurations in it. A couple have kerning xml files as they produce incorrectly without. The routine that produces the PDF is as follows public File generatePDFromFO(File foFile) { OutputStream ot = null; BufferedOutputStream out = null; File tempFile = null; try { tempFile = File.createTempFile(W2P, .pdf); out = new BufferedOutputStream( new FileOutputStream(tempFile)); fopFactory.setStrictValidation(false); DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder(); Configuration cfg = cfgBuilder.buildFromFile(new File(/fopconfig.xml)); fopFactory.setUserConfig(cfg); FOUserAgent useragent= fopFactory.newFOUserAgent(); useragent.setTargetResolution(300); Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,useragent,out); TransformerFactory factory = TransformerFactory.newInstance(); Source src = new StreamSource(foFile); Transformer transformer = factory.newTransformer(); Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, res); } catch (IOException ioe) { LOGGER.error(IOException ,ioe); ioe.printStackTrace(); } catch (SAXException se) { LOGGER.error(Sax Exception ,se); se.printStackTrace(); } catch (ConfigurationException ce) { LOGGER.error(Configuration Exception ,ce); ce.printStackTrace(); } catch (TransformerConfigurationException tce) { LOGGER.error(Transformer Configuration Exception,tce); tce.printStackTrace(); } catch (TransformerException te) { LOGGER.error(Transformer Exception ,te); te.printStackTrace(); } return tempFile; } Fop config file here fop xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; strict-configurationtrue/strict-configuration baseC:\preprocessor\filestore\/base font-base/Fonts/font-base cache-file/fop-cache/cache-file !-- Add fonts here -- renderers renderer mime=application/pdf fonts font embed-url=FRUTL___.TTF kerning=yes metrics-url=FrutigerLight.xml font-triplet name=Frutiger style=normal weight=200/ /font font embed-url=FRUTB___.TTF kerning=yes font-triplet name=Frutiger style=normal weight=400/ /font font embed-url=tfarrow-medium.TTF font-triplet name=TFArrow style=normal weight=400/ /font font embed-url=HELVNBL_.TTF font-triplet name=HelveticaNeue style=normal weight=900/ /font font embed-url=helveticaneue_85hv.ttf font-triplet name=HelveticaNeue style=normal weight=800/ /font font embed-url=HELVNBI_.TTF font-triplet name=HelveticaNeue style=italic weight=700/ /font font embed-url=HELVNM__.TTF font-triplet name=HelveticaNeue style=normal weight=500/ /font font embed-url=HELVNI__.TTF font-triplet name=HelveticaNeue style=italic weight=400/ /font font embed-url=lte50259.ttf font-triplet name=HelveticaNeue style=normal weight=400/ font-triplet name=HelveticaNeue style=roman weight=400/
Re: Problem that could lose me my job
Hi, you should read FOP trace (from stdin or stderr). This reveals what is wrong in your XSL-FO: FOP throws a lot of exceptions, that prevent it to generate any PDF. At least, your app should report you if PDF has been generated or not. Le 03/02/2012 14:32, Theresa Jayne Forster a écrit : Why would that make the output PDF invalid to Adobe and not to Sumatra pdf? Kindest regards Theresa Forster Hi, I've just opened the FO file in oXygen, and it throws up a number of errors: @ margin-top not allowed in fo:region-start @ z-index not allowed in fo:region-body @ z-index not allowed in fo:region-before @ z-index not allowed in fo:region-after ... about 20 or so in the fo:simple-page-master section HTH David Sorry, I was under pressure to roll back the servers that we had just upgraded to use the fop 1.0 system. One of the failing PDFs is at http://www.inbrand1.co.uk/failsinadobe.pdf The FO that generated it is at http://www.inbrand1.co.uk/failsinadobe.fo The fopconfig has nothing except font configurations in it. A couple have kerning xml files as they produce incorrectly without. The routine that produces the PDF is as follows public File generatePDFromFO(File foFile) { OutputStream ot = null; BufferedOutputStream out = null; File tempFile = null; try { tempFile = File.createTempFile(W2P, .pdf); out = new BufferedOutputStream( new FileOutputStream(tempFile)); fopFactory.setStrictValidation(false); DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder(); Configuration cfg = cfgBuilder.buildFromFile(new File(/fopconfig.xml)); fopFactory.setUserConfig(cfg); FOUserAgent useragent= fopFactory.newFOUserAgent(); useragent.setTargetResolution(300); Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,useragent,out); TransformerFactory factory = TransformerFactory.newInstance(); Source src = new StreamSource(foFile); Transformer transformer = factory.newTransformer(); Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, res); } catch (IOException ioe) { LOGGER.error(IOException ,ioe); ioe.printStackTrace(); } catch (SAXException se) { LOGGER.error(Sax Exception ,se); se.printStackTrace(); } catch (ConfigurationException ce) { LOGGER.error(Configuration Exception ,ce); ce.printStackTrace(); } catch (TransformerConfigurationException tce) { LOGGER.error(Transformer Configuration Exception,tce); tce.printStackTrace(); } catch (TransformerException te) { LOGGER.error(Transformer Exception ,te); te.printStackTrace(); } return tempFile; } Fop config file here fop xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; strict-configurationtrue/strict-configuration baseC:\preprocessor\filestore\/base font-base/Fonts/font-base cache-file/fop-cache/cache-file !-- Add fonts here -- renderers renderer mime=application/pdf fonts font embed-url=FRUTL___.TTF kerning=yes metrics-url=FrutigerLight.xml font-triplet name=Frutiger style=normal weight=200/ /font font embed-url=FRUTB___.TTF kerning=yes font-triplet name=Frutiger style=normal weight=400/ /font font embed-url=tfarrow-medium.TTF font-triplet name=TFArrow style=normal weight=400/ /font font embed-url=HELVNBL_.TTF font-triplet name=HelveticaNeue
Re: Problem that could lose me my job
On 3/02/2012 8:58 PM, Theresa Jayne Forster wrote: Sorry, I was under pressure to roll back the servers that we had just upgraded to use the fop 1.0 system. One of the failing PDFs is at http://www.inbrand1.co.uk/failsinadobe.pdf The FO that generated it is at http://www.inbrand1.co.uk/failsinadobe.fo Adobe (or even Adobe Acrobat or Adobe Reader) can be a lot of different things. Versions are important. That said, the PDF is clearly broken. Adobe Reader X fails with There was an error opening this document. The file is damaged and could not be repaired. It isn't handled by Chrome either. Re David's comment about the XSL-FO being non-confirming: If fop produces a broken PDF silently and without error output that is a fop bug, even if it's triggered by bad XSL-FO input. A warning should be emitted if valid PDF can be produced - though possibly not displaying how the author intended - but if no valid PDF can be produced that surely must be a fatal error. I know you're not actually saying it's *not* a fop bug, just being clear that IMO bad FO - bad PDF *is* a fop bug. However, looking at your code below, I see little reason to believe this is a fop bug. All you've shown so far is that your code ignores errors if fop does tell you about them. Have you looked at your application's error logs to see if fop is throwing an exception and if so, what? That's the only place you'll see errors since your code otherwise ignores them: } catch (IOException ioe) { LOGGER.error(IOException ,ioe); ioe.printStackTrace(); } catch (SAXException se) { LOGGER.error(Sax Exception ,se); se.printStackTrace(); } catch (ConfigurationException ce) { LOGGER.error(Configuration Exception ,ce); ce.printStackTrace(); } catch (TransformerConfigurationException tce) { LOGGER.error(Transformer Configuration Exception,tce); tce.printStackTrace(); } catch (TransformerException te) { LOGGER.error(Transformer Exception ,te); te.printStackTrace(); } return tempFile; ... that's some interesting error handling code. LOGGER clearly doesn't throw another (wrapping) exception since otherwise `te.printStackTrace()' would never be getting executed. That means your code is logging an error (two different ways) then IGNORING IT. Not only is that error handling code rather skeezy, but you assign a value to tempFile early on and do not clear it when an error occurs, so you MAY RETURN A HALF-WRITTEN GARBAGE FILE TO THE CALLER if an error occurs. I strongly advise you to fix your error handling code and re-test. There are at least a few bugs in that code: - After some errors you may return a handle to an incompletely written temp file without any indication it's broken - You don't close your file handle(s) or streams, so you're relying on the objects' finialisation to do it for you when the gc gets around to cleaning them up. This is not usually a good idea. You really need to be using try{}finally{} blocks to clean up resources like this. Try correcting your error handling code and seeing if the problem changes. Please also send any messages fop 1.0 logs with detailed logging enabled when it is producing the faulty PDF. I'm sure you've looked at the logs as part of basic first-step troubleshooting anyway, so you should have no problem bringing them to hand... Here's a 30-second quickly hacked out version of how I'd want to tweak this. I haven't tested this code and don't claim I'm any expert, I'm just sure it's closer than what you're using right now: // Of course you'd use your app's real exception classes instead of this demo // scratch code public class MyApplicationRuntimeException extends RuntimeException { public MyApplicationRuntimeException(Throwable err) { super(err); } public MyApplicationRuntimeException(String msg) { super(msg); } public MyApplicationRuntimeException(String msg, Throwable err) { super(msg,err); } } public File generatePDFromFO(File foFile) { File tempFile = File.createTempFile(W2P, .pdf); try { fopFactory.setStrictValidation(false); // -- This is a **HINT** you're doing something **WRONG** DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder(); Configuration cfg = cfgBuilder.buildFromFile(new File(/fopconfig.xml)); // -- You're reparsing and re-applying the config for each file?!? fopFactory.setUserConfig(cfg); FOUserAgent useragent = fopFactory.newFOUserAgent(); useragent.setTargetResolution(300); TransformerFactory factory = TransformerFactory.newInstance(); BufferedOutputSteam out = new BufferedOutputStream(new FileOutputStream(tempFile)); try { Fop fop
RE: Problem that could lose me my job
The stacktraces were added to allow me to quickly debug without trapesing through the mega log that log4J is spewing out from the whole system (I know its wrong hell I cringe whenever I see some of the code but it is based on the old system just upgraded for Fop 1.0 as the old system was 0.23 with a handful of custom addons like accepting font-weight=bold and z-index=2 to using a bare 1.0 Kindest regards Theresa Forster Senior Software Developer From: Craig Ringer [mailto:ring...@ringerc.id.au] Sent: 03 February 2012 14:00 To: fop-users@xmlgraphics.apache.org Cc: Theresa Jayne Forster Subject: Re: Problem that could lose me my job On 3/02/2012 8:58 PM, Theresa Jayne Forster wrote: Sorry, I was under pressure to roll back the servers that we had just upgraded to use the fop 1.0 system. One of the failing PDFs is at http://www.inbrand1.co.uk/failsinadobe.pdf The FO that generated it is at http://www.inbrand1.co.uk/failsinadobe.fo Adobe (or even Adobe Acrobat or Adobe Reader) can be a lot of different things. Versions are important. That said, the PDF is clearly broken. Adobe Reader X fails with There was an error opening this document. The file is damaged and could not be repaired. It isn't handled by Chrome either. Re David's comment about the XSL-FO being non-confirming: If fop produces a broken PDF silently and without error output that is a fop bug, even if it's triggered by bad XSL-FO input. A warning should be emitted if valid PDF can be produced - though possibly not displaying how the author intended - but if no valid PDF can be produced that surely must be a fatal error. I know you're not actually saying it's *not* a fop bug, just being clear that IMO bad FO - bad PDF *is* a fop bug. However, looking at your code below, I see little reason to believe this is a fop bug. All you've shown so far is that your code ignores errors if fop does tell you about them. Have you looked at your application's error logs to see if fop is throwing an exception and if so, what? That's the only place you'll see errors since your code otherwise ignores them: } catch (IOException ioe) { LOGGER.error(IOException ,ioe); ioe.printStackTrace(); } catch (SAXException se) { LOGGER.error(Sax Exception ,se); se.printStackTrace(); } catch (ConfigurationException ce) { LOGGER.error(Configuration Exception ,ce); ce.printStackTrace(); } catch (TransformerConfigurationException tce) { LOGGER.error(Transformer Configuration Exception,tce); tce.printStackTrace(); } catch (TransformerException te) { LOGGER.error(Transformer Exception ,te); te.printStackTrace(); } return tempFile; ... that's some interesting error handling code. LOGGER clearly doesn't throw another (wrapping) exception since otherwise `te.printStackTrace()' would never be getting executed. That means your code is logging an error (two different ways) then IGNORING IT. Not only is that error handling code rather skeezy, but you assign a value to tempFile early on and do not clear it when an error occurs, so you MAY RETURN A HALF-WRITTEN GARBAGE FILE TO THE CALLER if an error occurs. I strongly advise you to fix your error handling code and re-test. There are at least a few bugs in that code: - After some errors you may return a handle to an incompletely written temp file without any indication it's broken - You don't close your file handle(s) or streams, so you're relying on the objects' finialisation to do it for you when the gc gets around to cleaning them up. This is not usually a good idea. You really need to be using try{}finally{} blocks to clean up resources like this. Try correcting your error handling code and seeing if the problem changes. Please also send any messages fop 1.0 logs with detailed logging enabled when it is producing the faulty PDF. I'm sure you've looked at the logs as part of basic first-step troubleshooting anyway, so you should have no problem bringing them to hand... Here's a 30-second quickly hacked out version of how I'd want to tweak this. I haven't tested this code and don't claim I'm any expert, I'm just sure it's closer than what you're using right now: // Of course you'd use your app's real exception classes instead of this demo // scratch code public class MyApplicationRuntimeException extends RuntimeException { public MyApplicationRuntimeException(Throwable err) { super(err); } public MyApplicationRuntimeException(String msg) { super(msg); } public MyApplicationRuntimeException(String msg, Throwable err) { super(msg,err); } } public File generatePDFromFO(File foFile) { File tempFile = File.createTempFile(W2P, .pdf); try { fopFactory.setStrictValidation(false); // -- This is a **HINT** you're doing something
RE: Problem that could lose me my job
Ok Checked the deletion code, it doesnt appear to be that , I stopped that part happening but the pdf is still ending up corrupt for adobe and Foxit (but still valid with no errors on Sumatra PDF) Kindest regards Theresa Forster Senior Software Developer -Original Message- From: Theresa Jayne Forster [mailto:ther...@inbrand.co.uk] Sent: 03 February 2012 14:06 To: fop-users@xmlgraphics.apache.org Subject: RE: Problem that could lose me my job Ok I have put the complete log for the generation on a gist as it is Way to big to post here https://gist.github.com/1730300 I will check the code I have that sends the pdf to the client then check it is flushing and completing before deleting the file to prevent clutter Maybe I need to change my fileisreadystrategy Thanks for the heads up there at least it gives me somewhere to look. Kindest regards Theresa Forster Senior Software Developer -Original Message- From: mehdi houshmand [mailto:med1...@gmail.com] Sent: 03 February 2012 13:51 To: fop-users@xmlgraphics.apache.org Subject: Re: Problem that could lose me my job Hi Theresa, The PDF you put up isn't complete, it's as if FOP stopped creating the document for some reason. Was an exception thrown? Would there be any reason why FOP wouldn't finish writing to file? If so, I'd suggest you try FOP trunk as well to see if the same problem arises, if so, then the stacktrace should give an indication as to what is causing the problem. Mehdi On 3 February 2012 13:32, Theresa Jayne Forster ther...@inbrand.co.uk wrote: Why would that make the output PDF invalid to Adobe and not to Sumatra pdf? Kindest regards Theresa Forster Senior Software Developer From: David J. B. Hollis [mailto:dhol...@aandoconsultancy.ltd.uk] Sent: 03 February 2012 13:19 To: fop-users@xmlgraphics.apache.org Subject: Re: Problem that could lose me my job Hi, I've just opened the FO file in oXygen, and it throws up a number of errors: @ margin-top not allowed in fo:region-start @ z-index not allowed in fo:region-body @ z-index not allowed in fo:region-before @ z-index not allowed in fo:region-after ... about 20 or so in the fo:simple-page-master section HTH David Sorry, I was under pressure to roll back the servers that we had just upgraded to use the fop 1.0 system. One of the failing PDFs is at http://www.inbrand1.co.uk/failsinadobe.pdf The FO that generated it is at http://www.inbrand1.co.uk/failsinadobe.fo The fopconfig has nothing except font configurations in it. A couple have kerning xml files as they produce incorrectly without. The routine that produces the PDF is as follows public File generatePDFromFO(File foFile) { OutputStream ot = null; BufferedOutputStream out = null; File tempFile = null; try { tempFile = File.createTempFile(W2P, .pdf); out = new BufferedOutputStream( new FileOutputStream(tempFile)); fopFactory.setStrictValidation(false); DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder(); Configuration cfg = cfgBuilder.buildFromFile(new File(/fopconfig.xml)); fopFactory.setUserConfig(cfg); FOUserAgent useragent= fopFactory.newFOUserAgent(); useragent.setTargetResolution(300); Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,useragent,out); TransformerFactory factory = TransformerFactory.newInstance(); Source src = new StreamSource(foFile); Transformer transformer = factory.newTransformer(); Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, res); } catch (IOException ioe) { LOGGER.error(IOException ,ioe); ioe.printStackTrace(); } catch (SAXException se) { LOGGER.error(Sax Exception ,se); se.printStackTrace(); } catch (ConfigurationException ce) { LOGGER.error(Configuration Exception ,ce); ce.printStackTrace(); } catch (TransformerConfigurationException tce) { LOGGER.error(Transformer Configuration Exception,tce); tce.printStackTrace(); } catch (TransformerException te) { LOGGER.error(Transformer Exception ,te); te.printStackTrace(); } return tempFile; } Fop config file here fop xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; strict-configurationtrue/strict-configuration baseC:\preprocessor\filestore\/base font-base/Fonts/font-base cache-file/fop-cache/cache-file !-- Add fonts here
RE: Problem that could lose me my job
UPDATE: Tried on 0.95-1 and 0.95 (the latter needed the Avalon framework adding manually to the pom) Still does not work, any suggestions why I am getting a pdf that works in a 3rd party viewer and not in adobe. Kindest regards Theresa Forster Senior Software Developer -Original Message- From: Theresa Jayne Forster [mailto:ther...@inbrand.co.uk] Sent: 03 February 2012 14:44 To: fop-users@xmlgraphics.apache.org Subject: RE: Problem that could lose me my job Ok Checked the deletion code, it doesnt appear to be that , I stopped that part happening but the pdf is still ending up corrupt for adobe and Foxit (but still valid with no errors on Sumatra PDF) Kindest regards Theresa Forster Senior Software Developer -Original Message- From: Theresa Jayne Forster [mailto:ther...@inbrand.co.uk] Sent: 03 February 2012 14:06 To: fop-users@xmlgraphics.apache.org Subject: RE: Problem that could lose me my job Ok I have put the complete log for the generation on a gist as it is Way to big to post here https://gist.github.com/1730300 I will check the code I have that sends the pdf to the client then check it is flushing and completing before deleting the file to prevent clutter Maybe I need to change my fileisreadystrategy Thanks for the heads up there at least it gives me somewhere to look. Kindest regards Theresa Forster Senior Software Developer -Original Message- From: mehdi houshmand [mailto:med1...@gmail.com] Sent: 03 February 2012 13:51 To: fop-users@xmlgraphics.apache.org Subject: Re: Problem that could lose me my job Hi Theresa, The PDF you put up isn't complete, it's as if FOP stopped creating the document for some reason. Was an exception thrown? Would there be any reason why FOP wouldn't finish writing to file? If so, I'd suggest you try FOP trunk as well to see if the same problem arises, if so, then the stacktrace should give an indication as to what is causing the problem. Mehdi On 3 February 2012 13:32, Theresa Jayne Forster ther...@inbrand.co.uk wrote: Why would that make the output PDF invalid to Adobe and not to Sumatra pdf? Kindest regards Theresa Forster Senior Software Developer From: David J. B. Hollis [mailto:dhol...@aandoconsultancy.ltd.uk] Sent: 03 February 2012 13:19 To: fop-users@xmlgraphics.apache.org Subject: Re: Problem that could lose me my job Hi, I've just opened the FO file in oXygen, and it throws up a number of errors: @ margin-top not allowed in fo:region-start @ z-index not allowed in fo:region-body @ z-index not allowed in fo:region-before @ z-index not allowed in fo:region-after ... about 20 or so in the fo:simple-page-master section HTH David Sorry, I was under pressure to roll back the servers that we had just upgraded to use the fop 1.0 system. One of the failing PDFs is at http://www.inbrand1.co.uk/failsinadobe.pdf The FO that generated it is at http://www.inbrand1.co.uk/failsinadobe.fo The fopconfig has nothing except font configurations in it. A couple have kerning xml files as they produce incorrectly without. The routine that produces the PDF is as follows public File generatePDFromFO(File foFile) { OutputStream ot = null; BufferedOutputStream out = null; File tempFile = null; try { tempFile = File.createTempFile(W2P, .pdf); out = new BufferedOutputStream( new FileOutputStream(tempFile)); fopFactory.setStrictValidation(false); DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder(); Configuration cfg = cfgBuilder.buildFromFile(new File(/fopconfig.xml)); fopFactory.setUserConfig(cfg); FOUserAgent useragent= fopFactory.newFOUserAgent(); useragent.setTargetResolution(300); Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,useragent,out); TransformerFactory factory = TransformerFactory.newInstance(); Source src = new StreamSource(foFile); Transformer transformer = factory.newTransformer(); Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, res); } catch (IOException ioe) { LOGGER.error(IOException ,ioe); ioe.printStackTrace(); } catch (SAXException se) { LOGGER.error(Sax Exception ,se); se.printStackTrace(); } catch (ConfigurationException ce) { LOGGER.error(Configuration Exception ,ce); ce.printStackTrace(); } catch (TransformerConfigurationException tce) { LOGGER.error(Transformer Configuration Exception,tce); tce.printStackTrace(); } catch (TransformerException te) { LOGGER.error(Transformer Exception ,te); te.printStackTrace(); } return tempFile
Re: Problem that could lose me my job
On 3/02/2012 10:13 PM, Theresa Jayne Forster wrote: The stacktraces were added to allow me to quickly debug without trapesing through the mega log that log4J is spewing out from the whole system (I know its wrong hell I cringe whenever I see some of the code but it is based on the old system just upgraded for Fop 1.0 as the old system was 0.23 with a handful of custom addons like accepting font-weight=bold and z-index=2 to using a bare 1.0 OK, but either way you're still ignoring the exceptions. That was just as wrong before the printStackTrace calls were added as it is now. UPDATE: Tried on 0.95-1 and 0.95 (the latter needed the Avalon framework adding manually to the pom) Still does not work, any suggestions why I am getting a pdf that works in a 3rd party viewer and not in adobe. Because you are getting an incomplete, damaged PDF. Some viewers manage to cope with it, others do not. When I open the file in a hex editor (or a decent text editor) I can see that it ends at an `endobj', not with a proper xref dictionary and trailer. What *should* be happening is that when fop hits whatever error prevents it from finishing generating the PDF it throws an exception. Your app should catch that exception, delete the temporary file, and rethrow the exception or handle it within your app's error handling and reporting framework. Logging and ignoring the exception is *incorrect*. You have still not confirmed whether or not fop is throwing an exception when generating this file. Please confirm whether fop actually throws an exception when generating this file. If fop *does not *throw an exception, there is a fop bug. If fop *does *throw an exception, there is a bug in your code. -- Craig Ringer