PDF 禁用行上的抗锯齿功能

发布于 2024-08-24 15:57:15 字数 1429 浏览 2 评论 0原文

我正在使用 FPDF 创建动态生成的 PDF。

我的 PDF 需要在网格中使用许多完全水平/垂直的线,并且在渲染时它们是抗锯齿的,并且看起来非常模糊并且对客户来说是不可接受的。我需要删除文档中这些(或所有)行的抗锯齿功能。

我知道这是可能的,因为它在 adobe pdf 规范本身中正确显示 http://www.adobe.com/devnet/acrobat/pdfs/PDF32000_2008。 pdf(警告:大文件) 请参阅第 2 页中的方框了解其外观。

我如何复制此页面上显示的框?

-- 编辑 --

%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

这是一个非常简单的 PDF 文件,它绘制了一条线来显示我遇到的问题。我发现诀窍是添加这个:

/Type /ExtGState
/SA false

但我还无法让它工作。 SA在上述PDF规范的10.6.5中定义

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

看海 2024-08-31 15:57:15

我没有确切的答案,但我认为这不仅仅是一条评论......

既然您已经对 PDF 规范感到满意,那么您应该尝试以下操作:

弄清楚 fpdf 实际上是如何绘制这些线条的。它输出的 pdf 文件很可能是压缩的,因此您应该下载 pdftk 来解压缩它。您可以使用以下命令来执行此操作:

 pdftk fpdf_output.pdf output fdf_readable.pdf uncompress

在文本编辑器中打开 pdf,然后查看线条的绘制方式是否与您正在查看的 PDF 规范中的示例相同。

如果不是,请查看 fpdf 用于绘制线条的方法是否具有抗锯齿选项(我的意思是在 PDF 规范中)。如果 fpdf 以相同的方式绘制它(或者如果他们的方式有选项),请尝试更改输出文档(在文本编辑器中)以关闭抗锯齿功能。如果文档在文本编辑器中编辑后无法打开,您可以运行:

 pdftk fdf_readable.pdf output fdf_fixed.pdf

它应该修复任何损坏的引用或字节计数。

然后打开调整后的 pdf,看看它是否像您想要的那样。

坏消息是:上面完成的唯一一件事是通过 fpdf 在幕后使用的方法验证抗锯齿是否可能。如果可能的话,希望该功能已经存在,或者您可以提出功能请求,或者如果您真的有信心,您可以尝试扩展 fpdf 以包含某种 antialias("true|false" ") 方法。如果他们用来绘制线条的方法与规范不同,并且没有关闭抗锯齿的选项,那么您最好的选择可能是找到替代的 pdf 生成器,例如 tcpdf,看看他们是否提供该功能。

更新

好吧,我想首先指出我仍然没有看到模糊之处。所以我无法判断这是否真的解决了您的问题。但我确实将自动描边调整规则添加到您的示例中,并且 PDF 仍然打开。

为了不再发布整个 PDF,您可以按照以下方式更新示例代码:

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

基本上,我所做的就是添加对主资源字典的字典对象引用,然后使用笔划调整规则集创建实际的字典对象为真。我还添加了规范示例中的传递函数,因为我不确定这是否会产生影响。它可以很容易地取出来。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文