-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from fugerit-org/111-add-module-openpdf-and-o…
…penrtf Added module openpdf-ext and openrtf-ext #111
- Loading branch information
Showing
58 changed files
with
2,364 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Fugerit Document Generation Framework (fj-doc) | ||
|
||
## OpenPDF Renderer (PDF)(fj-doc-mod-openpdf-ext) | ||
|
||
[back to fj-doc index](../README.md) | ||
|
||
[![Maven Central](https://img.shields.io/maven-central/v/org.fugerit.java/fj-doc-mod-openpdf-ext.svg)](https://mvnrepository.com/artifact/org.fugerit.java/fj-doc-mod-openpdf-ext) | ||
[![javadoc](https://javadoc.io/badge2/org.fugerit.java/fj-doc-mod-openpdf-ext/javadoc.svg)](https://javadoc.io/doc/org.fugerit.java/fj-doc-mod-openpdf-ext) | ||
|
||
Renderer for PDF format, based on [OpenPDF](https://github.com/LibrePDF/OpenPDF). | ||
|
||
*Status* : | ||
Basic features implemented. (Sample JUnit [TestFreeMarker01](../fj-doc-sample/src/test/java/test/org/fugerit/java/doc/sample/freemarker/TestFreeMarker01.java) is now working). | ||
|
||
*Since* : fj-doc 3.4 | ||
|
||
*Native support* : | ||
Disabled, native support will be added in a future release. openpdf-ext native support must be verified. | ||
|
||
*Quickstart* : | ||
Basically this is only a type handler, see core library [fj-doc-base](../fj-doc-base/README.md). | ||
NOTE: If you have any special need you can open a pull request or create your own handler based on this. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>fj-doc-mod-openpdf-ext</artifactId> | ||
|
||
<parent> | ||
<groupId>org.fugerit.java</groupId> | ||
<artifactId>fj-doc</artifactId> | ||
<version>3.3.2-SNAPSHOT</version> | ||
</parent> | ||
|
||
<name>fj-doc-mod-openpdf-ext</name> | ||
<description>Renderer for PDF format, based on https://github.com/LibrePDF/OpenPDF</description> | ||
|
||
<properties> | ||
<openpdf-version-version>1.3.39</openpdf-version-version> | ||
</properties> | ||
|
||
<licenses> | ||
<license> | ||
<name>Apache License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>com.github.librepdf</groupId> | ||
<artifactId>openpdf</artifactId> | ||
<version>${openpdf-version-version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.fugerit.java</groupId> | ||
<artifactId>fj-core</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.fugerit.java</groupId> | ||
<artifactId>fj-doc-base</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.fugerit.java</groupId> | ||
<artifactId>fj-doc-freemarker</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<organization> | ||
<url>https://www.fugerit.org</url> | ||
<name>Fugerit</name> | ||
</organization> | ||
|
||
<url>https://www.fugerit.org/perm/venus/</url> | ||
|
||
</project> |
53 changes: 53 additions & 0 deletions
53
...c-mod-openpdf-ext/src/main/java/org/fugerit/java/doc/mod/openpdf/ext/HtmlTypeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.fugerit.java.doc.mod.openpdf.ext; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.OutputStream; | ||
|
||
import org.fugerit.java.core.cfg.ConfigException; | ||
import org.fugerit.java.doc.base.config.DocConfig; | ||
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.base.config.DocTypeHandlerDefault; | ||
import org.fugerit.java.doc.base.model.DocBase; | ||
import org.fugerit.java.doc.mod.openpdf.ext.helpers.OpenPDFConfigHelper; | ||
import org.fugerit.java.doc.mod.openpdf.ext.helpers.OpenPpfDocHandler; | ||
import org.w3c.dom.Element; | ||
|
||
import com.lowagie.text.Document; | ||
import com.lowagie.text.html.HtmlWriter; | ||
|
||
public class HtmlTypeHandler extends DocTypeHandlerDefault { | ||
|
||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = -3491991891783269389L; | ||
|
||
public static final DocTypeHandler HANDLER = new HtmlTypeHandler(); | ||
|
||
public HtmlTypeHandler() { | ||
super( DocConfig.TYPE_HTML, OpenPpfDocHandler.MODULE ); | ||
} | ||
|
||
@Override | ||
public void handle(DocInput docInput, DocOutput docOutput) throws Exception { | ||
DocBase docBase = docInput.getDoc(); | ||
OutputStream outputStream = docOutput.getOs(); | ||
Document document = new Document( ); | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
HtmlWriter.getInstance( document, baos ); | ||
OpenPpfDocHandler handler = new OpenPpfDocHandler( document, DocConfig.TYPE_HTML ); | ||
handler.handleDoc( docBase ); | ||
baos.writeTo( outputStream ); | ||
baos.close(); | ||
outputStream.close(); | ||
} | ||
|
||
@Override | ||
protected void handleConfigTag(Element config) throws ConfigException { | ||
super.handleConfigTag(config); | ||
OpenPDFConfigHelper.handleConfig( config, this.getType() ); | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
...oc-mod-openpdf-ext/src/main/java/org/fugerit/java/doc/mod/openpdf/ext/PdfTypeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.fugerit.java.doc.mod.openpdf.ext; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.OutputStream; | ||
|
||
import org.fugerit.java.core.cfg.ConfigException; | ||
import org.fugerit.java.doc.base.config.DocConfig; | ||
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.base.config.DocTypeHandlerDefault; | ||
import org.fugerit.java.doc.base.model.DocBase; | ||
import org.fugerit.java.doc.mod.openpdf.ext.helpers.OpenPDFConfigHelper; | ||
import org.fugerit.java.doc.mod.openpdf.ext.helpers.OpenPpfDocHandler; | ||
import org.w3c.dom.Element; | ||
|
||
import com.lowagie.text.Document; | ||
import com.lowagie.text.PageSize; | ||
import com.lowagie.text.pdf.PdfWriter; | ||
|
||
public class PdfTypeHandler extends DocTypeHandlerDefault { | ||
|
||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = 5459938865782356227L; | ||
|
||
public static final DocTypeHandler HANDLER = new PdfTypeHandler(); | ||
|
||
public PdfTypeHandler() { | ||
super( DocConfig.TYPE_PDF, OpenPpfDocHandler.MODULE ); | ||
} | ||
|
||
@Override | ||
public void handle(DocInput docInput, DocOutput docOutput) throws Exception { | ||
DocBase docBase = docInput.getDoc(); | ||
OutputStream outputStream = docOutput.getOs(); | ||
String[] margins = docBase.getInfo().getProperty( "margins", "20;20;20;20" ).split( ";" ); | ||
Document document = new Document( PageSize.A4, Integer.parseInt( margins[0] ), | ||
Integer.parseInt( margins[1] ), | ||
Integer.parseInt( margins[2] ), | ||
Integer.parseInt( margins[3] ) ); | ||
// allocate buffer | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
// create pdf writer | ||
PdfWriter pdfWriter = PdfWriter.getInstance( document, baos ); | ||
// create doc handler | ||
OpenPpfDocHandler handler = new OpenPpfDocHandler( document, pdfWriter ); | ||
if ( "true".equalsIgnoreCase( docBase.getInfo().getProperty( "set-total-page" ) ) ) { | ||
handler.handleDoc( docBase ); | ||
int totalPageCount = pdfWriter.getCurrentPageNumber()-1; | ||
document = new Document( PageSize.A4, Integer.parseInt( margins[0] ), | ||
Integer.parseInt( margins[1] ), | ||
Integer.parseInt( margins[2] ), | ||
Integer.parseInt( margins[3] ) ); | ||
baos = new ByteArrayOutputStream(); | ||
pdfWriter = PdfWriter.getInstance( document, baos ); | ||
handler = new OpenPpfDocHandler(document, pdfWriter, totalPageCount ); | ||
} | ||
handler.handleDoc( docBase ); | ||
baos.writeTo( outputStream ); | ||
baos.close(); | ||
outputStream.close(); | ||
} | ||
|
||
@Override | ||
protected void handleConfigTag(Element config) throws ConfigException { | ||
super.handleConfigTag(config); | ||
OpenPDFConfigHelper.handleConfig( config, this.getType() ); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...od-openpdf-ext/src/main/java/org/fugerit/java/doc/mod/openpdf/ext/helpers/CellParent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.fugerit.java.doc.mod.openpdf.ext.helpers; | ||
|
||
import com.lowagie.text.Cell; | ||
import com.lowagie.text.Element; | ||
|
||
public class CellParent implements ParentElement { | ||
|
||
private Cell cell; | ||
|
||
public CellParent( Cell cell ) { | ||
this.cell = cell; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.fugerit.java.doc.mod.itext.ParentElement#add(com.lowagie.text.Element) | ||
*/ | ||
public void add(Element element) { | ||
this.cell.addElement( element ); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...penpdf-ext/src/main/java/org/fugerit/java/doc/mod/openpdf/ext/helpers/DocumentParent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.fugerit.java.doc.mod.openpdf.ext.helpers; | ||
|
||
import com.lowagie.text.Document; | ||
import com.lowagie.text.Element; | ||
|
||
public class DocumentParent implements ParentElement { | ||
|
||
private Document document; | ||
|
||
public DocumentParent( Document document) { | ||
this.document = document; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.fugerit.java.doc.mod.itext.ParentElement#add(com.lowagie.text.Element) | ||
*/ | ||
public void add(Element element) { | ||
this.document.add( element ); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...f-ext/src/main/java/org/fugerit/java/doc/mod/openpdf/ext/helpers/OpenPDFConfigHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.fugerit.java.doc.mod.openpdf.ext.helpers; | ||
|
||
import org.fugerit.java.core.cfg.ConfigException; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.NodeList; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class OpenPDFConfigHelper { | ||
|
||
private OpenPDFConfigHelper() {} | ||
|
||
public static final String TAG_NAME_FONT = "font"; | ||
|
||
public static final String ATT_NAME = "name"; | ||
public static final String ATT_PATH = "path"; | ||
|
||
|
||
public static void handleConfig( Element config, String type ) throws ConfigException { | ||
log.info( "configure for type: {}", type ); | ||
NodeList fontList = config.getElementsByTagName( TAG_NAME_FONT ); | ||
for ( int k=0; k<fontList.getLength(); k++ ) { | ||
Element currentFontTag = (Element) fontList.item( k ); | ||
String name = currentFontTag.getAttribute( ATT_NAME ); | ||
String path = currentFontTag.getAttribute( ATT_PATH ); | ||
log.info( "current font {} - {}", name, path ); | ||
ConfigException.apply( () -> OpenPpfDocHandler.registerFont( name , path ) ); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.