我可以创建一个始终以缩放级别100%打开的PDF吗?(Can I create a PDF which will always opens at zoom level 100%?)

编程入门 行业动态 更新时间:2024-10-26 22:17:36
我可以创建一个始终以缩放级别100%打开的PDF吗?(Can I create a PDF which will always opens at zoom level 100%?)

我遇到了PNG到PDF转换的问题。

实际上我有大的PNG文件不是大小而是内容。

在PDF转换中,它会创建一个大的PDF文件。 我的质量没有任何问题,但每当我尝试在PDF查看器中打开此PDF时,它都会以“适合页面”模式打开。

所以,我在初始视图中看不到创建的PDF,但我需要将其缩放到100%。

我的问题是:我可以创建一个始终以缩放100%打开的PDF吗?

I am running into an issue with PNG to PDF conversion.

Actually I have big PNG files not in size but in contents.

In PDF conversion it creates a big PDF files. I don't have any issue with its quality, but whenever I try to open this PDF in PDF viewer, it opens in "Fit to Page" mode.

So, I can't see the created PDF in the initial view, but I need to zoom it up to 100%.

My question is: can I create a PDF which will always open at zoom 100% ?

最满意答案

你可以在Ghostscript的帮助下实现你想要的。

Ghostscript支持通过-c "...[PostScript code here]..."段插入其命令行参数中。

PostScript有一个名为pdfmark的特殊运算符。 大多数PostScript解释器都不理解此运算符,但Acrobat Distiller和(对于其大多数参数)在生成PDF时也由Ghostscript理解。

所以你可以尝试插入

-c "[ /PageMode /UseNone /Page 1 /View [/XYZ null null 1] \ /PageLayout /SinglePage /DOCVIEW pdfmark"

进入PDF-> PDF转换Ghostscript命令行。

请注意有关此代码段的各种基本内容:

