0

I have a problem printing a watermark on my pdf files. Normal text is working great, but as soon as a newline is included, the text after the newline simply disappears.

The text is coming from an textarea field in our WebApplication, and if I directly use the String with the \n included, the text after the newline disappears. In suggestions on stackoverflow I found a solution by using "Chunk.NEWLINE" but it changes nothing and the text still is gone.

// Phrase p = new Phrase(watermarkText, f);
String[] parts = watermarkText.split("\\n");
Paragraph para = new Paragraph();
for (int k = 0; k < parts.length; k++) {
    Phrase p = new Phrase("", f);
    p.add(parts[k]);
    p.add(Chunk.NEWLINE);
    para.add(p);
}

PdfGState gs1 = new PdfGState();
gs1.setFillOpacity(opacity);
over.setGState(gs1);
ColumnText.showTextAligned(over, Element.ALIGN_CENTER, para, x_position, y_position, rotation);

The splitting works great, I have exactly the 2 parts I wanted, but Chunk.NEWLINE changes nothing.

I'm using iText 5.5.0, I tried upgrading to 5.5.10 but that behaviour is still the same. If there are any known bugs, I haven't found them and if I am doing something wrong I simply don't see it.

I hope there is somebody out there who can help me.

Rubikan
  • 11
  • 1
  • 2
  • `ColumnText.showTextAligned` is a convenience method for drawing a single line of text. For multiple lines you either have to use that convenience method once per line or you instantiate, initialize and use a `ColumnText` instance yourself. – mkl Nov 18 '16 at 14:42
  • I have closed the question as a duplicate of a C# question. If you want the answer in Java, just change the uppercase of the first letter in the method names into a lowercase character (`setSimpleColumn()` instead of `SetSimpleColumn`, `addElement()` instead of `AddElement()`, `go()` instead of `Go()`). – Bruno Lowagie Nov 18 '16 at 16:51
  • Thanks mkl, that was the tip I needed! @BrunoLowagie Sorry, I seem to have overlocked the corresponding C# answerd. Thanks anyway! – Rubikan Nov 18 '16 at 17:20

0 Answers0