具有矢量导出功能的 SVG 绘图应用程序

发布于 2024-10-09 05:30:35 字数 456 浏览 0 评论 0原文

我想创建一个绘图应用程序,可以在画布上放置文本和图像。这些元素还需要进行交互操作。最终,生成的画布必须导出为基于矢量的 PDF。 SVG 是此功能的一个优秀竞争者。

但是,该应用程序还需要跨浏览器兼容。我已经浏览了一段时间并看到了一些可用的解决方案。我发现了 RaphaelJS 和 Google 的 SVGWeb 用于使用 SVG。

现在,为了将这些 SVG 文件转换为 PDF,我不确定 Batik 是否会为我提供什么我正在寻找。

另外,将 SVG 转换为 PDF 时如何处理位图图像?

I want to create a drawing application where I can place text and images on a canvas. Those elements also need to be interactively manipulated. Eventually the resulting canvas has to be exported to a vector based PDF. An excellent contender for this functionality would be SVG.

However, this application also needs to be crossbrowser compatible. I've been browsing around for some time now and have seen a couple of solutions available. I found among others RaphaelJS and Google's SVGWeb for working with SVG.

Now for converting those SVG files to a PDF I'm not sure if for instance Batik will offer me what I am looking for.

Also, how would bitmap images be handled when converting the SVG to PDF?

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

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

发布评论

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

评论(4

当爱已成负担 2024-10-16 05:30:35

PDF 中的图像必须是 PDF 的一部分。他们可以使用任意数量的压缩技术(jpeg、fax、jbig2、zip、gif 等)、每种颜色的各种位、每个像素的各种颜色等等......但像素必须在该 PDF 中定义。

我自己也用过蜡染。与 iText 结合起来有点笨重(令人惊讶的是涉及大量代码),但非常有用。唯一真正困扰我的是它不会将文本绘制为文本......Batik 坚持将其绘制为路径。自从我一两年前开始使用它以来,他们可能已经克服了这个问题。但这有点破坏交易(巨大的 pdf 膨胀),所以我们最终单独渲染文本:PITA、潜在的 z 顺序问题(我们从未遇到过),以及一些微妙的内部布局问题,这些问题没有解决直到稍后。

Batik 支持脚本、动画和各种在 SVG->PDF 转换范围内并不重要的其他内容。至少还有一个更紧凑的 Java SVG 库(功能不是那么丰富……半空/半满),尽管我现在记不起这个名字了。这个名字可能在一年前出现在 iText 邮件列表上?具体记不太清了。很久以前,在我开始蜡染工作之后。啊好吧。

Images within a PDF have to be part of the PDF. They can use any number of compression techniques (jpeg, fax, jbig2, zip, gif, a couple others), various bits per color, various colors per pixel, and so forth... but the pixels must be defined within that PDF.

I've used Batik myself. A little clunky in combination with iText (surprisingly large amount of code involved), but quite serviceable. The only thing that really bugged me was that it wouldn't draw text as text... Batik insists on drawing it as paths. They may have overcome this since I started using it a year or two ago. But that was kind of a deal breaker (HUGE pdf bloat) so we ended up rendering our text separately: PITA, potential z-order issues (that never came up for us), plus a couple subtle interal layout issues that didn't turn up till later.

Batik supports script, animation, and a variety of Other Things that don't really matter within the bounds of SVG->PDF conversion. There's at least one other Java SVG library out there that is much more compact(not as feature rich... half empty/half full), though I can't for the life of me remember the name at the moment. The name came up on the iText mailing list maybe a year ago? Don't recall exactly. Quite some time ago, and AFTER I got Batik working. Ah well.

執念 2024-10-16 05:30:35

Batik 可以将 svg 转换为 pdf,据我所知,Inkscape 或 Adob​​e Illustrator 也可以。

Batik can convert svg to pdf, Inkscape or Adobe Illustrator can too AFAIK.

柠檬 2024-10-16 05:30:35

我认为 Inkscape 将是你最好的选择,它所实现的形状主要坚持 SVG 1.1(使用它自己的一些属性,如果将其保存为普通 SVG,则可以摆脱这些属性)。对我来说,即使我另存为 Inkscape SVG,它在浏览器中也能很好地显示,即使有模糊,但它在 Internet Explorer 中不起作用。为此,除了使用外部工具(例如(正如您已经找到的)SVGWeb)之外,没有其他解决方案。不幸的是,不同浏览器对 SVG 的 JavaScript 支持可能有所不同,并且没有办法解决这个问题。

至于 PDF,我认为如果光栅图像嵌入到 SVG 本身中,则它们被嵌入,或者如果 SVG 被链接,则它们被链接。通过转到“扩展”>“扩展”即可轻松完成此操作。图片>选择嵌入图像或提取图像。

I think that Inkscape would be your best choice here, it mostly sticks to SVG 1.1 for the shapes it implements (using a few of its own properties, which you can get rid of if you save it as a plain SVG). For me, even when I save as an Inkscape SVG, it displays fine in browsers even with blurs, though it won't work in Internet Explorer. For that, there is no solution besides using an external tool such as (as you've already found) SVGWeb. Unfortunately, javascript support for SVG can differ between browsers, and there is no way to fix this.

As for PDF, I think that raster images are embedded if they are embedded within the SVG itself, or linked if the SVG's is linked. This is easy to do by going to Extensions > Images > select either Embed Images or Extract Images.

℉服软 2024-10-16 05:30:35

您可以使用Processing 来编写java 小程序。它是跨浏览器的,可以导出为pdf。位图图像将保留嵌入 pdf 中的位图图像。

You can program a java applet with Processing. It's cross-browser, can export to pdf. Bitmap images would remain bitmap images embedded in the pdf.

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