Am 20.03.2022 um 19:48 schrieb Andy Czerwonka:
The language that I'm using is Scala, targeting Java 11.
I just transposed and simplified this example
<https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java?view=markup>,
which doesn't expressly close the content stream.
It does close the content stream, this is the try-with-resources syntax.
That's why I was asking, because I don't know if scala has a similar
syntax. You MUST close the content stream.
Binary attachments are blocked, please upload to a sharehoster. And take
care not to save to the file you were loading from.
Tilman
I've attached the corrupt file, which I just generated via
PDDocument.save.
On Sun, Mar 20, 2022 at 12:36 PM Tilman Hausherr
<thaush...@t-online.de> wrote:
How is it "corrupt"?
What is that programming language and does the "}" close the
content stream?
Tilman
Am 20.03.2022 um 19:26 schrieb Andy Czerwonka:
> I pull the latest 2.x version and am just playing around with
the API. I
> saw some examples, and was trying to add some text to each page.
>
> The following code creates a corrupt PDF. Wondering if anyone
can help me
> understand why.
>
> def addUser(user: UserData, is: InputStream): Try[PDDocument] =
Try {
> val doc = PDDocument.load(is)
> if (doc.isEncrypted) {
> throw new RuntimeException("We can't adjust the PDF if it's
encrypted")
> }
>
> val licensee = s"${user.name <http://user.name>} (${user.email})"
> doc.getPages.forEach { page =>
> val contentStream = new PDPageContentStream(doc, page,
AppendMode.APPEND,
> true, true)
> contentStream.beginText()
> contentStream.setFont(PDType1Font.HELVETICA_BOLD, 15.0f)
> contentStream.setNonStrokingColor(Color.red)
> contentStream.setTextMatrix(Matrix.getTranslateInstance(0, 0));
> contentStream.showText(licensee);
> contentStream.endText();
> }
>
> doc
> }
>
> Best,
>
> Andy
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail:users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail:users-h...@pdfbox.apache.org