Home > front end >  PDF sourcecode of text with tab/tabstop or fixed width trick
PDF sourcecode of text with tab/tabstop or fixed width trick

Time:09-22

I have this s variable string: ID#9NAME#9VALUE

How this string look like in PDF? (ID) Tj (NAME) Tj (VALUE) Tj

I have to convert the s variable to PDF string. How can I change the #9 character to a working tabstop character? I can change the #9 character to 7 pieces of #20, but it is not good for me, because I and W are different widths.

Is there a trick? Like horizontal spacing in percent?

(ID) Tj

some code that spacing 100 horizontal pixels

(NAME) Tj

some code that spacing 100 horizontal pixels

(VALUE) Tj

CodePudding user response:

Your #9 seems to be ^09 i.e. (HT)

That should be x09 in (Base 16 / hex.) or \011 (base 8) or \t in literal string

IF defined like that in a base font, then you should be able to insert that.

(ID\t\tNAME\t\tVALUE) TJ

enter image description here

or

(ID\011\011NAME\011\011VALUE) Tj

However as pointed out by @mkl those were traditional mechanical printer carriage stops that could be set ON at 4 or 8 characters from line left or anything the printer operator chose to place indents or columns. Thus in a Word Processor are highly variable in number and position. But in a PDF are usually ignored.

In PDF it is more conventional to set each block of characters at a new x,y position, where y is constant for each text block at that elevation.

So for a tab stop approach with tabs at one inch (based on default 1 unit =1/72") try this

stream
q

BT
/F1 12 Tf
1 0 0 1 144 720 Tm
(ID) Tj
ET

BT
/F1 12 Tf
1 0 0 1 216 720 Tm
(NAME) Tj
ET

BT
/F1 12 Tf
1 0 0 1 288 720 Tm
(VALUE) Tj
ET
Q

endstream

Remember in PDF all whitespace is equal, but some is more so than others.

so here find id name value accepts the non existent tabs as a single white space:-

enter image description here

Finally to answer your query you can set fixed space from the start of a text to the start of another just like tab stops using TD

enter image description here

0 0 TD (ID) Tj
100 0 TD (NAME) Tj
100 0 Td (VALUE) Tj
  • Related