C#中的JPG到PDF转换器 [英] JPG to PDF Convertor in C#

查看:23
本文介绍了C#中的JPG到PDF转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将图像(如 jpg 或 png)转换为 PDF.

I would like to convert from an image (like jpg or png) to PDF.

我已经查看了 ImageMagickNET,但它对于我的需求来说太复杂了.

I've checked out ImageMagickNET, but it is far too complex for my needs.

还有哪些其他 .NET 解决方案或代码可以将图像转换为 PDF?

What other .NET solutions or code are there for converting an image to a PDF?

推荐答案

iTextSharp 做得非常干净并且是开放的来源.此外,它还有作者非常好的随书 如果你最终做了更有趣的事情,比如管理表单,我推荐它.对于正常使用,邮件列表和新闻组中提供了大量资源,可提供有关如何执行常见操作的示例.

iTextSharp does it pretty cleanly and is open source. Also, it has a very good accompanying book by the author which I recommend if you end up doing more interesting things like managing forms. For normal usage, there are plenty resources on mailing lists and newsgroups for samples of how to do common things.

正如 @Chirag 的评论 中提到的,@Darin 的回答 的代码肯定可以用当前版本编译.

as alluded to in @Chirag's comment, @Darin's answer has code that definitely compiles with current versions.

示例用法:

Example usage:

public static void ImagesToPdf(string[] imagepaths, string pdfpath)
{
    using(var doc = new iTextSharp.text.Document())
    {
        iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new FileStream(pdfpath, FileMode.Create));
        doc.Open();
        foreach (var item in imagepaths)
        {
            iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(item);
            doc.Add(image);
        }
    }
}

这篇关于C#中的JPG到PDF转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