Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pdf setting the font color to the text

I am trying to add some text to a pdf file manually.I was able to add new text with a specific font. But i am not able to set the font color. So how can i do it manually? (I just want to change these manually as i already have the code where i write these byte to make the pdf file) Also how can i use graphic states specified in the pdf standard to manipulate the text so that feature changes does not affect the color changes etc.How exactly i can use the graphic state?

Source pdf file click here Modified pdf file clcik here

like image 287
IT researcher Avatar asked Dec 20 '22 08:12

IT researcher


1 Answers

The PDF color operators are listed in Table 74 of the PDF specification ISO 32000-1:2008.

In your case your added content stream is

104 0 obj
<</Length 105 0 R>>stream
  /Helv 8 Tf
  BT
  1 0 0 1 15.67 150 Tm
  (l)Tj
  ET
  /Helv 8 Tf
  BT
  1 0 0 1 17.88 190 Tm
  (abcdefghijklmnopqr)Tj
  ET
endstream
endobj 

If e.g. you want the writing to be filled with red in a RGB color space, you add an 1 0 0 rg:

104 0 obj
<</Length 105 0 R>>stream
  BT
  1 0 0 1 15.67 150 Tm
  /Helv 8 Tf
  1 0 0 rg
  [...]

EDIT

If you are afraid that that change may affect later text, remember to use the Graphics State Stack operators q and Q (cf. section 8.4.2 of the PDF specification). E.g.

q
0 1 -1 0 595.22 0 cm
q
BT
1 0 0 1 36 540 Tm
/Xi0 12 Tf
0.75 g
(Hello people!)Tj
0 g
ET
Q
Q

(Copied from How to add text object to existing pdf)

like image 174
mkl Avatar answered Jan 17 '23 23:01

mkl