iText PDF中的矢量图形 [英] Vector graphics in iText PDF
问题描述
我们使用iText从Java生成PDF(部分基于此站点的建议).但是,将徽标的副本以GIF之类的图像格式嵌入会导致人们放大和缩小时看起来有些奇怪.
We use iText to generate PDFs from Java (based partly on recommendations on this site). However, embedding a copy of our logo in an image format like GIF results in it looking a bit strange as people zoom in and out.
理想情况下,我们希望以矢量格式嵌入图像,例如EPS,SVG或只是PDF模板.该网站声称EPS支持已被删除,在PDF中嵌入PDF或PS可能会导致错误,甚至没有提到SVG.
Ideally we'd like to embed the image in a vector format, such as EPS, SVG or just a PDF template. The website claims that EPS support has been dropped, that embedding a PDF or PS within a PDF can result in errors, and it doesn't even mention SVG.
我们的代码直接使用Graphics2D API而不是iText,但是我们愿意脱离AWT模式,并在实现结果的情况下使用iText本身.该怎么办?
Our code uses the Graphics2D API rather than iText directly, but we'd be willing to break out of AWT mode and use iText itself if it achieved the result. How can this be done?
推荐答案
根据文档 iText支持以下图像格式:JPEG,GIF,PNG,TIFF,BMP,WMF和EPS.我不知道这是否有帮助,但是我已经成功地使用 iTextSharp 嵌入矢量 WMF 图片:
According to the documentation iText supports the following image formats: JPEG, GIF, PNG, TIFF, BMP, WMF and EPS. I don't know if this might be of any help but I have successfully used iTextSharp to embed vector WMF image in a pdf file:
C#:
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
public class Program
{
public static void Main()
{
Document document = new Document();
using (Stream outputPdfStream = new FileStream("output.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
using (Stream imageStream = new FileStream("test.wmf", FileMode.Open, FileAccess.Read, FileShare.Read))
{
PdfWriter.GetInstance(document, outputPdfStream);
Image wmf = Image.GetInstance(imageStream);
document.Open();
document.Add(wmf);
document.Close();
}
}
}
这篇关于iText PDF中的矢量图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!