metanorma / mn2pdf

Metanorma XML to PDF
3 stars 2 forks source link

Error: Cannot change the version of this PDF document. #205

Closed Intelligent2013 closed 1 year ago

Intelligent2013 commented 1 year ago

Errors occurs with updated mn2pdf for PDF version 1.7 (mn2pdf not released yet) for JIS document:

Cannot change the version of this PDF document.
java.lang.IllegalStateException: Cannot change the version of this PDF document.
    at org.apache.fop.pdf.VersionController$FixedVersion.setPDFVersion(VersionController.java:73)
    at org.apache.fop.pdf.PDFDocument.setPDFVersion(PDFDocument.java:250)
    at org.apache.fop.pdf.PDFFactory.makeFontFile(PDFFactory.java:1401)
    at org.apache.fop.pdf.PDFFactory.makeFontDescriptor(PDFFactory.java:1328)
    at org.apache.fop.pdf.PDFFactory.makeFont(PDFFactory.java:968)
    at org.apache.fop.pdf.PDFResources.addFonts(PDFResources.java:137)
    at org.apache.fop.render.pdf.PDFDocumentHandler.endDocument(PDFDocumentHandler.java:186)
    at org.apache.fop.render.intermediate.util.IFDocumentHandlerProxy.endDocument(IFDocumentHandlerProxy.java:187)
    at org.apache.fop.render.intermediate.IFParser$Handler$DocumentHandler.endElement(IFParser.java:458)
    at org.apache.fop.render.intermediate.IFParser$Handler.endElement(IFParser.java:413)
    at org.apache.xalan.transformer.TransformerIdentityImpl.endElement(TransformerIdentityImpl.java:1102)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:610)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1784)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2969)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:113)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:507)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:867)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:796)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:142)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216)
    at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:485)
    at org.metanorma.fop.PDFGenerator.runFOP(PDFGenerator.java:558)
    at org.metanorma.fop.PDFGenerator.convertmn2pdf(PDFGenerator.java:445)
    at org.metanorma.fop.PDFGenerator.process(PDFGenerator.java:306)
    at org.metanorma.fop.mn2pdf.main(mn2pdf.java:345)
Intelligent2013 commented 1 year ago

The issue occurs in VersionController class: image

The version 1.6 sets in the PDFFactory:

if (font.getEmbeddingMode() == EmbeddingMode.FULL) {
    fontBytes = reader.getAllBytes();
    if (isCFF) {
            //Ensure version 1.6 for full OTF CFF embedding
            document.setPDFVersion(Version.V1_6);
    }
Intelligent2013 commented 1 year ago

Issue fixed.