Calculation of TJ array values - pdf

Please tell us how you can calculate the values in the TJ array?
From the question
example:
1 0 0 1 0 188.28799438 cm
BT
/F2 11.04 Tf
1 0 0 -1 0 9.38000011 Tm
(Some)Tj ( )Tj
21.24200058 0 Td
(text)Tj ( )Tj
Which I want to turn into this:
1 0 0 1 0 188.28799438 cm
BT
/F2 11.04 Tf
1 0 0 -1 0 9.38000011 Tm
[(S)10(o)11(m)12(e)( )]TJ
21.24200058 0 Td
[(t)10(e)10(x)10(t)( )]TJ
How values are calculated(10) (11) (12) ?
so if I open any pdf and find THESE values there, how can I check them? how do they appear?

Related

Why is this vertical text positioning working?

The PDF content below renders with the correct vertical positions, but how?
1 0 0 -1 0 792 cm
q
.75 0 0 .75 72 192.75 cm
BT
/F4 14.666667 Tf
1 0 0 -1 0 .80265617 Tm
0 -13.2773438 Td <0030> Tj
12.2087708 0 Td <0024> Tj
8.6870575 0 Td <003C> Tj
9.7756042 0 Td <0032> Tj
11.4001007 0 Td <0035> Tj
ET
Q
q
.75 0 0 .75 72 222.75 cm
BT
/F4 14.666667 Tf
1 0 0 -1 4.0719757 .80265617 Tm
0 -13.2773438 Td <002C> Tj
4.0719757 0 Td <0003> Tj
4.0719757 0 Td <0057> Tj
4.0719757 0 Td <004B> Tj
8.1511078 0 Td <004C> Tj
3.2561493 0 Td <0051> Tj
8.1511078 0 Td <004E> Tj
ET
Q
Renders correctly:
MAJOR
I think
However I can't understand how the y positions are calculated to do this (x is fine). The Text Rendering Matrix (TRM) is given by Text Matrix (TM) multiplied by Current Transformation Matrix (CTM) PDF1.7 Reference section 9.4.4. CTM is the identity matrix multiplied by each "cm" operation.
So for the first snippet,
CTM = [1 0 0 -1 0 792] x [0.75 0 0 0.75 72 192.75] = [0.75 0 0 -0.75 72 786.75]
TRM is TM x CTM:
TRM = [1 0 0 -1 0 0.8026] x [0.75 0 0 -0.75 72 786.75] = [0.75 0 0 0.75 72 786.1]
So, ignoring small details, the text will be rendered around y = 786 (actually 776 I reckon)
For the second snippet,
CTM = [1 0 0 -1 0 792] x [0.75 0 0 0.75 72 222.75] = [0.75 0 0 -0.75 72 816.75]
TRM = [1 0 0 -1 4.072 0.802] x [0.75 0 0 -0.75 72 816.75] = [0.75 0 0 0.75 75.05 816.4]
Again, ignoring small details, the text will be rendered around y = 816 (actually 806 I reckon)
But the y origin is the bottom of the page, and 816 is greater than 786. So how come the second snippet of text renders correctly below the first? I'm clearly missing something in the calculations, but I can't see what. Any ideas?
The error in your calculations is that you apply the cm matrix by multiplication from the right side. You instead have to apply it from the left side.
I.e. for the first snippet you have
CTM = [0.75 0 0 0.75 72 192.75] ร— [1 0 0 -1 0 792] = [0.75 0 0 -0.75 72 599.25]
and for the second snippet
CTM = [0.75 0 0 0.75 72 222.75] ร— [1 0 0 -1 0 792] = [0.75 0 0 -0.75 72 569.25]
With these current transformation matrices the rendered result is to be expected.
If you wonder how you should have known that you need to multiply from the left side...
This result is true in general for PDF: when a sequence of transformations is carried out, the matrix representing the combined transformation (Mโ€ฒ) is calculated by premultiplying the matrix representing the additional transformation (MT) with the one representing all previously existing transformations (M):
๐‘€โ€ฒ = ๐‘€๐‘‡ ร— ๐‘€
(ISO 32000-2 section 8.3.4 "Transformation matrices")
Without going deep into matrices (not my forte, there is a slight error in my initial maths so images new corrected) you are working downwards from top left based on an inverted start point of 0 792 cm (Top Left corner)
The start of that snippet is above MAJOR 72 192.75 cm
Without outher transformations the text would be "UpsideDown" with M facing towards the bottom then the second 1 0 0 -1 mirrors it back upright and 0.8 "raises" it towards bottom so baseline is 193.5 ish from topleft at which point you "add" 0 -13.2773438 Td so the baseline is now about 205 from top left
Likewise, the origin for the second row is 72 222.75 cm down from above datum.
In both cases you placed their mirrored baseline even lower at 0 -13.2773438 Td thus both lines will be lower than shown above. In part due to the matrix inversions.
so here the second baseline is now at about 72 234 cm down from top left as subject to similar maths is roughly 222.75+.802+13.277 down but scale can also have effect.
Generally its best to use real time viewer of alterations (however this is not the best way just an example that by playing with rounded values I can see the effects).

