You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Rob Bradley <ro...@ttlco.com> on 2009/08/04 02:38:00 UTC

Create PDF Text Color

How to add red text?

I have been struggling with formatting a new PDF.

It is simple text with some hyperlinks and is working fine.  

However, I need some of the text to be Red and I have not been able to figure out how to change the text color.

Can someone give me an example?

Thanks in advance!

Rob Bradley
MIS Manager
Truckee-Tahoe Lumber Co.
Email:  rob@ttlco.com
Phone:  (530) 582-2125
Mobile: (530) 308-6188
Fax:    (530) 582-2135



Create PDF Text Color

Posted by "Hesham G." <he...@gmail.com>.
Hi Rob ,
Please check this example :

- Ex: How to insert colorized text in the pdf :
	String file = "C:\\mypdf.pdf";	PDDocument 
pdfFile = PDDocument.load( file );	PDPage 
newPage = new PDPage();
	PDPageContentStream newPageData = new PDPageContentStream( pdfFile, 
newPage );  // This is our stream.

	newPageData.beginText();

	// Set the font settings :
		PDSimpleFont font = PDType1Font.TIMES_ITALIC;
		int fontSize = 18;		newPageData.setFont( 
 font, fontSize );
		newPageData.setNonStrokingColor( 49, 7, 241 );  // That's our target .. 
This changes the text color.

	newPageData.drawString( "This is blue text." );

--------------------------------------------------
From: "Rob Bradley" <ro...@ttlco.com>
Date: Tuesday, August 04, 2009 3:38 AM
To: <pd...@incubator.apache.org>
Subject: Create PDF Text Color

> How to add red text?
>
> I have been struggling with formatting a new PDF.
>
> It is simple text with some hyperlinks and is working fine.
>
> However, I need some of the text to be Red and I have not been able to 
> figure out how to change the text color.
>
> Can someone give me an example?
>
> Thanks in advance!
>
> Rob Bradley
> MIS Manager
> Truckee-Tahoe Lumber Co.
> Email:  rob@ttlco.com
> Phone:  (530) 582-2125
> Mobile: (530) 308-6188
> Fax:    (530) 582-2135
>
>