I need to put in
each page of my Pdf a text as background, using getUnderContent, I read in
archive that Illegal operation 'Tm' outside a text object is generated by a
wrong position in code but I don't understand where I have to put it, because I
don't have direct call to beginText and endText() . This error is generated just
if i try to write in underContent.
..............
Document document = new Document();
Document document = new Document();
try{
PdfWriter writer =
PdfWriter.getInstance(document, new
FileOutputStream(namePdf));
Phrase p = null;
document.open();
Font courier8 = new Font(Font.COURIER,
8);
Font courier8b = new Font(Font.COURIER, 8);
courier8b.setStyle(Font.BOLD);
bf= BaseFont.createFont("c:\\windows\\fonts\\arialuni.ttf", BaseFont.IDENTITY_H, true);
Font courier8b = new Font(Font.COURIER, 8);
courier8b.setStyle(Font.BOLD);
bf= BaseFont.createFont("c:\\windows\\fonts\\arialuni.ttf", BaseFont.IDENTITY_H, true);
Chunk c = new Chunk(riga_norm, courier8);//riga_norm is a string
Chunk cb = new Chunk(riga_bold, courier8b);//riga_bold is a string
p = new Phrase(10,
"");
p.add(cb);
p.add(c);
p.add(cb);
p.add(c);
if (newPage){
document.newPage();
/////////////////////////////////////////////////////////////////////part
that produce the error
PdfContentByte under = writer.getDirectContentUnder();
under.setColorFill(new Color(220, 220, 220));
under.setFontAndSize(bf, 36);
under.showTextAligned(Element.ALIGN_LEFT, "TEXT", 50, 50, 55);
under.fill();
////////////////////////////////////////////////////////////////////
PdfContentByte under = writer.getDirectContentUnder();
under.setColorFill(new Color(220, 220, 220));
under.setFontAndSize(bf, 36);
under.showTextAligned(Element.ALIGN_LEFT, "TEXT", 50, 50, 55);
under.fill();
////////////////////////////////////////////////////////////////////
}
else
document.add(new Paragraph(p));
else
document.add(new Paragraph(p));
}
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
document.close();
.......................
Best
regards
Achille
Salerni
