Skip to content

Commit

Permalink
LDEV-2968 switch to openhtmlpdf from flying saucer (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Jan 22, 2025
1 parent 87de16f commit 06bfa75
Show file tree
Hide file tree
Showing 25 changed files with 129 additions and 61 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ jobs:
luceeVersion: ${{ matrix.lucee.version }}
luceeVersionQuery: ${{ matrix.lucee.query }}
extensionDir: ${{ github.workspace }}/target
extensions: B737ABC4-D43F-4D91-8E8E973E37C40D1B #image
env:
testLabels: pdf
testAdditional: ${{ github.workspace }}/tests

deploy:
runs-on: ubuntu-latest
needs: [build-and-test]
if: always() && needs.build-and-test.result == 'success'
if: never() && needs.build-and-test.result == 'success'
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
28 changes: 5 additions & 23 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<property name="dist" location="target"/>
<property name="tld" location="source/tld"/>
<property name="fld" location="source/fld"/>
<property name="bundleversion" value="version"/>
<property name="bundlename" value="bundlename"/>
<property name="filename" value="filename"/>

<path id="classpath">
<fileset dir="${lib}">
Expand All @@ -23,17 +26,15 @@
<target name="init">
<!-- Create the time stamp -->
<tstamp/>

<delete dir="${temp}"/>
<delete dir="${dist}"/>

<!-- Create the build directory structure used by compile -->
<mkdir dir="${temp}"/>
<mkdir dir="${build}"/>
<mkdir dir="${dist}/"/>
</target>


<target name="copy" depends="init" description="copy source file to temp" >
<!-- copy the source -->
<copy todir="${temp}">
Expand All @@ -42,7 +43,6 @@
</fileset>
</copy>


<tstamp>
<format property="NOW" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
Expand All @@ -57,34 +57,25 @@ lucee-core-version: "${luceeCoreVersion}"
release-type: ${releaseType}
start-bundles: false
</echo>


</target>



<target name="compile" depends="copy"
description="compile the source " >
<!-- Compile ACF-Infinspan source -->
<javac srcdir="${temp}" target="1.7" destdir="${build}" debug="true" debuglevel="lines,vars,source">
<javac srcdir="${temp}" target="11" source="11" destdir="${build}" debug="true" debuglevel="lines,vars,source">
<classpath refid="classpath" />
</javac>
</target>

<target name="dist" depends="compile"
description="generate the distribution" >



<!-- copy the source -->
<echo>-------------------------</echo>
<copy todir="${build}">
<fileset dir="${src}">
<include name="**/*.jar"/>
</fileset>
</copy>


<!-- Put everything in ${build} into .jar file -->
<jar
jarfile="${dist}/extension/jars/${bundlename}-${bundleversion}.jar" basedir="${build}" manifest="${src}/META-INF/MANIFEST.MF">
Expand All @@ -96,7 +87,6 @@ start-bundles: false
</manifest>
</jar>


<!-- copy the tlds necessary -->
<copy file="${tld}/tag.tldx" tofile="${dist}/extension/tlds/pdftag.tldx" />
<replaceregexp
Expand All @@ -110,7 +100,6 @@ start-bundles: false
replace="${bundleversion}"
byline="true"/>


<!-- copy the flds necessary -->
<copy file="${fld}/function.fld" tofile="${dist}/extension/flds/pdffunction.fld" />
<replaceregexp
Expand All @@ -124,10 +113,6 @@ start-bundles: false
replace="${bundleversion}"
byline="true"/>





<!-- copy the context necessary
<copy todir="${dist}/extension/webcontexts">
<fileset dir="${context}">
Expand All @@ -154,13 +139,10 @@ start-bundles: false
</fileset>
</copy>



<!-- Zip everything -->
<zip destfile="${dist}/${filename}-${bundleversion}.lex">
<zipfileset dir="${dist}/extension"/>
</zip>

</target>

<target name="clean" depends="dist" description="clean up" >
Expand Down
72 changes: 66 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.lucee</groupId>
<artifactId>pdf-extension</artifactId>
<version>1.2.0.11-SNAPSHOT</version>
<version>2.0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>PDF Extension</name>

Expand All @@ -21,9 +21,69 @@
<release.url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</release.url>
<snapshot.url>https://oss.sonatype.org/content/repositories/snapshots/</snapshot.url>
</properties>



<!-- not used, but good for version reporting! -->
<dependencies>
<dependency>
<groupId>io.github.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-core</artifactId>
<version>1.1.24</version>
</dependency>
<dependency>
<groupId>io.github.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-pdfbox</artifactId>
<version>1.1.24</version>
</dependency>
<dependency>
<groupId>io.github.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-java2d</artifactId>
<version>1.1.24</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-io</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>xmpbox</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>de.rototor.pdfbox</groupId>
<artifactId>graphics2d</artifactId>
<version>3.0.1</version><!-- waiting on OSGI PR https://github.com/rototor/pdfbox-graphics2d/pull/61 -->
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>xmpbox</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcutil-jdk18on</artifactId>
<version>1.80</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>1.80</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.80</version>
</dependency>
</dependencies>
<scm>
<url>https://github.com/lucee/extension-pdf</url>
<connection>scm:git:git://github.com/lucee/extension-pdf.git</connection>
Expand Down Expand Up @@ -121,7 +181,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
Expand All @@ -130,7 +190,7 @@
</goals>
<configuration>
<target>
<ant antfile="build.xml" target="clean">
<ant antfile="build.xml" target="clean" inheritAll="true">
<property name="bundleversion" value="${project.version}"/>
<property name="bundlename" value="${bundlename}"/>
<property name="filename" value="${project.artifactId}"/>
Expand Down
Binary file added source/java/libs/bcmail-jdk18on-1.80.jar
Binary file not shown.
Binary file added source/java/libs/bcpkix-jdk18on-1.80.jar
Binary file not shown.
Binary file added source/java/libs/bcprov-jdk18on-1.80.jar
Binary file not shown.
Binary file added source/java/libs/bcutil-jdk18on-1.80.jar
Binary file not shown.
Binary file added source/java/libs/commons-logging-1.3.2.jar
Binary file not shown.
Binary file not shown.
Binary file added source/java/libs/graphics2d-3.0.3-SNAPSHOT.jar
Binary file not shown.
Binary file added source/java/libs/openhtmltopdf-core-1.1.24.jar
Binary file not shown.
Binary file added source/java/libs/openhtmltopdf-java2d-1.1.24.jar
Binary file not shown.
Binary file added source/java/libs/openhtmltopdf-pdfbox-1.1.24.jar
Binary file not shown.
Binary file not shown.
Binary file modified source/java/libs/org.lucee.itext-2.1.7.jar
Binary file not shown.
Binary file removed source/java/libs/org.lucee.pdfbox-3.0.0.RC101.jar
Binary file not shown.
Binary file not shown.
Binary file added source/java/libs/pdfbox-3.0.3.jar
Binary file not shown.
Binary file added source/java/libs/pdfbox-io-3.0.3.jar
Binary file not shown.
Binary file added source/java/libs/xmpbox-3.0.3.jar
Binary file not shown.
19 changes: 14 additions & 5 deletions source/java/src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ Require-Bundle: bouncycastle.mail;bundle-version=1.38.0,
bouncycastle.prov;bundle-version=1.38.0,
bouncycastle.tsp;bundle-version=1.38.0,
org.lucee.itext;bundle-version=2.1.7,
org.xhtmlrenderer.flying.saucer.core;bundle-version=9.1.20,
org.lucee.flyingSaucerPDF;bundle-version=9.1.20,
org.lucee.pdfbox;bundle-version=3.0.0.RC101,
org.lucee.pdfbox-fontbox;bundle-version=3.0.0.RC1,
tagsoup;bundle-version=1.2.1.0002L
tagsoup;bundle-version=1.2.1.0002L,
io.github.openhtmltopdf.core;bundle-version=1.1.24,
io.github.openhtmltopdf.java2d;bundle-version=1.1.24,
io.github.openhtmltopdf.pdfbox;bundle-version=1.1.24,
org.apache.pdfbox;bundle-version=3.0.3,
org.apache.pdfbox.fontbox;bundle-version=3.0.3,
org.apache.pdfbox.io;bundle-version=3.0.3,
bcmail;bundle-version=1.80.0,
bcprov;bundle-version=1.80.0,
bcutil;bundle-version=1.80.0,
bcpkix;bundle-version=1.80.0,
org.apache.commons.commons-logging;bundle-version=1.3.2,
de.rototor.pdfbox.graphics2d;bundle-version=3.0.3.SNAPSHOT,
org.apache.pdfbox.xmpbox;bundle-version=3.0.3
16 changes: 9 additions & 7 deletions source/java/src/org/lucee/extension/fs/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;

import org.xhtmlrenderer.pdf.ITextRenderer;
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;

public class Test {

public static void main(String[] args) throws Exception {

ITextRenderer renderer = new ITextRenderer();
PdfRendererBuilder builder = new PdfRendererBuilder();

// if you have html source in hand, use it to generate document object
renderer.setDocumentFromString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:html=\"http://www.w3.org/1999/xhtml\"><body><h1>Title</h1>\n" + "This is the text\n" + "</body></html>");
renderer.layout();
String html = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:html=\"http://www.w3.org/1999/xhtml\"><body><h1>Title</h1>\n" + "This is the text\n" + "</body></html>";

String fileNameWithPath = "/Users/mic/Tmp3/PDF-FromHtmlString.pdf";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
FileOutputStream fos = new FileOutputStream(fileNameWithPath);
renderer.createPDF(baos);

builder.withHtmlContent(html, null);
builder.toStream(outputStream);
builder.run();
fos.close();

System.out.println("File 2: '" + fileNameWithPath + "' created.");
Expand Down
10 changes: 6 additions & 4 deletions source/java/src/org/lucee/extension/pdf/PDFStruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.io.RandomAccessReadBuffer;
import org.apache.pdfbox.io.RandomAccessReadBufferedFile;
import org.lucee.extension.pdf.util.PDFUtil;
import org.lucee.extension.pdf.util.StructSupport;

Expand Down Expand Up @@ -375,17 +377,17 @@ public java.util.Collection values() {
public PDDocument toPDDocument() throws IOException {
PDDocument doc;
if (barr != null) {
if (password != null) doc = Loader.loadPDF(new ByteArrayInputStream(barr, 0, barr.length), password);
else doc = Loader.loadPDF(new ByteArrayInputStream(barr, 0, barr.length));
if (password != null) doc = Loader.loadPDF(new RandomAccessReadBuffer(barr), password);
else doc = Loader.loadPDF(new RandomAccessReadBuffer(barr));
}
else if (resource instanceof File) {
if (password != null) doc = Loader.loadPDF((File) resource, password);
else doc = Loader.loadPDF((File) resource);
}
else {
barr = PDFUtil.toBytes(resource);
if (password != null) doc = Loader.loadPDF(new ByteArrayInputStream(barr, 0, barr.length), password);
else doc = Loader.loadPDF(new ByteArrayInputStream(barr, 0, barr.length));
if (password != null) doc = Loader.loadPDF(new RandomAccessReadBuffer(barr), password);
else doc = Loader.loadPDF(new RandomAccessReadBuffer(barr));
}
return doc;

Expand Down
Loading

0 comments on commit 06bfa75

Please sign in to comment.