关于[和]运算符/关键字,命令行代码段的内容似乎是“不平衡的”。 但事实并非如此! 最初的[由最终的pdfmark关键字平衡。 (不要问 - 我没有定义这种语法......)

'inner' [ ... ]括号分隔表示所需页面/View设置的数组

并非所有PDF查看器都尊重PDF文件中嵌入的视图设置(Acrobat软件会这样做!)。

大多数PDF查看器允许用户覆盖PDF文件中嵌入的视图设置(Acrobat软件也会这样做)。 也就是说,您可以告诉您的查看者永远不会尊重它打开的PDF文件中的任何设置,但是要始终以“适合宽度”打开它。

关于此代码段的一些具体事项:

页面模式/UseNone表示:文档显示没有书签或缩略图。 它可以被替换为 /UseOutlines (也显示书签,而不仅仅是页面) /UseThumbs (显示页面的缩略图图像,而不仅仅是页面 /FullScreen (以全屏模式打开文档) 构造为[/XYZ <left> <top> <zoom>]的视图模式的数组意味着:缩放因子为1(= 100%),距页面原点的左边距离是特殊的“空”值,意味着保持以前的用户设定值; 页面原点的最远距离也是“空”。 这个数组可以替换为 /Fit (使页面适应当前窗口大小) /FitB (使可见页面内容适应当前窗口大小) /FitH <top>' (to adapt the page width to the current window width); `表示从页面原点到窗口上边缘的所需距离。 ......还有其他几个我现在都记不住了。

因此,要更改现有PDF文件的设置,您可以执行以下操作:

gs \ -o out.pdf \ -sDEVICE=pdfwrite \ -c "[ /PageMode /UseNone /Page 1 /View [ /XYZ null null 1 ] " \ -c " /PageLayout /SinglePage /DOCVIEW pdfmark" \ -f in.pdf

要检查Ghostscript命令是否有效,请在能够处理二进制文件的文本编辑器中打开PDF。 搜索/View或/PageMode关键字并检查它们是否存在,作为值插入到PDF根对象中。

如果有效,请检查您的PDF查看器是否符合设置。 如果它不尊重它们,请查看查看器首选项设置中是否存在覆盖设置。

我对我的样本PDF进行了快速测试。 以下是PDF根对象的字典现在的外观,在pdf-parser.py的帮助下进行pdf-parser.py

pdf-parser-beta.py -s Catalog a.pdf obj 1 0 Type: /Catalog Referencing: 3 0 R, 9 0 R << /Type /Catalog /Pages 3 0 R /PageMode /UseNone /Page 1 /View [/XYZ null null 1] /PageLayout /SinglePage /Metadata 9 0 R >>

要了解有关pdfmark运算符的更多信息,请访问“pdfmark参考文件类型:pdf” 。 您应该能够在Adobe网站和其他地方找到它:

https://www.google.de/search?q=pdfmark%20reference%20filetype%3Apdf&oq=pdfmark%20reference%20filetype%3Apdf

为了让ImageMagick根据需要创建PDF,您可以破解定义代理设置的文件。 有关此主题的更多帮助,请参阅此处的示例:

http://www.imagemagick.org/Usage/files/#delegates

You can possibly achieve what you want with the help of Ghostscript.

Ghostscript supports to insert PostScript snippets into its command line parameters via -c "...[PostScript code here]...".

PostScript has a special operator called pdfmark. This operator is not understood by most PostScript interpreters, but is understood by Acrobat Distiller and (for most of its parameters) also by Ghostscript when generating PDFs.

So you could try to insert

-c "[ /PageMode /UseNone /Page 1 /View [/XYZ null null 1] \ /PageLayout /SinglePage /DOCVIEW pdfmark"

into a PDF->PDF conversion Ghostscript command line.

Please take note about various basic things concerning this snippet:

The contents of the command line snippet appears to be 'unbalanced' regarding the [ and ] operators/keywords. But it is not! The initial [ is balanced by the final pdfmark keyword. (Don't ask -- I did not define this syntax...)

The 'inner' [ ... ] brackets delimit an array representing the page /View settings you desire.

Not all PDF viewers do respect the view settings embedded in the PDF file (Acrobat software does!).

Most PDF viewers allow users to override the view settings embedded in PDF files (Acrobat software also does this). That is, you can tell your viewer to never respect any settings from the PDF files it opens, but f.e. to always open it with "fit to width".

Some specific things about this snippet:

The page mode /UseNone means: the document displays without bookmarks or thumbnails. It could be replaced by /UseOutlines (to display bookmarks also, not just the pages) /UseThumbs (to display thumbnail images of the pages, not just the pages /FullScreen (to open document in full screen mode) The array for the view mode constructed as [/XYZ <left> <top> <zoom>] means: The zoom factor is 1 (=100%), the left distance from the page origin is the special 'null' value, which means to keep the previously user-set value; the top distance from the page origin is also 'null'. This array could be replaced by /Fit (to adapt the page to the current window size) /FitB (to adapt the visible page content to the current window size) /FitH <top>' (to adapt the page width to the current window width);` indicates the required distance from page origin to upper edge of window. ...plus several others I cannot remember right now.

So to change the settings of an existing PDF file, you could do the following:

gs \ -o out.pdf \ -sDEVICE=pdfwrite \ -c "[ /PageMode /UseNone /Page 1 /View [ /XYZ null null 1 ] " \ -c " /PageLayout /SinglePage /DOCVIEW pdfmark" \ -f in.pdf

To check if the Ghostscript command worked, open the PDF in a text editor which is capable of handling binary files. Search for the /View or the /PageMode keywords and check if they are there, inserted as values into the PDF root object.

If it worked, check if your PDF viewer honors the settings. If it doesn't honor them, see if there is an overriding setting within the viewers preference settings.

I did a quick test run on a sample PDF of mine. Here is how the PDF root object's dictionary looks now, checked with the help of pdf-parser.py:

pdf-parser-beta.py -s Catalog a.pdf obj 1 0 Type: /Catalog Referencing: 3 0 R, 9 0 R << /Type /Catalog /Pages 3 0 R /PageMode /UseNone /Page 1 /View [/XYZ null null 1] /PageLayout /SinglePage /Metadata 9 0 R >>

To learn more about the pdfmark operator, google for 'pdfmark reference filetype:pdf'. You should be able to find it on the Adobe website and elsewhere:

https://www.google.de/search?q=pdfmark%20reference%20filetype%3Apdf&oq=pdfmark%20reference%20filetype%3Apdf

In order to let ImageMagick create a PDF as you want it, you may be able to hack the file defining your delegate settings. For more help about this topic see for example here:

http://www.imagemagick.org/Usage/files/#delegates

更多推荐

本文发布于:2023-04-27 23:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缩放   创建一个   级别   PDF   opens

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!