如何使用 C# 渲染 pdf [英] How to render pdfs using C#

查看:29
本文介绍了如何使用 C# 渲染 pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 C# 以图形方式加载和绘制 pdf 文件.我不需要编辑它们或任何东西,只需在给定的缩放级别渲染它们.

I want to load and draw pdf files graphically using C#. I don't need to edit them or anything, just render them at a given zoom level.

我发现的 pdf 库似乎专注于生成.我该怎么做?

The pdf libraries I have found seem to be focussed on generation. How do I do this?

谢谢.

推荐答案

如果 Adob​​e ActiveX 不是您要找的东西,还有其他一些选择(因为 Acrobat 必须存在于用户计算机上,并且您可以不要自己发货).

There are a few other choices in case the Adobe ActiveX isn't what you're looking for (since Acrobat must be present on the user machine and you can't ship it yourself).

要创建 PDF 预览,请先查看 StackOverflow 上有关该主题的其他一些讨论:

For creating the PDF preview, first have a look at some other discussions on the subject on StackOverflow:

在最后两个中,我谈到了一些您可以尝试的事情:

In the last two I talk about a few things you can try:

  • You can get a commercial renderer (PDFViewForNet, PDFRasterizer.NET, ABCPDF, ActivePDF, XpdfRasterizer and others in the other answers...).
    Most are fairly expensive though, especially if all you care about is making a simple preview/thumbnails.

除了 Omar Shahine 的代码片段,还有一篇 CodeProject 文章 展示了如何使用 Adob​​e ActiveX,但它可能已经过时,很容易被新版本破坏,其合法性是模糊的(基本上它可以用于内部使用,但你不能运送它,你不能在服务器上使用它来生成 PDF 图像).

In addition to Omar Shahine's code snippet, there is a CodeProject article that shows how to use the Adobe ActiveX, but it may be out of date, easily broken by new releases and its legality is murky (basically it's ok for internal use but you can't ship it and you can't use it on a server to produce images of PDF).

您可以查看 SumatraPDF 的源代码,一个用于 Windows 的开源 PDF 查看器.

You could have a look at the source code for SumatraPDF, an OpenSource PDF viewer for windows.

还有 Poppler,一种使用 Xpdf 作为渲染引擎.所有这些都很棒,但需要付出相当多的努力才能使它们工作并与 .Net 交互,并且它们往往在 GPL 下分发.

There is also Poppler, a rendering engine that uses Xpdf as a rendering engine. All of these are great but they will require a fair amount of commitment to make make them work and interface with .Net and they tend to be be distributed under the GPL.

您可能需要考虑使用 GhostScript 作为解释器,因为渲染页面是一个相当简单的过程.
缺点是您需要将其重新打包以与您的应用程序一起安装,或者使其成为先决条件(或至少是安装过程的一部分).
这不是一个很大的挑战,而且肯定比必须按摩其他渲染引擎与 .Net 合作更容易.
我做了一个小项目,你可以在 Developer Express 论坛 作为附件.
请注意 GhostScript through 的许可要求.
如果您不能这样做,那么商业软件可能是您唯一的选择.

You may want to consider using GhostScript as an interpreter because rendering pages is a fairly simple process.
The drawback is that you will need to either re-package it to install it with your app, or make it a pre-requisite (or at least a part of your install process).
It's not a big challenge, and it's certainly easier than having to massage the other rendering engines into cooperating with .Net.
I did a small project that you will find on the Developer Express forums as an attachment.
Be careful of the license requirements for GhostScript through.
If you can't leave with that then commercial software is probably your only choice.

这篇关于如何使用 C# 渲染 pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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