CTM matrix multiplication with previous state vs with Identity matrix in PDF position parsing?

I gone through different solutions on CTM matrix calculations(someof them are this and this).
What I know about content stream is when "q " encounters we need to push identity matrix in a graphics_stack and keep multiply with next position operator(cm , Tm, Td, TD) CTM. When "Q" encounters we need to pop the last matrix.
For text positioning parsing when "BT" encounters push in identity matrix in position_stack and keep multiply with next position operator(cm , Tm, Td, TD) CTM. When "ET" encounters we need to pop the last matrix.
Here the some times we need to multiply with last CTM matrix and some times just multiply with identity matrix. When these cases are occurs?
Case 1:
From as shown in image 1 and 2 case merely replacement of new matrix from Td to Tm. And from 2 to 3 it's again last CTM multiplication. How I know?(By visually I can tell by looks)
Case 2:
In this case which how the matrix pushing and calculation will be there ?
Case 3:
BT
TT_1 20 Tf
35.56 150.24533 Td _______________ 1
(some sample text) Tj
50.526 250.36 Td ________________ 2
(second line new replace) Tj
0 -16.2 Td _____________________ 3
(Line end.) Tj
ET
This case 1 and 2 are merely replacement, 2 and 3 previous matrix multiplication. How do I know?
Case 4:
Please parse these positions at least till 10. The source file of this pdf
Case 5:
In above one need to calculate the l position. I highlighted with 1 to 4 numbers. I need to calculate the positions of each and every l How can do that? pdf
case6:
What is the change in calculation when the page(pdf) is rotated to 90 or 180 or 270 and 315 degrees?
These are some cases what I saw. What else might cases I can encounter and What is the generic approach to solve this ?
Operators of interest
First of all, I get the impression you mix up two different aspects. You have the current transformation matrix (CTM) and you have the text and text line matrices. The CTM is subject to cm, q, and Q. The text and text line matrices are subject to BT, Tm, Td, ... And to determine the exact position and direction of drawn text you need the product of text matrix and CTM at the time that text is drawn.
How those operators change the matrices, is described in the PDF specification, ISO 32000 part 1 or 2.
From ISO 32000-1 Table 57 โ€“ Graphics State Operators โ€“
cm: Modify the current transformation matrix (CTM) by concatenating the specified matrix
q: Save the current graphics state including the CTM on the graphics state stack
Q: Restore the graphics state including the CTM by removing the most recently saved state from the stack and making it the current state
From ISO 32000-1 Table 107 โ€“ Text object operators โ€“
BT: Begin a text object, initializing the text matrix, Tm, and the text line matrix, Tlm, to the identity matrix.
From ISO 32000-1 Table 108 โ€“ Text-positioning operators โ€“
tx ty Td: Move to the start of the next line, offset from the start of the current line by (tx, ty). More precisely, this operator shall perform these assignments:
a b c d e f Tm: Set the text matrix, Tm, and the text line matrix, Tlm:
Furthermore, TD, T*, ', and " operate on Tm and Tlm in a way specified using the Td operator.
From ISO 32000-1 section 9.4.4 โ€“ Text Space Details โ€“
Whenever a glyph is drawn, its entire transformation from text space may be represented by a text rendering matrix, Trm:
where Tfs is the current font size, Th is the current horizontal scaling factor, and Trise is the current text rise value.
After drawing that glyph, Tm is updated according to the glyph displacement
In horizontal mode tx is the displacement and ty is zero, in vertical mode tx is zero and ty is the displacement. The applicable value is calculated as
Example 1
In the following paragraphs I use rounded values to concentrate on the essentials.
The CTM starts as the Identity matrix, and as there is no cm operation here, it remains so all the time. Tm and Tlm on the other hand do change:
BT
Tm and Tlm are both set to the identity matrix
/GS0 gs
/T1_0 10 Tf
No change to Tm or Tlm.
317 65 Td
This multiplies a translation matrix as described above from the left to the former value of the Tlm and sets Tm and Tlm to the result:
1 0 0 1 0 0 1 0 0
T = T = 0 1 0 * 0 1 0 = 0 1 0
m lm 317 65 1 0 0 1 317 65 1
As that former value was the identity, this may look like a replacement by the Td translation matrix but it actually is a multiplication.
(F)Tj
This draws a glyph transformed by the text rendering matrix
10 ร— 1 0 0 1 0 0 1 0 0 10 0 0
T = 0 10 0 * 0 1 0 * 0 1 0 = 0 10 0
rm 0 0 1 317 65 1 0 0 1 317 65 1
Thereafter Tm is updated as described above. Unfortunately we don't have the widths of the font T1_0, so we cannot calculate the updated value.
1 0 0 1 370 87 Tm
This sets the text matrix, Tm, and the text line matrix, Tlm, to the given matrix:
1 0 0
T = T = 0 1 0
m lm 370 87 1
So now we know the current Tm value again.
-47 -22 Td
This multiplies a translation matrix as described above from the left to the former value of the Tlm and sets Tm and Tlm to the result:
1 0 0 1 0 0 1 0 0
T = T = 0 1 0 * 0 1 0 = 0 1 0
m lm -47 -22 1 370 87 1 323 65 1
[(igure)-251(2.3:)-621(P)16...] TJ
This draws the strings in the argument array with a starting text rendering matrix of
10 ร— 1 0 0 1 0 0 1 0 0 10 0 0
T = 0 10 0 * 0 1 0 * 0 1 0 = 0 10 0
rm 0 0 1 323 65 1 0 0 1 323 65 1
updating Tm again and again as described above.
Example 2
In the following paragraphs I use rounded values to concentrate on the essentials.
The CTM starts as the Identity matrix.
q
This saves the current graphics state, including the current CTM. As there is no Q operation in the example, though, we can ignore that for now.
.24 0 0 .24 91 740 cm
This updates the CTM by the given matrix:
0.24 0 0 1 0 0 0.24 0 0
CTM = 0 0.24 0 * 0 1 0 = 0 0.24 0
91 740 1 0 0 1 91 740 1
BT
Tm and Tlm are both set to the identity matrix
133 0 0 133 0 0 Tm
This sets the text matrix, Tm, and the text line matrix, Tlm, to the given matrix:
133 0 0
T = T = 0 133 0
m lm 0 0 1
/TT1.0 1 Tf
.002 Tc
No change to CTM, Tm, or Tlm.
[(The)1( )1(Long )1(Tai)1(l)]TJ
This draws the strings in the argument array with a starting text rendering matrix of
1 ร— 1 0 0 133 0 0 0.24 0 0 32 0 0
T = 0 1 0 * 0 133 0 * 0 0.24 0 = 0 32 0
rm 0 0 1 0 0 1 91 740 1 91 740 1
updating Tm again and again as described above.
Example 3
BT
TT_1 20 Tf
35.56 150.24533 Td _______________ 1
(some sample text) Tj
50.526 250.36 Td ________________ 2
(second line new replace) Tj
0 -16.2 Td _____________________ 3
(Line end.) Tj
ET
In the following paragraphs I use rounded values to concentrate on the essentials.
The CTM starts as the Identity matrix, and as there is no cm operation here, it remains so all the time. Tm and Tlm on the other hand do change:
BT
Tm and Tlm are both set to the identity matrix
TT_1 20 Tf
No change to Tm or Tlm.
36 150 Td
This multiplies a translation matrix as described above from the left to the former value of the Tlm and sets Tm and Tlm to the result:
1 0 0 1 0 0 1 0 0
T = T = 0 1 0 * 0 1 0 = 0 1 0
m lm 36 150 1 0 0 1 36 150 1
As that former value was the identity, this may look like a replacement by the Td translation matrix but it actually is a multiplication.
(some sample text) Tj
This draws glyphs transformed by the text rendering matrix
20 ร— 1 0 0 1 0 0 1 0 0 20 0 0
T = 0 20 0 * 0 1 0 * 0 1 0 = 0 20 0
rm 0 0 1 36 150 1 0 0 1 36 150 1
Thereafter Tm is updated as described above. Unfortunately we don't have the widths of the font TT_1, so we cannot calculate the updated value.
51 250 Td
This multiplies a translation matrix as described above from the left to the former value of the Tlm and sets Tm and Tlm to the result:
1 0 0 1 0 0 1 0 0
T = T = 0 1 0 * 0 1 0 = 0 1 0
m lm 51 250 1 36 150 1 87 400 1
So now we know the current Tm value again.
(second line new replace) Tj
This draws glyphs transformed by the text rendering matrix
20 ร— 1 0 0 1 0 0 1 0 0 20 0 0
T = 0 20 0 * 0 1 0 * 0 1 0 = 0 20 0
rm 0 0 1 87 400 1 0 0 1 87 400 1
Thereafter Tm is updated as described above. Unfortunately we don't have the widths of the font TT_1, so we cannot calculate the updated value.
0 -16 Td
This multiplies a translation matrix as described above from the left to the former value of the Tlm and sets Tm and Tlm to the result:
1 0 0 1 0 0 1 0 0
T = T = 0 1 0 * 0 1 0 = 0 1 0
m lm 0 -16 1 87 400 1 87 384 1
So now we know the current Tm value again.
(Line end.) Tj
This draws glyphs transformed by the text rendering matrix
20 ร— 1 0 0 1 0 0 1 0 0 20 0 0
T = 0 20 0 * 0 1 0 * 0 1 0 = 0 20 0
rm 0 0 1 87 384 1 0 0 1 87 384 1
Thereafter Tm is updated as described above. Unfortunately we don't have the widths of the font TT_1, so we cannot calculate the updated value.
Example 4
We discussed example 4 in your answer and the comments to it.
Example 5
q 0.1 0 0 0.1 0 0 cm
/R108 gs
0 g
q
...
Q
0 0 1 rg
q
...
Q
4.05 w
0 G
722.023 4082.13 m
722.023 4490.28 l
S
723.961 4488.25 m
2872.98 4488.25 l
S
404.1 w
0 0 0.199951 0 K
723.961 4284.18 m
2872.98 4284.18 l
S
4.05 w
0 G
720 4080.2 m
2876.94 4080.2 l
S
2874.91 4082.13 m
2874.91 4490.28 l
S
0 g
q
Why does your view of those instructions show the numbers inaccurately? The above is copy&pasted from the stream contents, there is no need to change the numbers like that...
q
0.1 0 0 0.1 0 0 cm
Sets the CTM to
0.1 0 0
CTM = 0 0.1 0
0 0 1
/R108 gs
...
0 G
Nothing happens to the CTM
722.023 4082.13 m
722.023 4490.28 l
S
We have to apply the CTM to these coordinates
0.1 0 0
[722.023 4082.13] * 0 0.1 0 = [72.2023 408.213]
0 0 1
0.1 0 0
[722.023 4490.28] * 0 0.1 0 = [72.2023 449.028]
0 0 1
Thus, a line is stroked from 72.2023,408.213 to 72.2023,449.028.
723.961 4488.25 m
2872.98 4488.25 l
S
Just like above, a line is drawn from 72.3961,448.825 to 287.298,448.825.
404.1 w
0 0 0.199951 0 K
723.961 4284.18 m
2872.98 4284.18 l
S
And again, a line is drawn from 72.3961,428.418 to 287.298,428.418. The only notable thing here is that the line is quite wide, ca. 40 units, so this "line" actually looks more like a filled rectangle and represents the background of the text box with the Lorentz force characterization.
4.05 w
0 G
720 4080.2 m
2876.94 4080.2 l
S
Another line is drawn, narrow again and, therefore, looking like a line, this time from 72,408.02 to 287.694 408.02.
2874.91 4082.13 m
2874.91 4490.28 l
S
And finally the last line, this time from 287.491,408.213 to 287.491,449.028.
Example 4 solution:
The CTM starts as the Identity matrix.
q
This saves the current graphics state (Graphics state = Identity ---- 1).
1 0 0 1 62.692 277.671 cm
This updates the CTM by the given matrix:
1 0 0 1 0 0 1 0 0
CTM = 0 0 0 * 0 1 0 = 0 1 0 ----- 2
62.692 277.67 1 0 0 1 62.692 277.67 1
CTM is updated to above result
q
push the CTM save to graphics state(Graphics state = 1, 2)
q
Again push the same CTM matrix to graphics state(Graphics state = 1, 2, 2)
1 0 0 1 286.59 207.54 cm
Update the CTM by current matrix.
1 0 0 1 0 0 1 0 0
CTM = 0 1 0 * 0 0 0 = 0 1 0 ----- 3
286.49 207.54 1 62.692 277.67 1 349.18 485.21 1
CTM updated to above result matrix.
q
push the CTM save to graphics state(Graphics state = 1, 2,2,3)
.75 .75 .75 RG
n
11.33 19.84 171.67 232.146 re
S
This will nothing change in position matrices.
Q
Assign the CTM to last available graphics state CTM = 3. Q will remove the last graphics state from graphics stack.(Graphics state = 1, 2,2)
1 0 0 1 17.007 23.52 cm
Update the CTM by current matrix.
1 0 0 0 1 0 0 1 0
CTM = 0 1 0 * 0 0 0 = 0 1 0 ----- 4
17.007 23.52 1 349.18 485.21 1 366.18 508.73 1
CTM updated to above result matrix.
q
push the last CTM to graphics state(Graphics state = 1, 2,2,4)
Skip rg, RG
BT
assign Tm and Tlm to Identity matrix.
1 0 0 1 0 5.6 Tm
This sets the text matrix, Tm, and the text line matrix, Tlm, to the given matrix:
1 0 0
T = T = 0 1 0
m lm 0 5.6 1
Tm and Tlm updated.
46.22 0 Td
Translate the matrix according to above Td matrix.
1 0 0 1 0 0 1 0 0
T = T = 0 1 0 * 0 1 0 = 0 1 0
m lm 46.22 0 1 0 5.6 1 46.22 5.6 1
update the Tm and Tlm with above matrix. Next Tf you can leave.
12 TL
This sets the graphics state leading text parameter, no direct influence on Tm or Tlm.
(William Shakespeare) Tj
This draws the string glyph-by-glyph, the first glyph transformed by this text rendering matrix
8 ร— 1 0 0 1 0 0 1 0 0 8 0 0
T = 0 8 0 * 0 1 0 * 0 1 0 = 0 8 0
rm 0 0 1 46.22 5.6 1 366.18 508.73 1 412.4 514.33 1
While the string is rendered glyph-by-glyph, Tm is updated as described in ISO 32000-1 section 9.4.4, and so is the Trm.
T*
As the text leading currently is 12, T* is equivalent to 0 -12 Td, so:
1 0 0 1 0 0 1 0 0
T = T = 0 1 0 * 0 1 0 = 0 1 0
m lm 0 -12 1 46.22 5.6 1 46.22 -6.4 1

