1

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

peteri77
  • 15
  • 3
  • 1
    One remark: that wouldn't be like one usually uses horizontal TABs: usually one does not see them as creating a *gap of constant size* but as jumping to the next fixed TAB STOP position. Are you sure your unusual interpretation corresponds to the requirements of your project? – mkl Sep 21 '21 at 14:58
  • mkl: yes, I want to tab stop position. I expressed myself wrong. I do not want a gap of constant size because it will equal with 7 pieces of space character. I wanted to know how can I add spacing, and I am able to calculate the correct pixel number deppend on the length of the words. – peteri77 Sep 22 '21 at 06:55
  • As commented to @KJ's answer, I'd use his last approach for that, even though it means not being able to use **T\***. Alternatively you can use **TJ** but then you'd have to start calculating actual widths of drawn strings, and you appear tp prefer not having to do *that*. – mkl Sep 22 '21 at 10:28

1 Answers1

1

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. Note I had intentionally used TD and Td mixed to show it does not matter in such cases :-), however the Human readable convention is to use CAPS for the Object (Noun) and lowercase the "action" (Verb) so Td is better for debugging by eye.

enter image description here

This can be written as suggested by @mkl (with me adding a start point)

50 800 Td (ID) Tj 100 0 Td (NAME) Tj 100 0 Td (VALUE) Tj

In comments you asked about adding lines and the simplest, for line by line loop programming, is to use something like this. (In this case skipping 780) and contra my above comment BT and ET are usually both CAPS.

BT 50 800 Td (ID) Tj 100 0 Td (NAME) Tj 100 0 Td (VALUE) Tj ET
BT 50 760 Td (A1) Tj 100 0 Td (Example) Tj 100 0 Td (2000) Tj ET
BT 50 740 Td (B2) Tj 100 0 Td (Another) Tj 100 0 Td (1000) Tj ET

enter image description here

K J
  • 8,045
  • 3
  • 14
  • 36
  • 1
    The last variant (`(ID) Tj 100 0 Td (NAME) Tj 100 0 Td (VALUE) Tj`) is the one i had on my mind first when i wrote my comment. ;) – mkl Sep 22 '21 at 04:49
  • Yes, I tried replacing #9 to \t or \011, but PDF ignored then I read elsewhere that it did not go. I will try today your codes. Thanks. – peteri77 Sep 22 '21 at 07:03
  • Now I have some problem with the next line, so the s string is: ID#9NAME#9VALUE#13#10#A1#9EXAMPLE#92000 PDF is: 0 0 TD (ID) Tj 100 0 TD (NAME) Tj 100 0 TD (VALUE) Tj T* 0 0 TD (A1) Tj 100 0 TD (EXAMPLE) Tj 100 0 TD (2000) Tj But the second line is starting when the first line end :( – peteri77 Sep 22 '21 at 07:46
  • 1
    @peteri77 *"But the second line is starting when the first line end"* - As soon as you start using **Td** or **TD** for tabbing, you cannot sensibly use **T\*** for line feeding anymore. Instead use a **Td** that in x direction undoes the shifts for the TABs and in y direction goes down one line. – mkl Sep 22 '21 at 10:29