[
https://issues.apache.org/jira/browse/FOP-3137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17867286#comment-17867286
]
Rafael Witak commented on FOP-3137:
-----------------------------------
Argh, of course, that's right. Now this approach also produces the IOException.
For completeness, here's my method:
{code:java}
// App.java
public static void main(String[] args) throws IOException, SAXException {
try {
// Setup directories and files
File baseDir = new File(".");
File outDir = new File(baseDir, "out");
outDir.mkdirs();
File xmlfile = new File(baseDir, "empty.xml"); // just contains <empty/>
File xsltfile = new File(baseDir, "fo.xsl");
File configfile = new File(baseDir, "fop.xconf");
final FopFactory fopFactory = FopFactory.newInstance(configfile);
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
File pdffile = new File(outDir, "test.pdf");
try (OutputStream out = new
BufferedOutputStream(Files.newOutputStream(pdffile.toPath()))) {
// Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent,
out);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new
StreamSource(xsltfile));
// Setup input for XSLT transformation
Source src = new StreamSource(xmlfile);
// Resulting SAX events (the generated FO) must be piped through to
FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res);
}
} catch (Exception e) {
e.printStackTrace(System.err);
System.exit(-1);
}
} {code}
And the fo.xsl:
{code:java}
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-portrait"
page-height="29.7cm" page-width="21.0cm"
margin="2cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fox:external-document
src="url('file:///C:\Users\***\***\FOP-Test\original.pdf')" />
</fo:root>
</xsl:template>
</xsl:stylesheet> {code}
The fop.xconf is just the standard one with the addition of
{{<form-xobject>true</form-xobject>}} under {{<renderer
mime="application/pdf">}}
> PDF Images - external-document layout broken
> --------------------------------------------
>
> Key: FOP-3137
> URL: https://issues.apache.org/jira/browse/FOP-3137
> Project: FOP
> Issue Type: Bug
> Environment: Windows 10.0.19045 Build 19045
> Java 17
> FOP 2.8
> PDF Images 2.8
> Reporter: Rafael Witak
> Priority: Major
> Attachments: image-2023-07-13-16-46-26-626.png,
> image-2023-07-13-16-47-09-093.png, older.pdf, original.pdf, output.pdf
>
>
> When including the PDFs of one of our customers, the layout gets messed up,
> turning this:
> !image-2023-07-13-16-47-09-093.png|width=349,height=265!
> into this:
> !image-2023-07-13-16-46-26-626.png|width=350,height=284!
>
> The customer recently switched to PDF 1.7, all of their PDFs get messed up
> ever since.
> There are no FOP events in the log, checking the resulting PDF with _pdfcpu_
> validates perfectly, even with strict mode on.
> Setting strict-validation in the renderer also doesn't produce any errors.
> The problem happens regardless of the version of FOP and fop-pdf-images used.
> The FO input for reproduction can be reduced to
> {{<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"}}
> {{xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">}}
> {{ <fo:layout-master-set>}}
> {{ <fo:simple-page-master master-name="simple">}}
> {{ <fo:region-body/>}}
> {{ </fo:simple-page-master>}}
> {{ </fo:layout-master-set>}}
> {{ <fox:external-document src="PDF/input.pdf" />}}
> {{{}</fo:root>{}}}{{{}{}}}
>
> Various problems regarding layouts are mentioned in the "Known Issues".
> There is also the general statement _"Apache FOP currently generates PDF 1.4.
> If you include a PDF with a higher PDF version, the results may be
> unpredictable."_ to be found (That said, setting different versions in the
> renderer did not solve the problem).
> Please let me know, if this is out of scope for the project - and if it is,
> please provide me with any workarounds you might know of!
>
> (Included are one of the originals together with its output, as well as an
> older PDF of the same customer which works as expected. )
--
This message was sent by Atlassian Jira
(v8.20.10#820010)