Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- fj-doc-mod-fop, make accessibility and keep empty tags parameters configurable <https://github.com/fugerit-org/fj-doc/issues/508>

## [8.16.2] - 2025-09-12

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@

Whereas the link:https://github.com/fugerit-org/fj-doc/blob/main/CHANGELOG.md[CHANGELOG] is a detailed list of modifications to project, the release notes just refer to the most important changes.

[#doc-release-notes-unreleased]
==== Unreleased

- fj-doc-mod-fop, make accessibility and keep empty tags parameters configurable link:https://github.com/fugerit-org/fj-doc/issues/508[#508]

[#doc-release-notes-8-16-2]
==== Version 8.16.2 [2025-09-12]

- fj-doc-maven-plugin, updated all flavours version link:https://github.com/fugerit-org/fj-doc/issues/498[#498]

[#doc-release-notes-8-16-1]
==== Version 8.16.1 [2025-09-01]

- fj-doc-maven-plugin, updated all flavours version link:https://github.com/fugerit-org/fj-doc/issues/494[#494]

[#doc-release-notes-8-16-0]
==== Version 8.16.0 [2025-08-22]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ For this DocHandler it is possible to customize some attributes, for instance :
| *pdf-ua-mode* anchor:doc-handler-mod-fop-pdf-config-pdf-ua-mode[] | _string_ | | If present, will set pdf-ua-mode, possible values are : _PDF/UA-1_. link:https://github.com/fugerit-org/fj-doc/issues/52[Partially compatible with pdf-a-mode].
| *fop-pool-min* anchor:doc-handler-mod-fop-pdf-config-fop-pool-min[] | _int_ | 0 | If present, it will create a fo user agent pool, this is the minimum size of the pool.
| *fop-pool-max* anchor:doc-handler-mod-fop-pdf-config-fop-pool-max[] | _int_ | 0 | If present, it will create a fo user agent pool, this is the maximum size fo the pool.
| *accessibility* anchor:doc-handler-mod-fop-pdf-config-accessibility[] | _bool_ | true | fopUserAgent.setAccessibility($value); (since 8.16.3)
| *keep-empty-tags* anchor:doc-handler-mod-fop-pdf-config-keep-empty-tags[] | _bool_ | false | fopUserAgent.setKeepEmptyTags($value); (since 8.16.3)
|========================================================================================================================================

NOTE: If *pdf-a-mode* is set, there will be a strict validation of the PDF (i.e. it will be checked if the font are all embedded and the images should comply to link:https://www.adobe.com/uk/acrobat/resources/document-files/pdf-types/pdf-a.html[PDF/A standard]).

TIP: Setting accessibility to 'false' will produce a smaller but less accessible PDF.

[#doc-handler-mod-fop-pdf-config-pdf-a]
==== PDF/A DocHandler

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

[#doc-faq-reducing-fj-doc-mod-fop-pdf-size]
=== Reducing fj-doc-mod-fop PDF size

Module fj-doc-mod-fop is based on link:https://xmlgraphics.apache.org/fop/[Apache FOP].

Sometimes this module can produce relatively big size PF.

Here are some tips to reduce the size.

==== Accessibility

By default, fop user agent has the accessibility flag active.

Since Venus version 8.16.3 it is possible to use the new handler :

[source,java]
----
org.fugerit.java.doc.mod.fop.PdfFopTypeNoAccessibilityHandler
----

Which as the accessibility flag set to 'false' by default.

Alternatively, it is possible to use a new configuration option :

[source,xml]
----
<docHandler id="pdf-fop-config" info="pdf" type="org.fugerit.java.doc.mod.fop.PdfFopTypeHandler">
<docHandlerCustomConfig charset="UTF-8" accessibility='false'/>
</docHandler>
----

Refer to xref:#doc-handler-mod-fop-pdf-config-accessibility[PDF/FO DocHandler] documentation for further info.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ public class PdfFopTypeHandler extends FreeMarkerFopTypeHandler {

private static final String ATT_FONT_BASE_CLASSLOADER_PATH = "font-base-classloader-path"; // removed as of v2.0.1

public static final String ATT_ACCESSIBILITY = "accessibility";
public static final boolean DEFAULT_ACCESSIBILITY = true;

public static final String ATT_KEEP_EMPTY_TAGS = "keep-empty-tags";
public static final boolean DEFAULT_KEEP_EMPTY_TAGS = false;

public static final String ATT_FOP_SUPPRESS_EVENTS = "fop-suppress-events";
Expand Down Expand Up @@ -242,6 +244,8 @@ protected void handleConfigTag(Element config) throws ConfigException {
this.setSuppressEvents( BooleanUtils.isTrue( props.getProperty( ATT_FOP_SUPPRESS_EVENTS ) ) );
// setup pool
this.setupPool( props );
// extra setup
this.extraSetup( props );
}

private void setupPool( Properties props ) throws ConfigException {
Expand All @@ -260,6 +264,19 @@ private void setupPool( Properties props ) throws ConfigException {
}
}

private void extraSetup( Properties props ) throws ConfigException {
String valueAccessibility = props.getProperty( ATT_ACCESSIBILITY );
if ( StringUtils.isNotEmpty( valueAccessibility ) ) {
log.debug( "override accessibility {} -> {}", this.isAccessibility(), valueAccessibility );
this.accessibility = BooleanUtils.isTrue( valueAccessibility );
}
String valueKeepEnptyTags = props.getProperty( ATT_KEEP_EMPTY_TAGS);
if ( StringUtils.isNotEmpty( valueKeepEnptyTags ) ) {
log.debug( "override keep-empty-tags {} -> {}", this.isKeepEmptyTags(), valueKeepEnptyTags );
this.keepEmptyTags = BooleanUtils.isTrue( valueKeepEnptyTags );
}
}

private void setupFopConfigMode( String fopConfigMode, String fopConfigResoverType, String fopConfigClassloaderPath, Element config ) throws ConfigException {
if ( ATT_FOP_CONFIG_MODE_CLASS_LOADER.equalsIgnoreCase( fopConfigMode ) ) {
ConfigException.apply( () -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.fugerit.java.doc.mod.fop;

public class PdfFopTypeNoAccessibilityHandler extends PdfFopTypeHandler {

public PdfFopTypeNoAccessibilityHandler() {
super( Boolean.FALSE, DEFAULT_KEEP_EMPTY_TAGS );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,126 @@
"name" : "wait",
"parameterTypes" : [ "long", "int" ]
} ]
}, {
"name" : "org.fugerit.java.doc.mod.fop.PdfFopTypeNoAccessibilityHandler",
"methods" : [ {
"name" : "<init>",
"parameterTypes" : [ ]
}, {
"name" : "configure",
"parameterTypes" : [ "java.util.Properties" ]
}, {
"name" : "configure",
"parameterTypes" : [ "org.w3c.dom.Element" ]
}, {
"name" : "configureProperties",
"parameterTypes" : [ "java.io.InputStream" ]
}, {
"name" : "configureXML",
"parameterTypes" : [ "java.io.InputStream" ]
}, {
"name" : "createKey",
"parameterTypes" : [ "java.lang.String", "java.lang.String" ]
}, {
"name" : "equals",
"parameterTypes" : [ "java.lang.Object" ]
}, {
"name" : "getCharset",
"parameterTypes" : [ ]
}, {
"name" : "getClass",
"parameterTypes" : [ ]
}, {
"name" : "getCustomId",
"parameterTypes" : [ ]
}, {
"name" : "getFopConfig",
"parameterTypes" : [ ]
}, {
"name" : "getFopPoolMax",
"parameterTypes" : [ ]
}, {
"name" : "getFopPoolMin",
"parameterTypes" : [ ]
}, {
"name" : "getFormat",
"parameterTypes" : [ ]
}, {
"name" : "getKey",
"parameterTypes" : [ ]
}, {
"name" : "getKey",
"parameterTypes" : [ ]
}, {
"name" : "getMime",
"parameterTypes" : [ ]
}, {
"name" : "getModule",
"parameterTypes" : [ ]
}, {
"name" : "getPdfAMode",
"parameterTypes" : [ ]
}, {
"name" : "getPdfUAMode",
"parameterTypes" : [ ]
}, {
"name" : "getType",
"parameterTypes" : [ ]
}, {
"name" : "handle",
"parameterTypes" : [ "org.fugerit.java.doc.base.config.DocInput", "org.fugerit.java.doc.base.config.DocOutput" ]
}, {
"name" : "hashCode",
"parameterTypes" : [ ]
}, {
"name" : "isAccessibility",
"parameterTypes" : [ ]
}, {
"name" : "isKeepEmptyTags",
"parameterTypes" : [ ]
}, {
"name" : "isSuppressEvents",
"parameterTypes" : [ ]
}, {
"name" : "notify",
"parameterTypes" : [ ]
}, {
"name" : "notifyAll",
"parameterTypes" : [ ]
}, {
"name" : "setCustomId",
"parameterTypes" : [ "java.lang.String" ]
}, {
"name" : "setFopConfig",
"parameterTypes" : [ "org.fugerit.java.doc.mod.fop.FopConfig" ]
}, {
"name" : "setFopPoolMax",
"parameterTypes" : [ "int" ]
}, {
"name" : "setFopPoolMin",
"parameterTypes" : [ "int" ]
}, {
"name" : "setPdfAMode",
"parameterTypes" : [ "java.lang.String" ]
}, {
"name" : "setPdfUAMode",
"parameterTypes" : [ "java.lang.String" ]
}, {
"name" : "setSuppressEvents",
"parameterTypes" : [ "boolean" ]
}, {
"name" : "toString",
"parameterTypes" : [ ]
}, {
"name" : "wait",
"parameterTypes" : [ ]
}, {
"name" : "wait",
"parameterTypes" : [ "long" ]
}, {
"name" : "wait",
"parameterTypes" : [ "long", "int" ]
} ]
}, {
"name" : "org.fugerit.java.doc.mod.fop.PoolUtils",
"methods" : [ {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package test.org.fugerit.java.doc.mod.fop;

import lombok.extern.slf4j.Slf4j;
import org.fugerit.java.core.function.SafeFunction;
import org.fugerit.java.core.lang.helpers.ClassHelper;
import org.fugerit.java.core.xml.dom.DOMIO;
import org.fugerit.java.doc.base.config.DocInput;
import org.fugerit.java.doc.base.config.DocOutput;
import org.fugerit.java.doc.base.config.DocTypeHandler;
import org.fugerit.java.doc.mod.fop.FreeMarkerFopTypeHandlerUTF8;
import org.fugerit.java.doc.mod.fop.InitFopHandler;
import org.fugerit.java.doc.mod.fop.PdfFopTypeHandler;
import org.fugerit.java.doc.mod.fop.PdfFopTypeNoAccessibilityHandler;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Element;
import test.org.fugerit.java.BasicTest;

import java.io.FileOutputStream;
import java.io.InputStreamReader;

@Slf4j
class TestNoAccessibility extends BasicTest {

private boolean testHelper( String testCase, DocTypeHandler handler ) {
boolean ok = false;
try ( InputStreamReader reader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader( "sample/doc_alt_01.xml" ) );
FileOutputStream fos = new FileOutputStream( "target/test_no_accessibilit-"+testCase+"."+handler.getType() ) ) {
handler.handle( DocInput.newInput( handler.getType(), reader ) , DocOutput.newOutput( fos ) );
ok = true;
log.info( "result {}", ok );
} catch (Exception e) {
this.failEx( e );
}
return ok;
}

private static final DocTypeHandler[] HANDLERS = { PdfFopTypeHandler.HANDLER, new PdfFopTypeNoAccessibilityHandler() };

@Test
void testNoAccessibilityHandler() {
for ( int k=0; k<HANDLERS.length; k++ ) {
boolean ok = this.testHelper( HANDLERS[k].getClass().getSimpleName(), HANDLERS[k]);
Assertions.assertTrue(ok);
}
}

@Test
void testNoAccessibilityConfig() throws Exception {
PdfFopTypeHandler handler = new PdfFopTypeHandler();
this.testHelper( "test-config-pre", handler );
Element config = DOMIO.loadDOMDoc( "<conf><docHandlerCustomConfig accessibility='false' keep-empty-tags='true'/></conf>" ).getDocumentElement();
handler.configure( config );
this.testHelper( "test-config-post", handler );

}

}