Merge branch 'main' of https://github.com/omaster395464gh/fop4apex
This commit is contained in:
commit
928b46248c
20
pom.xml
20
pom.xml
@ -17,6 +17,7 @@
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<junit.version>5.10.0</junit.version>
|
||||
<batik.version>1.16</batik.version>
|
||||
<pdfbox.version>3.0.0</pdfbox.version>
|
||||
<sonar.organization>omaster395464gh</sonar.organization>
|
||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||
</properties>
|
||||
@ -44,7 +45,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>pdfbox</artifactId>
|
||||
<version>2.0.29</version>
|
||||
<version>${pdfbox.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
|
||||
@ -94,23 +95,6 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Start: Security fixes -->
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.pdfbox/fontbox -->
|
||||
<dependency>
|
||||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>fontbox</artifactId>
|
||||
<version>2.0.29</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- End: Security fixes -->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package de.pdv.apex;
|
||||
|
||||
import org.apache.fop.apps.*;
|
||||
import org.apache.pdfbox.io.RandomAccessReadBufferedFile;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.text.PDFTextStripper;
|
||||
import org.apache.pdfbox.text.PDFTextStripperByArea;
|
||||
@ -17,6 +18,7 @@ import javax.xml.transform.stream.StreamSource;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import org.apache.pdfbox.Loader;
|
||||
|
||||
class ExampleFO2PDFTest {
|
||||
|
||||
@ -110,8 +112,8 @@ class ExampleFO2PDFTest {
|
||||
if (!pdfFile.exists())
|
||||
throw new Exception("result file missing");
|
||||
|
||||
try (PDDocument document = PDDocument.load(pdfFile)) {
|
||||
//document.getClass();
|
||||
try (PDDocument document = Loader.loadPDF(new RandomAccessReadBufferedFile(pdfFile)))
|
||||
{
|
||||
if (!document.isEncrypted()) {
|
||||
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
|
||||
stripper.setSortByPosition(true);
|
||||
@ -124,6 +126,11 @@ class ExampleFO2PDFTest {
|
||||
System.out.println("Pages: " + document.getNumberOfPages());
|
||||
Assertions.assertEquals(Integer.valueOf(1).intValue(), document.getNumberOfPages());
|
||||
}
|
||||
/*
|
||||
for (PDPage page : document.getPages())
|
||||
{
|
||||
....
|
||||
}*/
|
||||
}
|
||||
System.out.println("Filesize (Bytes): " + Files.size(pdfFile.toPath()));
|
||||
System.out.println("Success!");
|
||||
|
||||
@ -4,6 +4,8 @@ import org.apache.fop.apps.FOUserAgent;
|
||||
import org.apache.fop.apps.Fop;
|
||||
import org.apache.fop.apps.FopFactory;
|
||||
import org.apache.fop.apps.MimeConstants;
|
||||
import org.apache.pdfbox.Loader;
|
||||
import org.apache.pdfbox.io.RandomAccessReadBufferedFile;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -19,6 +21,7 @@ import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
class ExampleXML2PDFTest {
|
||||
|
||||
@ -53,8 +56,7 @@ class ExampleXML2PDFTest {
|
||||
// configure foUserAgent as desired
|
||||
|
||||
// Setup output
|
||||
OutputStream out = new java.io.FileOutputStream(pdfFile);
|
||||
out = new java.io.BufferedOutputStream(out);
|
||||
OutputStream out = Files.newOutputStream(Paths.get(pdfFile.toURI()));
|
||||
|
||||
// Construct fop with desired output format
|
||||
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
|
||||
@ -84,11 +86,11 @@ class ExampleXML2PDFTest {
|
||||
|
||||
if (!pdfFile.exists())
|
||||
throw new Exception("result file missing");
|
||||
|
||||
PDDocument document = PDDocument.load(pdfFile);
|
||||
System.out.println("Pages: " + document.getNumberOfPages());
|
||||
System.out.println("Filesize (Bytes): " + Files.size(pdfFile.toPath()));
|
||||
Assertions.assertEquals(Integer.valueOf(1).intValue(), document.getNumberOfPages());
|
||||
System.out.println("Success!");
|
||||
try (PDDocument document = Loader.loadPDF(new RandomAccessReadBufferedFile(pdfFile))) {
|
||||
System.out.println("Pages: " + document.getNumberOfPages());
|
||||
System.out.println("Filesize (Bytes): " + Files.size(pdfFile.toPath()));
|
||||
Assertions.assertEquals(Integer.valueOf(1).intValue(), document.getNumberOfPages());
|
||||
System.out.println("Success!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user