Pdf setting the font color to the text

孤街醉人 提交于 2019-12-10 10:01:37

问题


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


回答1:


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)



来源:https://stackoverflow.com/questions/15241337/pdf-setting-the-font-color-to-the-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!