views:

241

answers:

1

I'm creating a dynamically generated PDF using FPDF.

My PDF requires many exactly horizontal/vertical lines in a grid and when rendered they are anti-aliased and look very fuzzy and unacceptable to the client. I need to remove the anti-aliasing for these(or all) lines in the doc.

I know this is possible because it's shown correctly in the adobe pdf specs itself http://www.adobe.com/devnet/acrobat/pdfs/PDF32000_2008.pdf (warning: big file) see the box in page 2 for how this should look.

How would I duplicate the box shown on this page?

-- EDIT --

%PDF-1.6
3 0 obj
<</Type /Page
/Parent 1 0 R
/Resources 2 0 R
/Contents 4 0 R>>
endobj
4 0 obj
<</Length 44>>
stream
2 J
1.00 w
20.00 821.89 m 200.00 821.89 l S

endstream
endobj
1 0 obj
<</Type /Pages
/Kids [3 0 R ]
/Count 1
/MediaBox [0 0 595.28 841.89]
>>
endobj
2 0 obj
<<
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
/Font <<
>>
/XObject <<
>>
>>
endobj
5 0 obj
<<
/Producer (FPDF 1.6)
/CreationDate (D:20100311190240)
>>
endobj
6 0 obj
<<
/Type /Catalog
/Pages 1 0 R
/OpenAction [3 0 R /FitH null]
/PageLayout /OneColumn
>>
endobj
xref
0 7
0000000000 65535 f 
0000000179 00000 n 
0000000266 00000 n 
0000000009 00000 n 
0000000087 00000 n 
0000000360 00000 n 
0000000435 00000 n 
trailer
<<
/Size 7
/Root 6 0 R
/Info 5 0 R
>>
startxref
538
%%EOF

This is a very simple PDF file that draws a single line showing the issue I'm having. I've figured out that the trick is to add this:

/Type /ExtGState
/SA false

But I can't get it to work yet. SA is defined in 10.6.5 in the above PDF specs

+1  A: 

I don't have the exact answer, but I have and idea that's a bit more than a comment...

Since you are already comfortable with the PDF specs, here's what you should try:

Figure out how fpdf is actually drawing those lines. Chances are the pdf file it outputs is compressed, so you should download pdftk to uncompress it. You would do that with the command:

 pdftk fpdf_output.pdf output fdf_readable.pdf uncompress

Open up the pdf in a text editor and see if the lines are drawn the same way as the example in the PDF specs you are looking at.

If they are not, see if the method fpdf uses to draw the lines has an anti-aliasing option (in the PDF specs, I mean). If fpdf is drawing it the same way (or if their way has the option), try changing your output document (in the text editor) to have the anti-aliasing turned off. If the document won't open after editing it in the text-editor, you can run:

 pdftk fdf_readable.pdf output fdf_fixed.pdf

and it should fix any broken references or byte counts.

Then open up your tweaked pdf to see if it looks like what you are going after.

Here's the bad news: The only thing the above accomplishes is verifying that anti-aliasing is or isn't possible via the methods fpdf is using under the hood. If it is possible, there is some hope that the feature already exists or that you can make a feature request or if you are feeling really confident, you could try to extend fpdf to include some kind of antialias("true|false") method. If the method they use to draw the lines is not the same as the specs and doesn't have an option to turn off anti-aliasing, your best bet is probably to find an alternative pdf generator, like tcpdf, and seeing if they offer that feature.

Update

Okay, I'd like to first point out that I still don't see the fuzziness. So I can't tell if this actually fixes your issue. But I did add the Automatic Stroke Adjustment rule to your example and the PDF still opens.

In the interest of not posting the entire PDF again, here's how you can update your sample code:

.........
/Font <<
>>
/XObject <<
>>

//Start my edit right below this point in your example, so at line 31, add:

/ExtGState << /GS1 10 0 R
>>
>>
endobj
10 0 obj
<<
/Type /ExtGState
/SA true
/TR 11 0 R
>>
endobj
31 0 obj
<< /FunctionType 0
/Domain [0.0 1.0]
/Range [0.0 1.0]
/Size 2
/BitsPerSample 8
/Length 7
/Filter /ASCIIHexDecode
>>
stream
01 00 >
endstream
endobj
// Your code picks back up with:

5 0 obj
<<
/Producer (FPDF 1.6)

Basically all I've done is added a dictionary object reference to the main resource dictionary and then created the actual dictionary object with the stroke adjustment rule set to true. I also threw in the transfer function that the spec example has, because i'm not sure if that makes a difference. It can easily be taken out.

Anthony
I'm almost positive that the TR is not required here. I've tried it both ways and it doesn't seem to make a difference and I was able to find a working example without it. I've tried the exact same thing as you've suggested in every way imaginable but it's just not working. I'm missing something subtle here and I'll figure it out but I'm getting the feeling it's beyond the scope of this question. I'm marking this sucker as done. THANK YOU for your time/help on this Anthony.
Travis