Reputation: 29
I have a tool that generates pdf files. For some reason, Adobe gives me "An error exists on this page" so I simplified the pdf and it seems like the problem comes from the (x, y) l paths in a stream. But I can not find exactly what is the issue.
As you can see in the following images, simply by removing some path parts, the documents becomes valid. Of course I make the necessary changes of offsets when I make this changes in code. Note that the 3 paths that I will mention below are the ones between (x,y) m and (x,y) h at the beginning of the stream.
Take a look at the following examples:
Original stream - Not working
stream
q
1991.040 1277.520 m
1991.040 583.681 l
1052.640 583.681 l
1052.640 578.521 l
1052.040 578.521 l
1052.040 532.321 l
1127.880 532.321 l
1127.880 533.159 l
1187.880 533.159 l
1187.880 532.321 l
1206.720 532.321 l
1206.720 532.922 l
1211.880 532.922 l
1211.880 572.040 l
1615.800 572.040 l
1615.800 532.922 l
1621.080 532.922 l
1621.080 532.321 l
1639.800 532.321 l
1639.800 533.159 l
1699.800 533.159 l
1699.800 532.321 l
1778.160 532.321 l
1778.160 532.922 l
1783.440 532.922 l
1783.440 572.040 l
1981.440 572.040 l
1981.440 522.960 l
1989.840 522.960 l
1989.840 522.361 l
2002.680 522.361 l
2002.680 597.959 l
2051.760 597.959 l
2051.760 605.882 l
2002.680 605.882 l
2002.680 752.159 l
2054.280 803.760 l
2054.399 804.000 l
2016.000 842.400 l
2010.120 842.400 l
2010.120 841.802 l
2004.360 841.802 l
2004.360 851.161 l
2002.680 851.161 l
2002.680 1009.679 l
2004.360 1009.679 l
2004.360 1017.600 l
2002.680 1017.600 l
2002.680 1164.000 l
2054.399 1215.720 l
2004.960 1265.160 l
2004.840 1265.160 l
2004.840 1272.240 l
2004.360 1272.240 l
2004.360 1277.520 l
1991.040 1277.520 l
h
2019.720 1218.600 m
2019.360 1218.480 l
2019.000 1218.360 l
2018.880 1218.240 l
2018.640 1218.120 l
2018.520 1218.000 l
2018.280 1217.880 l
2018.040 1217.400 l
2017.920 1217.280 l
2017.560 1216.560 l
2017.440 1215.720 l
2017.560 1215.600 l
2017.560 1214.880 l
2017.680 1214.880 l
2017.680 1214.640 l
2017.800 1214.640 l
2017.800 1214.400 l
2017.920 1214.400 l
2017.920 1214.160 l
2018.040 1214.160 l
2018.040 1213.920 l
2018.160 1213.920 l
2018.160 1213.680 l
2018.280 1213.680 l
2018.280 1213.440 l
2018.520 1213.440 l
2018.640 1213.320 l
2018.880 1213.200 l
2019.000 1213.080 l
2019.720 1212.840 l
2021.280 1212.720 l
2021.280 1212.840 l
2022.000 1213.080 l
2022.240 1213.200 l
2022.720 1213.680 l
2022.840 1213.920 l
2022.960 1214.040 l
2023.080 1214.280 l
2023.320 1215.000 l
2023.440 1216.440 l
2023.320 1216.440 l
2023.320 1216.800 l
2023.200 1216.800 l
2023.200 1217.160 l
2023.080 1217.160 l
2023.080 1217.400 l
2022.240 1218.240 l
2022.000 1218.360 l
2021.280 1218.600 l
2019.720 1218.600 l
h
2017.200 809.282 m
2016.840 809.158 l
2016.480 809.042 l
2016.120 808.681 l
2015.880 808.561 l
2015.760 808.321 l
2015.400 807.959 l
2015.280 807.600 l
2015.160 807.360 l
2015.040 806.401 l
2015.160 806.280 l
2015.160 805.560 l
2015.280 805.560 l
2015.280 805.202 l
2015.400 805.202 l
2015.400 804.841 l
2015.520 804.841 l
2015.880 804.480 l
2015.880 804.240 l
2016.120 804.240 l
2016.480 803.880 l
2017.200 803.522 l
2018.760 803.402 l
2018.760 803.522 l
2019.120 803.642 l
2019.600 803.880 l
2020.440 804.720 l
2020.920 805.682 l
2021.040 807.122 l
2020.920 807.122 l
2020.920 807.360 l
2020.800 807.360 l
2020.800 807.600 l
2020.680 807.600 l
2020.680 807.840 l
2020.560 807.840 l
2020.560 808.080 l
2019.720 808.921 l
2019.480 809.042 l
2018.760 809.282 l
2017.200 809.282 l
h
0.235 0.000 0.000 0.235 0.000 0.000 cm
1.000 g
4465.690 2217.310 m
8720.500 2217.310 l
8720.500 5422.810 l
4465.690 5422.810 l
4465.690 2217.310 l
h
W
n
f
Q
q
0.000 0.000 m
3456.000 0.000 l
3456.000 0.359 l
0.000 0.359 l
0.000 0.000 l
h
W
n
0.235 0.000 0.000 0.235 0.000 0.000 cm
1 J
1 j
10.000 M
1.528 w
0.000 G
14669.500 0.000 m
0.000 0.000 l
S
Q
q
0.351 0.000 0.000 0.359 3370.650 600.986 cm
29 0.00 0.00 -1 0.000 1.000 cm
/Im1 Do
Q
q
1.000 0.000 0.000 -1.000 3176.000 2155.000 cm
275 0.00 0.00 -51 0.000 51.000 cm
/Im2 Do
Q
endstream
Simplified all 3 blocks of paths - Works
stream
q
1991.040 1277.520 m
1991.040 583.681 l
1991.040 1277.520 l
h
2019.720 1218.600 m
2019.360 1218.480 l
2019.720 1218.600 l
h
2017.200 809.282 m
2016.840 809.158 l
2017.200 809.282 l
h
0.235 0.000 0.000 0.235 0.000 0.000 cm
1.000 g
4465.690 2217.310 m
8720.500 2217.310 l
8720.500 5422.810 l
4465.690 5422.810 l
4465.690 2217.310 l
h
f
Q
q
0.000 0.000 m
3456.000 0.000 l
3456.000 0.359 l
0.000 0.359 l
0.000 0.000 l
h
W
n
0.235 0.000 0.000 0.235 0.000 0.000 cm
1 J
1 j
10.000 M
1.528 w
0.000 G
14669.500 0.000 m
0.000 0.000 l
S
Q
q
0.351 0.000 0.000 0.359 3370.650 600.986 cm
29 0.00 0.00 -1 0.000 1.000 cm
/Im1 Do
Q
q
1.000 0.000 0.000 -1.000 3176.000 2155.000 cm
275 0.00 0.00 -51 0.000 51.000 cm
/Im2 Do
Q
endstream
I will not post all the samples but they work as follow:
Note: The last case makes me think that maybe there is a problem with the number of (x,y) lines. Like a max number of them allowed.
It you need the sample files: PDF Samples
Upvotes: 0
Views: 760
Reputation: 96064
Actually there are errors both in the full and in the simplified version of your stream:
You change the current transformation matrix and the fill color during the definition of the path:
...
h
0.235 0.000 0.000 0.235 0.000 0.000 cm
1.000 g
4465.690 2217.310 m
...
That is not allowed. After starting defining a path, only path definition instructions are allowed until an optional path clipping instruction and the path drawing instruction.
(Only in the full stream) You apply two path drawing instructions in sequence:
n
f
This is not allowed. After a path drawing instruction the path is gone. Before the next path drawing instruction you need to define a new path.
I don't know whether fixing these issues will make your pdf work. To allow checking that you have to share the pdfs in question.
As an aside... after opening both variants in Adobe Acrobat you say
simply by removing some path parts, the documents becomes valid.
This doesn't follow. Acrobat is very tolerant in respect to errors. If Acrobat doesn't complain about a pdf and displays it as you expected, that doesn't mean the pdf is valid. To ensure validity you have to check your pdf against the pdf specification.
After you shared the PDFs I ran the full PDF through Adobe Preflight (Profile "Report PDF syntax issues"). It reports the warnings
Invalid content stream state for operator (1 match on 1 page)
This occurs at the cm and g operators I already pointed out to be invalid above.
Unbalanced q and Q operators (1 match on 1 page)
Unused operands at end of content stream analysis (1 match on 1 page)
This took some more inspection. Eventually it turned out that the Length property of your stream is to small. You use 3329 but it's actually about 3393
After removing the invalid operators and fixing the stream length, this preflight profile (of my old Acrobat 9.5) doesn't find an issue anymore. Nonetheless Adobe Reader still is not happy with the PDF...
Some more attempts...
/Im1 Do
and /Im2 Do
, Adobe is happy. Apparently there are the issues in them, too.Upvotes: 1