Skip to content

Commit

Permalink
Added PDF/A1b doc handler.
Browse files Browse the repository at this point in the history
Some slight modification to the example document.ftl template were needed to be PDF/A compliant :
* added default font (loaded in fop-config-pdfa.xml)
* removed doc-subject info
* converted from para to h head-level=1
  • Loading branch information
fugerit79 committed Oct 17, 2024
1 parent 5bd0289 commit 648920b
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,16 @@ public byte[] openpdfhtmlExample() {
public byte[] rtfExample() {
return processDocument(DocConfig.TYPE_RTF);
}
@APIResponse(responseCode = "200", description = "The PDF document content" )
@APIResponse(responseCode = "500", description = "In case of an unexpected error" )
@Tags( { @Tag( name = "document" ), @Tag( name = "pdf" ) } )
@Operation( operationId = "PDFA1bExample", summary = "Example PDF/A-1b generation",
description = "Generates an example PDF document using Fugerit Venus Doc handler" )
@GET
@Produces("application/pdf")
@Path("/pdfa1b/example.pdf")
public byte[] pdfA1bExample() {
return processDocument("PDF/A-1b");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@
<!-- Type handler generating csv -->
<docHandler id="csv-opencsv" info="csv" type="org.fugerit.java.doc.mod.opencsv.OpenCSVTypeHandler"/>
<!-- OpenPDF type hanlder -->
<docHandler id="openpdf" info="openpdf" type="org.fugerit.java.doc.mod.openpdf.ext.PdfTypeHandler"/>
<docHandler id="openpdf" info="openpdf" type="org.fugerit.java.doc.mod.openpdf.ext.PdfTypeHandler">
<docHandlerCustomConfig charset="UTF-8">
<font name="TitilliumWeb" path="font/TitilliumWeb-Regular.ttf"/>
</docHandlerCustomConfig>
</docHandler>
<!-- OpenHTML type hanlder -->
<docHandler id="openpdf-html" info="openpdf-html" type="org.fugerit.java.doc.mod.openpdf.ext.HtmlTypeHandler"/>
<!-- OpenPDF type hanlder -->
<docHandler id="openrtf" info="openrtf" type="org.fugerit.java.doc.mod.openrtf.ext.RtfTypeHandler"/>
<!-- Type handler for PDF/A format -->
<docHandler id="PDF/A-1b" info="pdf" type="org.fugerit.java.doc.mod.fop.PdfFopTypeHandler">
<docHandlerCustomConfig charset="UTF-8" fop-config-mode="classloader" fop-config-classloader-path="fop-config-pdfa.xml" pdf-a-mode="PDF/A-1b"/>
</docHandler>
</docHandlerConfig>

<docChain id="shared">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@
<info name="margins">10;10;10;30</info>
<!-- documenta meta information -->
<info name="doc-title">${docTitle!defaultTitle}</info>
<info name="doc-subject">fj doc venus sample source FreeMarker Template XML - ftlx</info>
<info name="doc-author">fugerit79</info>
<info name="doc-language">en</info>
<!-- property specific for xls/xlsx -->
<info name="excel-table-id">data-table=print</info>
<!-- property specific for csv -->
<info name="csv-table-id">data-table</info>
<!-- Default font added for pdf a generation -->
<info name="default-font-name">TitilliumWeb</info>
<footer-ext>
<para align="right">${r"${currentPage}"} / ${r"${pageCount}"}</para>
</footer-ext>
</metadata>
<body>
<para>${docTitle!defaultTitle}</para>
<h head-level="1">${docTitle!defaultTitle}</h>
<table columns="3" colwidths="30;30;40" width="100" id="data-table" padding="2">
<row header="true">
<cell align="center"><para>Name</para></cell>
Expand Down
Binary file added src/main/resources/font/TitilliumWeb-Bold.ttf
Binary file not shown.
Binary file not shown.
Binary file added src/main/resources/font/TitilliumWeb-Italic.ttf
Binary file not shown.
Binary file not shown.
53 changes: 53 additions & 0 deletions src/main/resources/fop-config-pdfa.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<fop version="1.0">

<!-- Strict user configuration -->
<strict-configuration>true</strict-configuration>

<!-- Strict FO validation -->
<strict-validation>true</strict-validation>

<!-- Base URL for resolving relative URLs -->
<base>.</base>

<!-- Font Base URL for resolving relative font URLs -->
<font-base>.</font-base>

<!--
NOTE: for PDF/A format all fonts, even the basic ones, myst be fully embdedded.
https://xmlgraphics.apache.org/fop/2.8/pdfa.htm
-->
<renderers>
<renderer mime="application/pdf">
<pdf-a-mode>PDF/A-1b</pdf-a-mode>
<version>1.4</version>
<fonts>
<font embed-url="classpath://font/TitilliumWeb-Regular.ttf" embedding-mode="full">
<font-triplet name="TitilliumWeb" style="normal" weight="normal"/>
</font>
<font embed-url="classpath://font/TitilliumWeb-Bold.ttf" embedding-mode="full">
<font-triplet name="TitilliumWeb" style="normal" weight="bold"/>
</font>
<font embed-url="classpath://font/TitilliumWeb-Italic.ttf" embedding-mode="full">
<font-triplet name="TitilliumWeb" style="italic" weight="normal"/>
</font>
<font embed-url="classpath://font/TitilliumWeb-BoldItalic.ttf" embedding-mode="full">
<font-triplet name="TitilliumWeb" style="italic" weight="bold"/>
</font>
<!--
<auto-detect/>
-->
</fonts>
</renderer>
</renderers>


<!-- Source resolution in dpi (dots/pixels per inch) for determining the size of pixels in SVG and bitmap images, default: 72dpi -->
<source-resolution>72</source-resolution>
<!-- Target resolution in dpi (dots/pixels per inch) for specifying the target resolution for generated bitmaps, default: 72dpi -->
<target-resolution>72</target-resolution>

<!-- default page-height and page-width, in case
value is specified as auto -->
<default-page-settings height="11in" width="8.26in"/>

</fop>
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ void testOpenPDFHTML() {
void testOpenRTF() {
given().when().get("/doc/example.rtf").then().statusCode(200);
}
@Test
void testPdfA1b() {
given().when().get("/doc/pdfa1b/example.pdf").then().statusCode(200);
}
}

0 comments on commit 648920b

Please sign in to comment.