Skip to content

Commit

Permalink
PDF A mode disabling added, metanorma/metanorma-plateau#121
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelligent2013 committed Nov 2, 2024
1 parent 5ad4b3c commit 3b47d3d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SHELL ?= /bin/bash
endif

#JAR_VERSION := $(shell mvn -q -Dexec.executable="echo" -Dexec.args='$${project.version}' --non-recursive exec:exec -DforceStdout)
JAR_VERSION := 2.07
JAR_VERSION := 2.08
JAR_FILE := mn2pdf-$(JAR_VERSION).jar

all: target/$(JAR_FILE)
Expand Down
10 changes: 5 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ You will need the Java Development Kit (JDK) version 8, Update 241 (8u241) or hi

[source,sh]
----
java -Xss5m -Xmx2048m -jar target/mn2pdf-2.07.jar --xml-file <XML-FileName> --xsl-file <XSLT-FileName> --pdf-file <Output-PDF-FileName> [--syntax-highlight]
java -Xss5m -Xmx2048m -jar target/mn2pdf-2.08.jar --xml-file <XML-FileName> --xsl-file <XSLT-FileName> --pdf-file <Output-PDF-FileName> [--syntax-highlight]
----

e.g.

[source,sh]
----
java -Xss5m -Xmx2048m -jar target/mn2pdf-2.07.jar --xml-file tests/G.191.xml --xsl-file tests/itu.recommendation.xsl --pdf-file tests/G.191.pdf
java -Xss5m -Xmx2048m -jar target/mn2pdf-2.08.jar --xml-file tests/G.191.xml --xsl-file tests/itu.recommendation.xsl --pdf-file tests/G.191.pdf
----

=== PDF encryption features
Expand Down Expand Up @@ -100,7 +100,7 @@ Update version in `pom.xml`, e.g.:
----
<groupId>org.metanorma.fop</groupId>
<artifactId>mn2pdf</artifactId>
<version>2.07</version>
<version>2.08</version>
<name>Metanorma XML to PDF converter</name>
----

Expand All @@ -111,8 +111,8 @@ Tag the same version in Git:

[source,xml]
----
git tag v2.07
git push origin v2.07
git tag v2.08
git push origin v2.08
----

Then the corresponding GitHub release will be automatically created at:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.metanorma.fop</groupId>
<artifactId>mn2pdf</artifactId>
<version>2.07</version>
<version>2.08</version>
<name>Metanorma XML to PDF converter</name>
<packaging>jar</packaging>
<url>https://www.metanorma.org</url>
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/org/metanorma/fop/PDFGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ public class PDFGenerator {
int pageCount = 0;

boolean PDFUA_error = false;


boolean PDFUA_enabled = true;
boolean PDFA_enabled = true;

private String debugXSLFO = "";

public void setFontsPath(String fontsPath) {
Expand Down Expand Up @@ -486,18 +489,23 @@ private void convertmn2pdf(fontConfig fontcfg, XSLTconverter xsltConverter, File
runFOP(fontcfg, src, pdf);

if(PDFUA_error) {
logger.info("WARNING: Trying to generate PDF in non PDF/UA-1 mode.");
logger.warning("WARNING: Trying to generate PDF in non " + PDF_UA_MODE + " and non " + PDF_A_MODE + " modes.");
fontcfg.setPDFUAmode("DISABLED");
PDFUA_enabled = false;
PDFA_enabled = false;
src = new StreamSource(new StringReader(xmlFO));
runFOP(fontcfg, src, pdf);
logger.info(WARNING_NONPDFUA);
logger.warning(WARNING_NONPDFUA);
}

// validate PDF by veraPDF
VeraPDFValidator veraPDFValidator = new VeraPDFValidator();
veraPDFValidator.validate(pdf, PDF_A_MODE);
veraPDFValidator.validate(pdf, PDF_UA_MODE);

if (PDFA_enabled) {
veraPDFValidator.validate(pdf, PDF_A_MODE);
}
if (PDFUA_enabled) {
veraPDFValidator.validate(pdf, PDF_UA_MODE);
}

fontcfg.printMessages();

Expand Down Expand Up @@ -591,7 +599,9 @@ private void runFOP (fontConfig fontcfg, Source src, File pdf) throws IOExceptio
foUserAgent.setProducer("Ribose Metanorma mn2pdf version " + Util.getAppVersion());

if (encryptionParams.isEmpty()) {
foUserAgent.getRendererOptions().put("pdf-a-mode", PDF_A_MODE);
if (PDFA_enabled) {
foUserAgent.getRendererOptions().put("pdf-a-mode", PDF_A_MODE);
}
} else {
logger.severe("PDF/A doesn't allow encrypted PDFs. PDF will be generated in non-PDF/A mode.");
}
Expand Down

0 comments on commit 3b47d3d

Please sign in to comment.