Skip to content

Commit a3dd21e

Browse files
committed
Added samples for pdf-a #43
1 parent d44045b commit a3dd21e

File tree

7 files changed

+85
-25
lines changed

7 files changed

+85
-25
lines changed

fj-doc-sample/src/main/resources/config/freemarker-doc-process.xml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
xsi:schemaLocation="https://freemarkerdocprocess.fugerit.org https://www.fugerit.org/data/java/doc/xsd/freemarker-doc-process-1-0.xsd" >
66

77
<docHandlerConfig>
8-
<data id="md-ext" info="md" type="org.fugerit.java.doc.base.typehandler.markdown.SimpleMarkdownExtTypeHandler" />
9-
<data id="xml-doc" info="xml" type="org.fugerit.java.doc.base.config.DocTypeHandlerXMLUTF8" />
10-
<data id="xls-poi" info="xls" type="org.fugerit.java.doc.mod.poi.XlsPoiTypeHandler" />
11-
<data id="xlsx-poi" info="xlsx" type="org.fugerit.java.doc.mod.poi.XlsxPoiTypeHandler" />
12-
<data id="fo-fop" info="fo" type="org.fugerit.java.doc.mod.fop.FreeMarkerFopTypeHandlerUTF8" />
13-
<data id="pdf-fop" info="pdf" type="org.fugerit.java.doc.mod.fop.PdfFopTypeHandler">
8+
<docHandler id="PDF/A-1a" info="pdf" type="org.fugerit.java.doc.mod.fop.PdfFopTypeHandler">
9+
<docHandlerCustomConfig charset="UTF-8" fop-config-mode="classloader" fop-config-classloader-path="fop-config.xml" pdf-a-mode="PDF/A-1a"/>
10+
</docHandler>
11+
<docHandler id="md-ext" info="md" type="org.fugerit.java.doc.base.typehandler.markdown.SimpleMarkdownExtTypeHandler" />
12+
<docHandler id="xml-doc" info="xml" type="org.fugerit.java.doc.base.config.DocTypeHandlerXMLUTF8" />
13+
<docHandler id="xls-poi" info="xls" type="org.fugerit.java.doc.mod.poi.XlsPoiTypeHandler" />
14+
<docHandler id="xlsx-poi" info="xlsx" type="org.fugerit.java.doc.mod.poi.XlsxPoiTypeHandler" />
15+
<docHandler id="fo-fop" info="fo" type="org.fugerit.java.doc.mod.fop.FreeMarkerFopTypeHandlerUTF8" />
16+
<docHandler id="pdf-fop" info="pdf" type="org.fugerit.java.doc.mod.fop.PdfFopTypeHandler">
1417
<!--
1518
Starting with fj-doc-mod-fop version 0.5.2 there is a new attribute :
1619
'fop-config-mode'
@@ -27,13 +30,12 @@
2730
Example 1: <config fop-config-mode='classloader-legacy' fop-config-classloader-path="fop-config.xml" font-base-classloader-path="font/"/>
2831
Note for compatibilty reason, if attributes 'fop-config-classloader-path' and 'font-base-classloader-path' are both set, the mode switch to fop-config-mode='classloader-legacy'
2932
Example 2 : <config fop-config-classloader-path="fop-config.xml" font-base-classloader-path="font/"/>
30-
3133
-->
32-
<config charset="UTF-8" fop-config-classloader-path="fop-config.xml" font-base-classloader-path="font/"/>
33-
</data>
34-
<data id="html-fm" info="html" type="org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8" />
35-
<data id="html-fragment-fm" info="fhtml" type="org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlFragmentTypeHandlerUTF8" />
36-
<data id="csv-opencsv" info="csv" type="org.fugerit.java.doc.mod.opencsv.OpenCSVTypeHandler"/>
34+
<docHandlerCustomConfig charset="UTF-8" fop-config-mode="classloader" fop-config-classloader-path="fop-config.xml"/>
35+
</docHandler>
36+
<docHandler id="html-fm" info="html" type="org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8" />
37+
<docHandler id="html-fragment-fm" info="fhtml" type="org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlFragmentTypeHandlerUTF8" />
38+
<docHandler id="csv-opencsv" info="csv" type="org.fugerit.java.doc.mod.opencsv.OpenCSVTypeHandler"/>
3739
</docHandlerConfig>
3840

3941
<docChain id="shared">
@@ -80,5 +82,9 @@
8082
<docChain id="basic" parent="shared">
8183
<chainStep stepType="complex" template-path="basic.ftl"/>
8284
</docChain>
85+
86+
<docChain id="pdf_a_test" parent="shared">
87+
<chainStep stepType="complex" template-path="pdf_a_test.ftl"/>
88+
</docChain>
8389

8490
</freemarker-doc-process-config>

