Java – vector graphics in IText pdf

We use iText to generate PDF from Java (based in part on the suggestions on this website) However, embedding an image like our logo into an image format like GIF makes it look a little strange because people zoom in and out

Ideally, we want to embed images in vector format, such as EPS, SVG or PDF templates The website claims that EPS support has been deleted. Embedding PDF or PS into PDF may cause errors, and SVG is not even mentioned

Our code directly uses graphics2d API instead of iText, but if the results are achieved, we are willing to break through AWT mode and use iText itself How can this be done?

Solution

According to documentation iText supports the following image formats: JPEG, GIF, PNG, tiff, BMP, WMF and EPS I don't know how this might help, but I've successfully used itextsharp to embed vector WMF images into PDF files:

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();
        }
    }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>