pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vincent DEREC <vincent.de...@kaliconseil.fr>
Subject Added text does not appears in PDF document
Date Thu, 16 Feb 2017 18:45:53 GMT
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


Mime
View raw message