You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2024/12/05 09:04:03 UTC

(camel) branch camel-4.8.x updated: CAMEL-21506: ensure that PDF conversions work when using the file component

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch camel-4.8.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.8.x by this push:
     new 9edfca9544b CAMEL-21506: ensure that PDF conversions work when using the file component
9edfca9544b is described below

commit 9edfca9544b1989167fd650b82ac495c58c327d5
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Dec 3 14:31:24 2024 +0100

    CAMEL-21506: ensure that PDF conversions work when using the file component
---
 .../apache/camel/component/pdf/converter/PdfConverterLoader.java | 2 ++
 .../org/apache/camel/component/pdf/converter/PdfConverter.java   | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/components/camel-pdf/src/generated/java/org/apache/camel/component/pdf/converter/PdfConverterLoader.java b/components/camel-pdf/src/generated/java/org/apache/camel/component/pdf/converter/PdfConverterLoader.java
index 26ff3d42238..c4d21ae975d 100644
--- a/components/camel-pdf/src/generated/java/org/apache/camel/component/pdf/converter/PdfConverterLoader.java
+++ b/components/camel-pdf/src/generated/java/org/apache/camel/component/pdf/converter/PdfConverterLoader.java
@@ -46,6 +46,8 @@ public final class PdfConverterLoader implements TypeConverterLoader, CamelConte
     private void registerConverters(TypeConverterRegistry registry) {
         addTypeConverter(registry, org.apache.pdfbox.pdmodel.PDDocument.class, byte[].class, false,
             (type, exchange, value) -> getPdfConverter().convertToPDF((byte[]) value));
+        addTypeConverter(registry, org.apache.pdfbox.pdmodel.PDDocument.class, java.io.File.class, false,
+            (type, exchange, value) -> getPdfConverter().convertToPDF((java.io.File) value));
         addTypeConverter(registry, org.apache.pdfbox.pdmodel.PDDocument.class, java.io.InputStream.class, false,
             (type, exchange, value) -> getPdfConverter().toPDDocument((java.io.InputStream) value));
     }
diff --git a/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/converter/PdfConverter.java b/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/converter/PdfConverter.java
index 322b11176af..ef267794147 100644
--- a/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/converter/PdfConverter.java
+++ b/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/converter/PdfConverter.java
@@ -17,6 +17,8 @@
 
 package org.apache.camel.component.pdf.converter;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.InputStream;
 
 import org.apache.camel.Converter;
@@ -36,4 +38,11 @@ public class PdfConverter {
         final byte[] bytes = stream.readAllBytes();
         return convertToPDF(bytes);
     }
+
+    @Converter
+    public PDDocument convertToPDF(File file) throws Exception {
+        try (InputStream is = new FileInputStream(file)) {
+            return toPDDocument(is);
+        }
+    }
 }