Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.38
JAR_VERSION := 2.39
JAR_FILE := mn2pdf-$(JAR_VERSION).jar

all: target/$(JAR_FILE)
Expand Down
12 changes: 6 additions & 6 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.38.jar --xml-file <XML-FileName> --xsl-file <XSLT-FileName> --pdf-file <Output-PDF-FileName> [--syntax-highlight]
java -Xss5m -Xmx2048m -jar target/mn2pdf-2.39.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.38.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.39.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 @@ -108,15 +108,15 @@ Update version in `pom.xml`, e.g.:
----
<groupId>org.metanorma.fop</groupId>
<artifactId>mn2pdf</artifactId>
<version>2.38</version>
<version>2.39</version>
<name>Metanorma XML to PDF converter</name>
----

and in `src/main/resources/META-INF/MANIFEST.MF`:

[source]
----
Implementation-Version: 2.38
Implementation-Version: 2.39
----


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

[source,xml]
----
git tag v2.38
git push origin v2.38
git tag v2.39
git push origin v2.39
----

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.38</version>
<version>2.39</version>
<name>Metanorma XML to PDF converter</name>
<packaging>jar</packaging>
<url>https://www.metanorma.org</url>
Expand Down
46 changes: 41 additions & 5 deletions src/main/java/org/metanorma/fop/PDFGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@
import org.metanorma.fop.annotations.FileAttachmentAnnotation;
import org.metanorma.fop.eventlistener.LoggingEventListener;
import org.metanorma.fop.eventlistener.SecondPassSysOutEventListener;
import org.metanorma.fop.ifhandler.FOPIFFlatHandler;
import org.metanorma.fop.ifhandler.FOPIFHiddenMathHandler;
import org.metanorma.fop.ifhandler.FOPIFIndexHandler;
import org.metanorma.fop.ifhandler.FOPXMLPresentationHandler;
import org.metanorma.fop.form.FormItem;
import org.metanorma.fop.form.PDFForm;
import org.metanorma.fop.ifhandler.*;
import org.metanorma.fop.portfolio.PDFMetainfo;
import org.metanorma.fop.portfolio.PDFPortfolio;
import org.metanorma.fop.portfolio.PDFPortfolioItem;
Expand Down Expand Up @@ -109,6 +108,10 @@ public class PDFGenerator {
private boolean isAddLineNumbers = false;

private boolean isAddCommentaryPageNumbers = false;

private boolean isAddForms = false;

private List<FormItem> formsItems = new ArrayList<>();

private boolean isAddMathAsAttachment = false;

Expand Down Expand Up @@ -369,6 +372,7 @@ public boolean process() {
isAddAnnotations = sourceXMLDocument.hasAnnotations();
isAddFileAttachmentAnnotations = sourceXMLDocument.hasFileAttachmentAnnotations();
isTableExists = sourceXMLDocument.hasTables();
isAddForms = sourceXMLDocument.hasForms();
boolean isMathExists = sourceXMLDocument.hasMath();

XSLTconverter xsltConverter = new XSLTconverter(fXSL, fXSLoverride, sourceXMLDocument.getPreprocessXSLT(), fPDF.getAbsolutePath());
Expand Down Expand Up @@ -772,7 +776,11 @@ private void runFOP (fontConfig fontcfg, Source src, File pdf) throws IOExceptio

String mime = MimeConstants.MIME_PDF;

boolean isPostprocessing = isAddMathAsText || isAddAnnotations || isAddLineNumbers || isAddCommentaryPageNumbers;
boolean isPostprocessing = isAddMathAsText ||
isAddAnnotations ||
isAddLineNumbers ||
isAddCommentaryPageNumbers ||
isAddForms;

if (isPostprocessing) {
logger.info("Starting post-processing...");
Expand Down Expand Up @@ -815,6 +823,23 @@ private void runFOP (fontConfig fontcfg, Source src, File pdf) throws IOExceptio
debugSaveXML(xmlIF, pdf.getAbsolutePath() + ".if.commentarypagenumbers.xml");
}

if (isAddForms) {
logger.info("Read Forms information from Intermediate Format...");


SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
FOPIFFormsHandler fopIFFormsHandler = new FOPIFFormsHandler();
InputSource srcIntermediateXML = new InputSource(new StringReader(xmlIF));
saxParser.parse(srcIntermediateXML, fopIFFormsHandler);

//String xmlIFForm = applyXSLT("forms_if.xsl", xmlIF, true);

xmlIF = fopIFFormsHandler.getResultedXML();
formsItems = fopIFFormsHandler.getFormsItems();

debugSaveXML(xmlIF, pdf.getAbsolutePath() + ".if.forms.xml");
}

src = new StreamSource(new StringReader(xmlIF));
}
Expand Down Expand Up @@ -972,6 +997,17 @@ private void runFOP (fontConfig fontcfg, Source src, File pdf) throws IOExceptio
}
}

if (isAddForms && !formsItems.isEmpty()) {
logger.log(Level.INFO, "[INFO] Forms processing...");
try {
PDFForm forms = new PDFForm();
forms.process(pdf, formsItems);
} catch (Exception ex) {
logger.severe("Can't process forms (" + ex.toString() + ").");
ex.printStackTrace();
}
}

Profiler.printProcessingTime(methodName, startMethodTime);
Profiler.removeMethodCall();
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/metanorma/fop/SourceXMLDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class SourceXMLDocument {
private boolean hasAnnotations = false;
private boolean hasFileAttachmentAnnotations = false;
private boolean hasTables = false;
private boolean hasForms = false;
private Map<String, Integer> tablesCellsCountMap = new HashMap<>();
private boolean hasMath = false;

Expand Down Expand Up @@ -108,6 +109,8 @@ private void readMetaInformation() {
//hasTables = element_table.length() != 0;
obtainTablesCellsCount();
hasTables = !tablesCellsCountMap.isEmpty();
String element_form = readValue("//*[local-name() = 'form'][1]");
hasForms = element_form.length() != 0;
}

private void obtainTablesCellsCount() {
Expand Down Expand Up @@ -506,6 +509,11 @@ public boolean hasTables() {
return hasTables;
}

// find tag 'form'
public boolean hasForms() {
return hasForms;
}

public boolean hasMath() {
return hasMath;
}
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/org/metanorma/fop/form/FormItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.metanorma.fop.form;

import org.apache.pdfbox.pdmodel.common.PDRectangle;

public class FormItem {

PDRectangle rect ;// = new PDRectangle(50, 750, 200, 50);

int page;

FormItemType formItemType;

public FormItem(PDRectangle rect, int page) {
this.rect = rect;
this.page = page;
}

public PDRectangle getRect() {
return rect;
}

public FormItemType getFormItemType() {
return formItemType;
}

public int getPage() {
return page;
}

public void setFormItemType(String formItemType) {
switch (formItemType) {
case "textfield":
this.formItemType = FormItemType.TextField;
break;
default:
this.formItemType = FormItemType.TextField;
break;
}

}
}
7 changes: 7 additions & 0 deletions src/main/java/org/metanorma/fop/form/FormItemType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.metanorma.fop.form;

public enum FormItemType {
TextField,
CheckBox,
}

Loading
Loading