My program reads PDF and try to find coordinate of each glyph in user space

it goes like this
q
0.1199951 0 0 0.1199951 0 0 cm
1 g
824 4101 267 389 re
f
Q
q
0.1199951 0 0 0.1199951 0 0 cm
1 g
824 4853 267 25 re
f
Q
q
0.1199951 0 0 0.1199951 0 0 cm
1 g
824 5241 267 25 re
f
Q
q
0.1199951 0 0 0.1199951 0 0 cm
1 g
1090 578 3081 1988 re
f
Q
q
0.1199951 0 0 0.1199951 0 0 cm
603 586 m
603 1800 l
649 1800 l
649 586 l
h
W n
8.3336724 0 0 8.3336724 0 0 cm
BT
/T1_0 5.04 Tf
0 1.0002 -1 0 76.8 70.32 Tm
(J)Tj
I want to ask what should be coordinate for J ?
My cropbox is 0 0 612 792 , Rotate value is 90.
So according to me
Th=1 default,
Tfs=5.04, from {/T1_0 5.04 Tf}
Trise=0 default,
teststatematrix
5.04 1 0
0 5.04 0
0 0 1
Tm
0 1.0002 0
-1 0 0
76.8 70.32 1
TRM = textstatematrix X Tm
-1 5.041 0
-5.040 0 0
76.800 70.320 1
So
[x,y,1] = [76.8, 70.32, 1] X TRM = [-354.413 457.469 1]
So x coordinate in user space is coming to be a negative number. Can you please Explain What mistake i am doing?
The matrix Trm calculated by the OP as
-1 5.041 0
-5.040 0 0
76.800 70.320 1
is the text rendering matrix described as follows in the PDF specification:
Conceptually, the entire transformation from text space to device space may be represented by a text rendering matrix, Trm:
(section 9.4.2, ISO 32000-1:2008)
The OP's mistake is not in calculating this matrix but in using it: This matrix contains the entire transformation from text space to device space,
Tj and other text-showing operators shall position the origin of the first glyph to be painted at the origin of text space.
(section 9.2.4 ISO 32000-1:2008)
and
The glyph origin is the point (0, 0) in the glyph coordinate system
(ibidem)
To determine, therefore, where the OP's
(J)Tj
puts the origin of the glyph J, one has to apply that matrix to the origin (0, 0), not to (76.8, 70.32) as the OP did.
Thus,
[x,y,1] = [0, 0, 1] X Trm = [76.8, 70.32, 1]
i.e. the coordinates of J are (76.8, 70.32) in device space. As the OP assumed the initial transformation matrix to have been the identity matrix, this device space essentially is the default user space.
Unfortunately the OP did not explain the coordinates in which coordinate system he is looking for. Thus, these coordinates probably are not the coordinates he was looking for.

