Claus Ibsen created CAMEL-26054:
-----------------------------------
Summary: camel-pdf - the pageSize values of the catalog are
ignored, and pdf:create followed by pdf:extractText fails
Key: CAMEL-26054
URL: https://issues.apache.org/jira/browse/CAMEL-26054
Project: Camel
Issue Type: Bug
Components: camel-pdf
Affects Versions: 4.18.0, 4.22.0, 4.23.0
Reporter: Claus Ibsen
Fix For: 4.24.0
Found while adding the catalog body types of pdf (CAMEL-24961), checked with
{{camel run}}.
h4. 1. The pageSize values of the catalog are ignored
The catalog gives {{pageSize}} the values LETTER, LEGAL, A0 to A6 with the
default A4 ({{PdfConfiguration}}, main 5aac7df76b83, line 68), but the page
sizes are looked up by the internal names {{PAGE_SIZE_A0}} to
{{PAGE_SIZE_LETTER}} (lines 45-52, {{PAGE_MAP.get(pageSize)}} at line 146), and
LEGAL has none. So {{pageSize=A4}} gives null: PDFBox makes a U.S. Letter page,
and with {{textProcessingFactory=autoFormatting}} the create fails with a
{{NullPointerException}} at {{getPageSize().getWidth()}}
({{DefaultLineBuilderStrategy}}, line 118). Without pageSize the page is A4,
and the test uses {{pageSize=PAGE_SIZE_A1}}. Checked on 4.24.0-SNAPSHOT with
{{camel run}}: pageSize=A4 gave the media box 612 x 792 (Letter), no pageSize
595 x 842 (A4), pageSize=PAGE_SIZE_A5 an A5 page, and A4 with autoFormatting
the NullPointerException.
*Proposed change*: take the catalog values (LETTER, LEGAL, A0 to A6), and keep
the names such as {{PAGE_SIZE_A4}} working; fail for an unknown value.
h4. 2. pdf:create followed by pdf:extractText fails
create, append and merge leave the PDF in a {{ByteArrayOutputStream}}, which
does not convert to a {{PDDocument}}, so extractText gets null from
{{getBody(PDDocument.class)}} (line 129) and fails with {{NullPointerException:
Cannot invoke "org.apache.pdfbox.pdmodel.PDDocument.getPages()" because
"this.document" is null}}. Text and no body fail the same way. Checked on
4.24.0-SNAPSHOT with {{camel run}}: create then extractText failed; with a
{{convertBodyTo}} byte[] between them it gave the text.
*Proposed change*: leave a byte[] (or convert a ByteArrayOutputStream), and
fail with a message that names the body for a body that is not a PDF.
h4. 3. A CR or a tab fails with the default lineTermination
lineTermination, the default textProcessingFactory, splits the text on "\n"
only ({{LineTerminationWriterAbstractFactory}}, line 43), so text with Windows
line ends keeps the CR, and a tab stays too, and the font cannot show them.
Checked on 4.24.0-SNAPSHOT with {{camel run}}: "line one", CR LF, "line two"
failed with {{IllegalArgumentException: U+000D ('controlCR') is not available
in the font Helvetica, encoding: WinAnsiEncoding}}, a tab with U+0009; with
autoFormatting both worked.
*Proposed change*: split on any line end, and replace a tab and other control
characters.
h4. 4. create without a body fails with a NullPointerException
The body is read with {{getBody(String.class)}} (line 138), and no body fails
in the split with {{NullPointerException: Cannot invoke "String.split(String)"
because "text" is null}}. Checked on 4.24.0-SNAPSHOT with {{camel run}}.
h4. Also read in the code, not run
* The {{CamelPdfDecryptionMaterial}} header is documented as mandatory for an
encrypted document ({{PdfHeaderConstants}}, lines 35-40) but is not read
anywhere since CAMEL-11976.
* append closes the PDDocument of the {{CamelPdfDocument}} header (the
try-with-resources at line 106), so the header holds a closed document
afterwards.
* merge casts each element of {{CamelPdfFilesToMerge}} to {{java.io.File}}
(line 95): a String or a Path fails with a ClassCastException.
* The tests check nothing about the body: they send, then set
{{expectedMessagesMatches}}, which {{assertIsSatisfied}} does not run then (for
example PdfCreationTest).
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)