pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vincent DEREC <vincent.de...@kaliconseil.fr>
Subject Re: Added text does not appears in PDF document
Date Thu, 16 Feb 2017 19:38:18 GMT
It Works ! I'll read documentation (again) to understand this fifth parameter :-)

Thanks !



> Le 16 févr. 2017 à 20:14, Tilman Hausherr <THausherr@t-online.de> a écrit :
> 
> Try adding a fifth parameter (true) to PDPageContentStream.
> Tilman
> 
>> Am 16.02.2017 um 19:45 schrieb Vincent DEREC:
>> 
>> 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: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message