fj-doc-sample/src/main/resources/fop-config.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
<renderers>
1616
<renderer mime="application/pdf">
1717
<fonts>
18-
<font embed-url="classpath://font/TitilliumWeb-Regular.ttf">
18+
<font embed-url="classpath://font/TitilliumWeb-Regular.ttf" embedding-mode="full">
1919
<font-triplet name="TitilliumWeb" style="normal" weight="normal"/>
2020
</font>
21-
<font embed-url="classpath://font/TitilliumWeb-Bold.ttf">
21+
<font embed-url="classpath://font/TitilliumWeb-Bold.ttf" embedding-mode="full">
2222
<font-triplet name="TitilliumWeb" style="normal" weight="bold"/>
2323
</font>
24-
<font embed-url="classpath://font/TitilliumWeb-Italic.ttf">
24+
<font embed-url="classpath://font/TitilliumWeb-Italic.ttf" embedding-mode="subset">
2525
<font-triplet name="TitilliumWeb" style="italic" weight="normal"/>
2626
</font>
27-
<font embed-url="classpath://font/TitilliumWeb-BoldItalic.ttf">
27+
<font embed-url="classpath://font/TitilliumWeb-BoldItalic.ttf" embedding-mode="subset">
2828
<font-triplet name="TitilliumWeb" style="italic" weight="bold"/>
2929
</font>
3030
<!--
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<doc
3+
xmlns="http://javacoredoc.fugerit.org"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-0.xsd" >
6+
7+
<!--
8+
Sample Apache FreeMarker template for Fugerit Doc.
9+
Note : this example has no intention of being a guid to FreeMarker
10+
(In case check FreeMarker documentation https://freemarker.apache.org/docs/index.html)
11+
-->
12+
13+
<meta>
14+
15+
<!-- Margin for document : left;right;top;bottom -->
16+
<info name="margins">10;10;10;30</info>
17+
18+
<!-- id table to be used for xlsx output -->
19+
<info name="excel-table-id">excel-table=print</info>
20+
<info name="excel-width-multiplier">450</info>
21+
<!-- id table to be used for xsv output -->
22+
<info name="csv-table-id">excel-table</info>
23+
24+
<info name="default-font-name">TitilliumWeb</info>
25+
26+
<bookmark-tree>
27+
<bookmark ref="b1">Bookmark 1</bookmark>
28+
</bookmark-tree>
29+
30+
</meta>
31+
32+
<body>
33+
34+
<h head-level="1" id="b1">Heading test level 1 default font</h>
35+
36+
</body>
37+
38+
</doc>

fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/facade/BasicFacadeTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,26 +141,29 @@ protected DocBase getDocBase() throws Exception {
141141
return docBase;
142142
}
143143

144-
public void produce( File outputFolder, String facadeId, DocBase doc, Reader reader, String baseName, String type ) throws Exception {
144+
public void produce( File outputFolder, String facadeId, DocBase doc, Reader reader, String baseName, String format ) throws Exception {
145145
DocHandlerFacade facade = PROCESS_CONFIG.getFacade();
146-
DocTypeHandler handler = facade.findHandler( type );
146+
DocTypeHandler handler = facade.findHandler( format );
147147
StringBuilder append = new StringBuilder();
148148
if ( handler == null ) {
149-
throw new ConfigException( "No handler with id : "+type );
150-
} else if ( !handler.getType().equalsIgnoreCase( type ) ) {
149+
throw new ConfigException( "No handler with id : "+format );
150+
} else if ( !handler.getType().equalsIgnoreCase( format ) ) {
151151
append.append( "_" );
152152
append.append( handler.getModule() );
153153
}
154154
append.append( "." );
155155
append.append( handler.getType() );
156+
if ( !handler.getType().equalsIgnoreCase( handler.getFormat() ) ) {
157+
baseName = baseName+"_"+handler.getFormat().replaceAll( "/" , "_");
158+
}
156159
File file = new File( outputFolder, baseName + append.toString() );
157160
logger.info("Create file {}", file.getCanonicalPath());
158161
try (FileOutputStream fos = new FileOutputStream(file)) {
159162
long start = System.currentTimeMillis();
160-
DocInput input = DocInput.newInput( type , reader, this.getSourceType() );
163+
DocInput input = DocInput.newInput( format , reader, this.getSourceType() );
161164
DocOutput output = DocOutput.newOutput( fos );
162165
facade.handle( input , output );
163-
this.checkpoints.addCheckpointFromStartTime( "PRODUCE-"+type, start );
166+
this.checkpoints.addCheckpointFromStartTime( "PRODUCE-"+format, start );
164167
}
165168
}
166169

fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestFreeMarker01.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ public class TestFreeMarker01 extends BasicFreeMarkerTest {
66

77
public TestFreeMarker01() {
88
super( "free-marker-01", DocConfig.TYPE_FO,
9-
DocConfig.TYPE_XML, DocConfig.TYPE_PDF, DocConfig.TYPE_XLS,
10-
DocConfig.TYPE_HTML, DocConfig.TYPE_XLSX, DocConfig.TYPE_CSV );
9+
DocConfig.TYPE_XML, DocConfig.TYPE_PDF,
10+
DocConfig.TYPE_HTML);
1111
}
1212

1313

fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestFreemarkerConfigValidation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44

55
import org.fugerit.java.core.lang.helpers.ClassHelper;
66
import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigValidator;
7+
import org.junit.Assert;
78
import org.junit.Test;
89

910
public class TestFreemarkerConfigValidation {
1011

1112
@Test
1213
public void testValidation() {
1314
try ( InputStreamReader xmlReader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader( "config/freemarker-doc-process.xml" ) ) ) {
14-
FreemarkerDocProcessConfigValidator.logValidation( xmlReader );
15+
boolean valid = FreemarkerDocProcessConfigValidator.logValidation( xmlReader );
16+
Assert.assertTrue( "Xml non valido", valid );
1517
} catch (Exception e) {
1618
throw new RuntimeException( e );
1719
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package test.org.fugerit.java.doc.sample.freemarker;
2+
3+
import org.fugerit.java.doc.base.config.DocConfig;
4+
5+
public class TestPdfA extends BasicFreeMarkerTest {
6+
7+
public TestPdfA() {
8+
super( "pdf_a_test", DocConfig.TYPE_FO, DocConfig.FORMAT_PDF_A_1A, DocConfig.TYPE_PDF );
9+
}
10+
11+
}

0 commit comments

Comments
 (0)