通过 wkhtmltopdf 在 PDF 中重复使用相同的 SVG
我使用 wkhtmltopdf 将以下 HTML 转换为 PDF:
<html>
<head>
</head>
<body>
<object data="first.svg" width="100" height="100" type="image/svg+xml"></object>
<object data="second.svg" width="100" height="100" type="image/svg+xml"></object>
<object data="third.svg" width="100" height="100" type="image/svg+xml"></object>
</body>
</html>
我将在多个位置多次使用这些 SVG 文件,例如每个页面的顶部都有一个。
如何让输出的 PDF 文件重用文档中其他位置已存在的 SVG,而不在 PDF 中创建全新的 SVG,从而增加文件大小。
I have the following HTML for conversion to PDF using wkhtmltopdf:
<html>
<head>
</head>
<body>
<object data="first.svg" width="100" height="100" type="image/svg+xml"></object>
<object data="second.svg" width="100" height="100" type="image/svg+xml"></object>
<object data="third.svg" width="100" height="100" type="image/svg+xml"></object>
</body>
</html>
I will be using these SVG files more than once, in multiple locations, for example one will be at the top of each page.
How can I have the outputted PDF file reuse the already existant SVGs else where in the document, without making a brand new one in the PDF, thus increasing the filesize.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不熟悉 wkhtmltopdf,但 PDF 文件的结构是它包含一个“字形”库(对应于字母、符号、二合字母等),这些“字形”库在不同的坐标处反复重用。
您似乎很可能可以将最终的 svg 图像转换为字形,但恐怕我无法提供比这更多的细节。
I am not familiar with wkhtmltopdf, but the structure of a PDF file is that it contains a library of "glyphs" (corresponding to letters, symbols, digraphs, etc) that are reused over and over at different coordinates.
It seems very likely that you could turn the final svg image into a glyph, but I'm afraid I don't have any more detail than that to offer.
发现这篇文章正在寻找对矢量图形的 wkhtmltopdf 支持,并且在初步检查中似乎有一种更好的嵌入 svg 的方法:带有 css 宽度/高度的 img 标签来约束/设置大小。工作得很漂亮...
我还多次尝试包含我的 svg - 文件大小随着添加的每个实例而不断增长。
据猜测,这是您需要添加到页面中的徽标。您可能需要考虑通过 Pdftk 运行文件并为页面添加水印:
http ://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
Found this post looking for wkhtmltopdf support for vector graphics, and, on initial inspection it seems that there is a better way of embedding svg: the img tag with css width/height to constrain/set the size. Works beautifully...
I also tried including my svg more than once - the file size grows, and grows, and grows with each instance added.
At a guess it is a logo that you need adding to your pages. What you might want to consider is running the file through Pdftk and watermarking your pages:
http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/