This is an automated email from the ASF dual-hosted git repository.
apupier pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 7019f06187 Add test to pdf:merge with a more complex pdf
7019f06187 is described below
commit 7019f061876862fc5d53668acff526e21d694934
Author: Aurélien Pupier <[email protected]>
AuthorDate: Mon Jan 5 16:25:17 2026 +0100
Add test to pdf:merge with a more complex pdf
* image
* colored text
* hyperlink
* table
* shape
* fontwork
* text box
* pdf comment
* chart
* watermark
* table of content
* footnote
* formula
* OLE object
use of another pdf with page labels which I wasn't able to generate
This current set allowed to figure out that one class was not registered
for reflection.
The source of the pdf has been provided too to easily modify the pdf and
broaden coverage.
Signed-off-by: Aurélien Pupier <[email protected]>
---
.../component/pdf/deployment/PdfProcessor.java | 8 +++---
.../camel/quarkus/component/pdf/it/PdfTest.java | 27 +++++++++++++++++++++
.../pdf-with-several-different-contents.pdf | Bin 0 -> 110549 bytes
...or-test-pdf-with-several-different-contents.odt | Bin 0 -> 67758 bytes
.../pdf/src/test/resources/test_pagelabels.pdf | Bin 0 -> 289703 bytes
5 files changed, 32 insertions(+), 3 deletions(-)
diff --git
a/extensions/pdf/deployment/src/main/java/org/apache/camel/quarkus/component/pdf/deployment/PdfProcessor.java
b/extensions/pdf/deployment/src/main/java/org/apache/camel/quarkus/component/pdf/deployment/PdfProcessor.java
index 820cc7661c..f4bb3b70a0 100644
---
a/extensions/pdf/deployment/src/main/java/org/apache/camel/quarkus/component/pdf/deployment/PdfProcessor.java
+++
b/extensions/pdf/deployment/src/main/java/org/apache/camel/quarkus/component/pdf/deployment/PdfProcessor.java
@@ -22,6 +22,7 @@ import io.quarkus.deployment.builditem.FeatureBuildItem;
import
io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import
io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
+import
org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDParentTreeValue;
import org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler;
class PdfProcessor {
@@ -78,8 +79,9 @@ class PdfProcessor {
}
@BuildStep
- ReflectiveClassBuildItem registerForReflection() {
- return ReflectiveClassBuildItem.builder(StandardSecurityHandler.class)
- .build();
+ void registerForReflection(BuildProducer<ReflectiveClassBuildItem>
reflectionClass) {
+ reflectionClass
+
.produce(ReflectiveClassBuildItem.builder(StandardSecurityHandler.class).constructors().methods().build());
+
reflectionClass.produce(ReflectiveClassBuildItem.builder(PDParentTreeValue.class).constructors().methods().build());
}
}
diff --git
a/integration-tests/pdf/src/test/java/org/apache/camel/quarkus/component/pdf/it/PdfTest.java
b/integration-tests/pdf/src/test/java/org/apache/camel/quarkus/component/pdf/it/PdfTest.java
index 0001eb1473..aa0cfc19ff 100644
---
a/integration-tests/pdf/src/test/java/org/apache/camel/quarkus/component/pdf/it/PdfTest.java
+++
b/integration-tests/pdf/src/test/java/org/apache/camel/quarkus/component/pdf/it/PdfTest.java
@@ -17,6 +17,7 @@
package org.apache.camel.quarkus.component.pdf.it;
import java.io.IOException;
+import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -24,6 +25,7 @@ import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.smallrye.common.os.OS;
+import org.apache.commons.io.FileUtils;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
@@ -114,6 +116,31 @@ class PdfTest {
doc.close();
}
+ @Test
+ public void mergeWithComplexPdf() throws IOException {
+ InputStream pageLabelPdfStream =
PdfTest.class.getResourceAsStream("/test_pagelabels.pdf");
+ Path firstPdfPath = Files.createTempFile("firstPdf", ".pdf");
+ FileUtils.copyInputStreamToFile(pageLabelPdfStream,
firstPdfPath.toFile());
+
+ InputStream complexPdfStream = PdfTest.class.getResourceAsStream(
+ "/pdf-with-several-different-contents.pdf");
+ Path secondPdfPath = Files.createTempFile("secondPdf", ".pdf");
+ FileUtils.copyInputStreamToFile(complexPdfStream,
secondPdfPath.toFile());
+ byte[] bytesMergedPDF = RestAssured.given()
+ .queryParam("firstPdf", firstPdfPath.toString())
+ .queryParam("secondPdf", secondPdfPath.toString())
+ .post("/pdf/merge").then().statusCode(201)
+ .extract().asByteArray();
+
+ PDDocument doc = Loader.loadPDF(bytesMergedPDF);
+ PDFTextStripper pdfTextStripper = new PDFTextStripper();
+ String text = pdfTextStripper.getText(doc);
+ assertEquals(15, doc.getNumberOfPages());
+ assertTrue(text.contains("A shape"));
+
+ doc.close();
+ }
+
@Test
public void encryptDecrypt() throws IOException {
final String ownerPassword = "p4ssw0rd";
diff --git
a/integration-tests/pdf/src/test/resources/pdf-with-several-different-contents.pdf
b/integration-tests/pdf/src/test/resources/pdf-with-several-different-contents.pdf
new file mode 100644
index 0000000000..5f4b6b3e65
Binary files /dev/null and
b/integration-tests/pdf/src/test/resources/pdf-with-several-different-contents.pdf
differ
diff --git
a/integration-tests/pdf/src/test/resources/source-for-test-pdf-with-several-different-contents.odt
b/integration-tests/pdf/src/test/resources/source-for-test-pdf-with-several-different-contents.odt
new file mode 100644
index 0000000000..9040430565
Binary files /dev/null and
b/integration-tests/pdf/src/test/resources/source-for-test-pdf-with-several-different-contents.odt
differ
diff --git a/integration-tests/pdf/src/test/resources/test_pagelabels.pdf
b/integration-tests/pdf/src/test/resources/test_pagelabels.pdf
new file mode 100644
index 0000000000..149dbf7742
Binary files /dev/null and
b/integration-tests/pdf/src/test/resources/test_pagelabels.pdf differ