是否有可以将PNG文件转换为PDF的.NET库? [英] Is there a .NET library that can convert PNG files to PDF?
本文介绍了是否有可以将PNG文件转换为PDF的.NET库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个应用程序,需要即时转换PNG文件PDF.是否有一个现有的图书馆可以做到这一点?我希望PDF看起来与PNG完全一样-没有多余的边距,没有边框等.
I have an application where I need to convert PNG files PDF on the fly. Is there an existing library that will do this? I would like the PDF to look exactly like the PNG--no extra margins, no borders, etc.
我正在使用.NET 4.0.
I'm using .NET 4.0.
我尝试了iTextSharp,它的效果很好.这是我需要的基本代码.
I tried iTextSharp and it worked great. Here's the basic code to get what I needed.
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
public class ITextPDFHelper
{
public static void Main(string[] args)
{
ITextPDFHelper.CreatePDF("C:\\temp\test.pdf", "C:\\temp\test.png");
}
public static void CreatePDF(string fileToCreate, pngFileName)
{
Document doc = new Document();
PdfWriter.GetInstance(doc, new FileStream(fileToCreate, FileMode.Create));
doc.Open();
Image png = Image.GetInstance(pngFileName);
png.SetAbsolutePosition(0, 0);
doc.Add(png);
doc.Close();
}//CreatePDF
}
推荐答案
您的意思是,一个包含单个页面的pdf文档?看看 ITextSharp
You mean, a pdf document containing a single page with your picture in it? Take a look at ITextSharp
这篇关于是否有可以将PNG文件转换为PDF的.NET库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文