Hi all,
I'm using PDFBox 1.8.10 to add text to PDF documents.
It works fine except on some documents where text is added to document (checked
with pdf structure inspector) but not displayed in PDF.
I sample document is attached to this email.
Because I want to set some custom AlphaConstant to text (and rectangles), I'm
using Graphics State Parameter Dictionaries to add text.
Code used:
PDPageContentStream contentStream = new PDPageContentStream(pdfDoc, pdfPage,
true, true);
this.textGraphicState = new PDExtendedGraphicsState();
textGraphicState.setNonStrokingAlphaConstant(1f);
Map<String, PDExtendedGraphicsState> graphicsStatesMap =
pdfPage.getResources().getGraphicsStates();
if (graphicsStatesMap == null)
{
graphicsStatesMap = new HashMap<String, PDExtendedGraphicsState>();
}
graphicsStatesMap.put("textGraphicState", textGraphicState);
pdfPage.getResources().setGraphicsStates(graphicsStatesMap);
contentStream.appendRawCommands("/textGraphicState gs\n");
contentStream.setNonStrokingColor(fontColor);
contentStream.beginText();
contentStream.setFont( font, fontSize );
contentStream.moveTextPositionByAmount( pagePosX, pagePosY );
contentStream.drawString(text);
contentStream.endText();
contentStream.close();
Any idea ?
Thanks,
Vincent
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]