Search code examples
pdfpdfbox

While replacing formXobjects in to content stream I am loosing Font size?


This question may further discussion to this.

My initial formXobject is like below.

enter image description here

And it looks visually

enter image description here

After I try to replace the "/Meta98 Do " with Xobject content stream it looks like this.

enter image description here

The content Stream for this new file you can check here.

Before changing file is here

I think I am losing the Tf properties. How to replace the formxobject contents without loosing font size?


Solution

  • You forgot to take the XObject Matrix into account.

    In the original PDF a form XObject is used on your page:

    q
    0.25 0 0 0.42986 189.16 132.44 cm
    /Meta98 Do
    Q
    

    and you simply replaced the /Meta98 Do by the contents from XObject (enveloped in q..Q and with tags):

    q
    0.25 0 0 0.42986 189.16 132.44 cm
    /Formula <</MCID  74  >> BDC
    /F3_Fm0 11.04 Tf
    q
    0.51317 w 
    ...
    [(X)  ]TJ
    EMC
    ET
    Q
    Q 
    

    What you forgot, though, is taking the Matrix entry of the form XObject into account:

    55 0 obj
    <</BBox[0 0 18.425 31.89]/Filter/FlateDecode/Length 158/Matrix[3.9077 0 0 2.2578 0 0]/Resources<</Font<</F3 62 0 R/F4 65 0 R>>>>/Subtype/Form/Type/XObject>>stream
    ...
    

    This matrix has to applied here, too:

    q
    0.25 0 0 0.42986 189.16 132.44 cm
    % concatenate the former XObject Matrix:
    3.9077 0 0 2.2578 0 0 cm
    /Formula <</MCID  74  >> BDC
    /F3_Fm0 11.04 Tf
    q
    0.51317 w 
    ...
    [(X)  ]TJ
    EMC
    ET
    Q
    Q