Skip to content

Commit ff4fc15

Browse files
committed
1 parent b2519ff commit ff4fc15

File tree

11 files changed

+228
-0
lines changed

11 files changed

+228
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package test.org.fugerit.java.codesamples.fop.fop29;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.fugerit.java.codesamples.fop.common.FopPOC;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.io.File;
9+
import java.io.FileOutputStream;
10+
import java.io.IOException;
11+
12+
@Slf4j
13+
class TestFopPOC29 {
14+
15+
@Test
16+
void testFopPOC() throws IOException {
17+
File outputFile = new File( "target", "pdf-a-test-1-fop-2-9.pdf" );
18+
try (FileOutputStream fos = new FileOutputStream( outputFile )) {
19+
FopPOC.generatePdfATest1( fos );
20+
Assertions.assertTrue( outputFile.exists() );
21+
}
22+
}
23+
24+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.fugerit.java.codesamples.fop.common;
2+
3+
import org.apache.fop.apps.FOUserAgent;
4+
import org.apache.fop.apps.Fop;
5+
import org.apache.fop.apps.FopFactory;
6+
import org.apache.xmlgraphics.io.ResourceResolver;
7+
import org.apache.xmlgraphics.util.MimeConstants;
8+
import org.fugerit.java.core.function.SafeFunction;
9+
import org.fugerit.java.core.lang.helpers.ClassHelper;
10+
import org.fugerit.java.doc.mod.fop.FopConfig;
11+
import org.fugerit.java.doc.mod.fop.PdfFopTypeHandler;
12+
import org.fugerit.java.doc.mod.fop.config.FopConfigClassLoaderWrapper;
13+
import org.xml.sax.InputSource;
14+
15+
import javax.xml.transform.Result;
16+
import javax.xml.transform.Transformer;
17+
import javax.xml.transform.TransformerFactory;
18+
import javax.xml.transform.sax.SAXResult;
19+
import javax.xml.transform.stream.StreamSource;
20+
import java.io.FileInputStream;
21+
import java.io.InputStreamReader;
22+
import java.io.OutputStream;
23+
24+
public class FopPOC {
25+
26+
private FopPOC() {}
27+
28+
public static void generatePdfATest1(OutputStream os) {
29+
String xslFoPath = "test-xsl-fo/pdf-a-test-1.fo";
30+
String fopConfigPath = "fop-config/fop-config-pdf-a-ua.xml";
31+
generate( xslFoPath, fopConfigPath, os );
32+
}
33+
34+
public static void generate(String xslFoPath, String fopConfigPath, OutputStream os ) {
35+
SafeFunction.apply( () -> {
36+
ResourceResolver customResourceResolver = (ResourceResolver) ClassHelper.newInstance(PdfFopTypeHandler.ATT_FOP_CONFIG_RESOLVER_TYPE_DEFAULT );
37+
FopConfigClassLoaderWrapper fopConfig = new FopConfigClassLoaderWrapper(fopConfigPath, customResourceResolver);
38+
FopFactory fopFactory = fopConfig.newFactory();
39+
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
40+
foUserAgent.setAccessibility( true );
41+
foUserAgent.setKeepEmptyTags( true );
42+
Fop fop = fopConfig.newFactory().newFop(MimeConstants.MIME_PDF,foUserAgent,os);
43+
TransformerFactory factory = TransformerFactory.newInstance();
44+
Transformer transformer = factory.newTransformer();
45+
Result res = new SAXResult(fop.getDefaultHandler());
46+
try (InputStreamReader xslFoReader = new InputStreamReader(ClassHelper.loadFromDefaultClassLoader( xslFoPath )) ) {
47+
transformer.transform(new StreamSource(xslFoReader), res);
48+
}
49+
50+
} );
51+
}
52+
53+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<fop version="1.0">
2+
3+
<!-- Strict user configuration -->
4+
<strict-configuration>true</strict-configuration>
5+
6+
<!-- Strict FO validation -->
7+
<strict-validation>true</strict-validation>
8+
9+
<!-- Base URL for resolving relative URLs -->
10+
<base>.</base>
11+
12+
<!-- Font Base URL for resolving relative font URLs -->
13+
<font-base>.</font-base>
14+
15+
<!--
16+
NOTE: for PDF/A format all fonts, even the basic ones, myst be fully embdedded.
17+
https://xmlgraphics.apache.org/fop/2.10/pdfa.htm
18+
-->
19+
<renderers>
20+
<renderer mime="application/pdf">
21+
<pdf-ua-mode>PDF/UA-1</pdf-ua-mode>
22+
<pdf-a-mode>PDF/A-1b</pdf-a-mode>
23+
<version>1.4</version>
24+
<fonts>
25+
<font embed-url="classpath://font/TitilliumWeb-Regular.ttf" embedding-mode="full">
26+
<font-triplet name="TitilliumWeb" style="normal" weight="normal"/>
27+
</font>
28+
<font embed-url="classpath://font/TitilliumWeb-Bold.ttf" embedding-mode="full">
29+
<font-triplet name="TitilliumWeb" style="normal" weight="bold"/>
30+
</font>
31+
<font embed-url="classpath://font/TitilliumWeb-Italic.ttf" embedding-mode="full">
32+
<font-triplet name="TitilliumWeb" style="italic" weight="normal"/>
33+
</font>
34+
<font embed-url="classpath://font/TitilliumWeb-BoldItalic.ttf" embedding-mode="full">
35+
<font-triplet name="TitilliumWeb" style="italic" weight="bold"/>
36+
</font>
37+
</fonts>
38+
</renderer>
39+
</renderers>
40+
41+
42+
<!-- Source resolution in dpi (dots/pixels per inch) for determining the size of pixels in SVG and bitmap images, default: 72dpi -->
43+
<source-resolution>72</source-resolution>
44+
<!-- Target resolution in dpi (dots/pixels per inch) for specifying the target resolution for generated bitmaps, default: 72dpi -->
45+
<target-resolution>72</target-resolution>
46+
47+
<!-- default page-height and page-width, in case
48+
value is specified as auto -->
49+
<default-page-settings height="11in" width="8.26in"/>
50+
51+
</fop>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- 2 -->
3+
<fo:root xml:lang="en"
4+
font-family="TitilliumWeb" xmlns:fo="http://www.w3.org/1999/XSL/Format"
5+
xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
6+
<fo:layout-master-set>
7+
<fo:simple-page-master
8+
page-width="21cm"
9+
page-height="29.7cm"
10+
master-name="simpleA4"
11+
margin-left="10pt"
12+
margin-right="10pt"
13+
margin-top="10pt"
14+
margin-bottom="30pt">
15+
<fo:region-body region-name="xsl-region-body" />
16+
</fo:simple-page-master>
17+
</fo:layout-master-set>
18+
19+
<fo:declarations>
20+
<x:xmpmeta xmlns:x="adobe:ns:meta/">
21+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
22+
<rdf:Description rdf:about=""
23+
xmlns:dc="http://purl.org/dc/elements/1.1/">
24+
<dc:title><rdf:Alt><rdf:li xml:lang="x-default">Basic example</rdf:li></rdf:Alt></dc:title>
25+
<dc:creator><rdf:Seq><rdf:li>fugerit79</rdf:li></rdf:Seq></dc:creator>
26+
<dc:description>fj doc venus sample source xml</dc:description>
27+
<dc:language><rdf:Bag><rdf:li>en</rdf:li></rdf:Bag></dc:language>
28+
</rdf:Description>
29+
<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">
30+
<xmp:CreatorTool>Apache FOP over Fugerit Venus DOC</xmp:CreatorTool>
31+
</rdf:Description>
32+
</rdf:RDF>
33+
</x:xmpmeta>
34+
</fo:declarations>
35+
36+
<fo:bookmark-tree>
37+
<fo:bookmark internal-destination="b1">
38+
<fo:bookmark-title>Bookmark 1</fo:bookmark-title>
39+
</fo:bookmark>
40+
</fo:bookmark-tree>
41+
42+
<fo:page-sequence master-reference="simpleA4" initial-page-number="1">
43+
<fo:flow flow-name="xsl-region-body" >
44+
45+
46+
<fo:block>
47+
<fo:block id="b1" role="H1"><![CDATA[Heading test level 1 default font]]></fo:block>
48+
</fo:block>
49+
<fo:block id="EndOfDocument"></fo:block></fo:flow>
50+
</fo:page-sequence>
51+
</fo:root>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package test.org.fugerit.java.codesamples.fop.common;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.fugerit.java.codesamples.fop.common.FopPOC;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.io.File;
9+
import java.io.FileOutputStream;
10+
import java.io.IOException;
11+
12+
@Slf4j
13+
class TestFopPOC {
14+
15+
@Test
16+
void testFopPOC() throws IOException {
17+
File outputFile = new File( "target", "pdf-a-test-1.pdf" );
18+
try (FileOutputStream fos = new FileOutputStream( outputFile )) {
19+
FopPOC.generatePdfATest1( fos );
20+
Assertions.assertTrue( outputFile.exists() );
21+
}
22+
}
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package test.org.fugerit.java.codesamples.fop.latest;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.fugerit.java.codesamples.fop.common.FopPOC;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.io.File;
9+
import java.io.FileOutputStream;
10+
import java.io.IOException;
11+
12+
@Slf4j
13+
class TestFopPOCLatest {
14+
15+
@Test
16+
void testFopPOC() throws IOException {
17+
File outputFile = new File( "target", "pdf-a-test-1-fop-latest.pdf" );
18+
try (FileOutputStream fos = new FileOutputStream( outputFile )) {
19+
FopPOC.generatePdfATest1( fos );
20+
Assertions.assertTrue( outputFile.exists() );
21+
}
22+
}
23+
24+
}

0 commit comments

Comments
 (0)