(Manually Created) PDF is working fine on Ubuntu but its not working in windows?

I am trying to create a table in pdf using PDF codes . I have successfully created a table and its working fine in LinuX(Ubuntu) but when am trying to opening in windows its showing me an error message that "the file has been damaged".Here is my edited code,
%PDF-1.5
%รขรฃรร“
1 0 obj
<<
/PageLayout /OneColumn
/MarkInfo
<<
/Marked true
>>
/Outlines 2 0 R
/Lang <feff0045004e002d00550053>
/Pages 3 0 R
/StructTreeRoot 4 0 R
/Type /Catalog
>>
endobj
2 0 obj
<<
/First 5 0 R
/Type /Outlines
/Count 1
/Last 5 0 R
>>
endobj
3 0 obj
<<
/Kids [6 0 R]
/Type /Pages
/Count 1
>>
endobj
4 0 obj
<<
/ParentTree 7 0 R
/RoleMap 8 0 R
/ParentTreeNextKey 1
/K 9 0 R
/Type /StructTreeRoot
>>
endobj
5 0 obj
<<
/Title (Example table)
/Parent 2 0 R
/A 10 0 R
>>
endobj
6 0 obj
<<
/CropBox [0.0 0.0 612.0 792.0]
/Rotate 0
/StructParents 0
/Parent 3 0 R
/Resources
<<
/ColorSpace
<<
/CS1 11 0 R
/CS0 12 0 R
>>
/Font
<<
/TT2 13 0 R
/TT1 14 0 R
/TT0 15 0 R
>>
>>
/MediaBox [0.0 0.0 612.0 792.0]
/Type /Page
/Contents [16 0 R 17 0 R]
>>
endobj
9 0 obj
<<
/P 4 0 R
/K [18 0 R 19 0 R 20 0 R 21 0 R]
/S /Sect
>>
endobj
7 0 obj
<<
/Nums [0 22 0 R]
>>
endobj
8 0 obj
<<
/Subscript /Span
/Diagram /Figure
/Strikeout /Span
/Outline /Span
/DropCap /Figure
/InlineShape /Figure
/Footnote /Note
/Annotation /Span
/Underline /Span
/Superscript /Span
/Chart /Figure
/Endnote /Note
/TextBox /Art
>>
endobj
10 0 obj
<<
/D [6 0 R /XYZ 72 720 0.0]
/S /GoTo
>>
endobj
16 0 obj
<<
/Length 1991
>>
stream
BT
/H1 <</MCID 0 >>BDC
/CS0 cs 0.212 0.373 0.569 scn
/TT0 1 Tf
0.002 Tw 14.04 0 0 14.04 72 682.8 Tm
[(E)-3(x)4(a)-3(m)1(p)-1(le)10( t)6(a)-3(b)1(le)]TJ
0 Tw 6.496 0 Td
( )Tj
EMC
/P <</MCID 1 >>BDC
/CS1 cs 0 scn
/TT1 1 Tf
0.001 Tc -0.001 Tw 15.96 0 0 15.96 72 664.44 Tm
[(T)-1(hi)-3(s)1( )1(i)-3(s)1( )1(a)-1(n e)3(x)-2(a)-1(m)3(pl)-3(e)3( )-7(o)2(f)-2( )1(a)-1( da)-1(t)-2(a)-1( t)-2(a)-1(bl)-3(e)3(.)]TJ
0 Tc 0 Tw 13.789 0 Td
( )Tj
EMC
ET
/TH <</MCID 3 >>BDC
/CS0 cs 0.553 0.702 0.886 scn
84.84 632.64 76.68 14.88 re
f*
84.84 591.36 5.16 41.28 re
f*
156.36 591.36 5.16 41.28 re
f*
84.84 576.48 76.68 14.88 re
f*
EMC
/P <</MCID 4 >>BDC
90 618 66.36 14.64 re
f*
BT
/CS1 cs 0 scn
/TT2 1 Tf
0.004 Tc -0.004 Tw 12 0 0 12 90 621.24 Tm
[(D)4(is)3(a)8(b)1(il)10(it)1(y)8( )]TJ
ET
/CS0 cs 0.553 0.702 0.886 scn
90 591.36 66.36 26.64 re
f*
BT
/CS1 cs 0 scn
/TT2 1 Tf
-0.004 Tc 0.004 Tw 12 0 0 12 90 606.6 Tm
[(C)-5(at)-7(e)-1(go)-6(r)-9(y)]TJ
0 Tc 0 Tw ( )Tj
ET
EMC
/TH <</MCID 7 >>BDC
/CS0 cs 0.553 0.702 0.886 scn
162 625.32 71.76 22.2 re
f*
162 598.68 5.16 26.64 re
f*
228.6 598.68 5.16 26.64 re
f*
162 576.48 71.76 22.2 re
f*
EMC
/P <</MCID 8 >>BDC
167.16 598.68 61.44 26.64 re
f*
BT
/CS1 cs 0 scn
/TT2 1 Tf
0.003 Tc -0.003 Tw 12 0 0 12 167.16 613.92 Tm
[(P)5(a)7(r)-2(ti)-1(c)1(i)9(pa)7(nts)]TJ
0 Tc 0 Tw 4.95 0 Td
( )Tj
ET
EMC
/TH <</MCID 11 >>BDC
/CS0 cs 0.553 0.702 0.886 scn
234.24 632.64 71.52 14.88 re
f*
234.24 591.36 5.16 41.28 re
f*
300.6 591.36 5.16 41.28 re
f*
234.24 576.48 71.52 14.88 re
f*
EMC
/P <</MCID 12 >>BDC
239.4 618 61.2 14.64 re
f*
BT
/CS1 cs 0 scn
/TT2 1 Tf
0.004 Tc -0.004 Tw 12 0 0 12 239.4 621.24 Tm
[(B)5(a)8(llo)2(t)1(s)13( )]TJ
ET
/CS0 cs 0.553 0.702 0.886 scn
239.4 591.36 61.2 26.64 re
f*
BT
/CS1 cs 0 scn
/TT2 1 Tf
-0.003 Tc 0.003 Tw 12 0 0 12 239.4 606.6 Tm
[(C)-4(o)-5(mp)-6(l)-7(et)-6(ed)]TJ
0 Tc 0 Tw 4.55 0 Td
( )Tj
ET
EMC
endstream
endobj
17 0 obj
<<
/Length 707
>>
stream
/P <</MCID 42 >>BDC
q
84.84 550.56 76.68 25.44 re
W n
BT
/TT1 1 Tf
-0.001 Tc 0.001 Tw 11.04 0 0 11.04 90 565.56 Tm
[(Blin)2(d)]TJ
ET
Q
q
84.84 550.56 76.68 25.44 re
W n
BT
/TT1 1 Tf
11.04 0 0 11.04 112.56 565.56 Tm
( )Tj
ET
EMC
/P <</MCID 46 >>BDC
Q
q
162 550.56 71.76 25.44 re
W n
BT
/TT1 1 Tf
11.04 0 0 11.04 195.12 565.56 Tm
(5)Tj
ET
Q
q
162 550.56 71.76 25.44 re
W n
BT
/TT1 1 Tf
11.04 0 0 11.04 200.64 565.56 Tm
( )Tj
ET
EMC
/P <</MCID 50 >>BDC
Q
q
234.24 550.56 71.519 25.44 re
W n
BT
/TT1 1 Tf
11.04 0 0 11.04 267.24 565.56 Tm
(1)Tj
ET
Q
q
234.24 550.56 71.519 25.44 re
W n
BT
/TT1 1 Tf
11.04 0 0 11.04 272.76 565.56 Tm
( )Tj
ET
EMC
endstream
endobj
12 0 obj /DeviceRGB
endobj
11 0 obj /DeviceRGB
endobj
15 0 obj
<<
/BaseFont /Times-Roman
/Subtype /Type1
/Type /Font
/Encoding /WinAnsiEncoding
>>
endobj
14 0 obj
<<
/BaseFont /Helvetica
/Subtype /Type1
/Type /Font
/Encoding /WinAnsiEncoding
>>
endobj
13 0 obj
<<
/BaseFont /Courier
/Subtype /Type1
/Type /Font
/Encoding /WinAnsiEncoding
>>
endobj
18 0 obj
<<
/Pg 6 0 R
/P 9 0 R
/K 0
/S /H1
>>
endobj
19 0 obj
<<
/Pg 6 0 R
/P 9 0 R
/K 1
/S /P
>>
endobj
20 0 obj
<<
/P 9 0 R
/A 23 0 R
/K [24 0 R 25 0 R]
/S /Table
>>
endobj
21 0 obj
<<
/Pg 6 0 R
/P 9 0 R
/K 144
/S /P
>>
endobj
22 0 obj [18 0 R 19 0 R null 26 0 R 27 0 R null null 28 0 R 29 0 R null null 30 0 R 31 0 R null null null null null null null null null 24 0 R null null null null null null null null null null null null null null null null null null null 32 0 R null null null 33 0 R null null null 34 0 R null null null null null null null null null null null null null 25 0 R null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null 35 0 R null null null 36 0 R null null null 37 0 R null null null null null null null null null null null null null 38 0 R null null null null null null null null null null null null null null null null null null null null null null null null null 21 0 R]
endobj
23 0 obj
<<
/O /Layout
/Placement /Block
/BBox [84.11 446.51 545.89 648.25]
>>
endobj
24 0 obj
<<
/Pg 6 0 R
/P 20 0 R
/K [26 0 R 28 0 R 30 0 R]
/S /TR
>>
endobj
25 0 obj
<<
/Pg 6 0 R
/P 20 0 R
/K [39 0 R 40 0 R 41 0 R]
/S /TR
>>
endobj
38 0 obj
<<
/Pg 6 0 R
/P 20 0 R
/K [42 0 R 43 0 R 44 0 R]
/S /TR
>>
endobj
26 0 obj
<<
/Pg 6 0 R
/P 24 0 R
/K [27 0 R]
/S /TH
>>
endobj
27 0 obj
<<
/Pg 6 0 R
/P 26 0 R
/K 4
/S /P
>>
endobj
28 0 obj
<<
/Pg 6 0 R
/P 24 0 R
/K [29 0 R]
/S /TH
>>
endobj
29 0 obj
<<
/Pg 6 0 R
/P 28 0 R
/K 8
/S /P
>>
endobj
30 0 obj
<<
/Pg 6 0 R
/P 24 0 R
/K [11 31 0 R]
/S /TH
>>
endobj
31 0 obj
<<
/Pg 6 0 R
/P 30 0 R
/K 12
/S /P
>>
endobj
32 0 obj
<<
/Pg 6 0 R
/P 39 0 R
/K 42
/S /P
>>
endobj
33 0 obj
<<
/Pg 6 0 R
/P 40 0 R
/K 46
/S /P
>>
endobj
34 0 obj
<<
/Pg 6 0 R
/P 41 0 R
/K 50
/S /P
>>
endobj
35 0 obj
<<
/Pg 6 0 R
/P 42 0 R
/K 96
/S /P
>>
endobj
36 0 obj
<<
/Pg 6 0 R
/P 43 0 R
/K 100
/S /P
>>
endobj
37 0 obj
<<
/Pg 6 0 R
/P 44 0 R
/K 104
/S /P
>>
endobj
39 0 obj
<<
/P 25 0 R
/K 32 0 R
/S /TD
>>
endobj
40 0 obj
<<
/P 25 0 R
/K 33 0 R
/S /TD
>>
endobj
41 0 obj
<<
/P 25 0 R
/K 34 0 R
/S /TD
>>
endobj
42 0 obj
<<
/P 38 0 R
/K 35 0 R
/S /TD
>>
endobj
43 0 obj
<<
/P 38 0 R
/K 36 0 R
/S /TD
>>
endobj
44 0 obj
<<
/P 38 0 R
/K 37 0 R
/S /TD
>>
endobj xref
0 45
0000000000 65535 f
0000000015 00000 n
0000000190 00000 n
0000000263 00000 n
0000000322 00000 n
0000000430 00000 n
0000000500 00000 n
0000000849 00000 n
0000000889 00000 n
0000000775 00000 n
0000001130 00000 n
0000004027 00000 n
0000003999 00000 n
0000004203 00000 n
0000004130 00000 n
0000004055 00000 n
0000001190 00000 n
0000003237 00000 n
0000004274 00000 n
0000004329 00000 n
0000004383 00000 n
0000004460 00000 n
0000004516 00000 n
0000005296 00000 n
0000005384 00000 n
0000005461 00000 n
0000005615 00000 n
0000005678 00000 n
0000005733 00000 n
0000005796 00000 n
0000005851 00000 n
0000005917 00000 n
0000005973 00000 n
0000006029 00000 n
0000006085 00000 n
0000006141 00000 n
0000006197 00000 n
0000006254 00000 n
0000005538 00000 n
0000006311 00000 n
0000006362 00000 n
0000006413 00000 n
0000006464 00000 n
0000006515 00000 n
0000006566 00000 n
trailer
<<
/Root 1 0 R
/Size 45
>>
startxref
6616
%%EOF
Note: "opening in windows" is a non-statement. You cannot "open" a PDF in Windows, you need certain software to do so. Presumably, you tried using Acrobat Reader or something alike (the error message you quote is from Acrobat Reader).
It works in Mac OS X Preview, but then again that doesn't really tell us very much. Preview is written by Apple, and it's not a really conforming PDF reader (much to the dismay of anyone using, for example, transparency or color spaces). You did not provide an image of what your document is supposed to look like; is it anything like this?
But it does not open in Acrobat X.(a) Inspecting the PDF offsets -- the most likely place for an error -- I found the xref offsets are wrong from 11 0 obj onwards. This leads to a wrong offset of +89 bytes for all next objects, up to and including the ending startxref 6616, which IMO should be 6527.
I manually fixed the 34 wrong offsets by comparing the position of every X 0 obj with a hex editor, and saved with cr line endings. I got an error from my own inspecting tool:
The keyword stream that follows the stream dictionary should be followed by either a
carriage return and a line feed or by just a line feed, and not by a carriage return alone.
(PDF Reference 1.7, ยง3.2.7)
so I resaved with lf line endings. No errors, it shows correctly in Preview but still not in Acrobat X.
I noticed the /Length keys for objects 16 and 17, the Page Contents objects, were off as well. After correcting them to 1887 and 648, respectively, it still displays in Preview but still not in Acrobat X.
The problem appears to lie in these contents. Requesting for an Inventory shows the error message: "An error occurred while parsing a contents stream. Unable to analyze the PDF file.", and browsing the internal PDF structure I get to see a first handful of text formatting commands from 16 0 obj but they stop at the 15th command:
/CS1 cs 0 scn
and the next command, /TT1 1 Tf, never gets seen.
Ooo-kay. Checking the parameters for scn, I see their number depends on the color space set using cs; and there is your problem.
Both 11 0 obj and 12 0 obj set color spaces, and they both set it to /DeviceRGB. So the number of parameters for /CS1 (defined in 11 0 obj) is wrong -- you only supply one. It's safe to assume you meant this one to be /DeviceGray, and lo and behold, after that final change I got to see this in Acrobat X:
and a proper Inventory and fully browsable PDF structure.
There were lots of minor problems with this file, but the PDF format in itself is quite resilient. The bad offsets, and possibly the lengths, may have been silently corrected (the PDF specification allows that) but the bad parameters for the color space were killing it.
(a) Clarification after re-reading: it does open in Acrobat but silently shows a blank page only; no error message of any kind.
Addition
This made me think: was the /DeviceRGB the only cause of it failing in Acrobat X? No: after reloading the original PDF and changing just that one line, Acrobat says the file is damaged beyond repair. So all that extra checking I did wasn't for nothing, fortunately.

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
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)