在 winform 中显示 PDF

Display a PDF in winforms

我正在尝试使用 C# .net 在 winform 中显示 PDF

我已经包含了 iTextSharp 库,并成功打开了 PDF 文件,但是我从 iTextView

得到了一个 byte[] 返回
 PdfReader reader = new PdfReader(GetURI("test.pdf")); 
 reader.getPageN(1); //returns byte array

我找不到关于这个库的太多文档,我想知道如何在实际表单上获取 PDF,无论是在图片框还是在 web 视图中。如何显示 PDF 的页面?

编辑:

我不想在第三方打开它reader

我不想依赖 adobe reader

我想专注于使用 iTextSharp 或类似工具的解决方案,因为我需要保护 PDF、加密它并最终更改它。

您可以在WebBrowser控件中轻松显示PDF。将 webBrowser 控件添加到您的 Winform。将以下方法添加到您的表单中。

private void RenderPdf(string filePath)
{
    if (!string.IsNullOrWhiteSpace(filePath))
    {
        webBrowser1.Navigate(@filePath);
    }
}

通过传递 PDF 文件路径调用此方法,

RenderPdf(@"PDF path");

这个问题是this

的副本

我找到的答案:

i think the easiest way is to use the Adobe PDF reader COM Component right click on your toolbox & select "Choose Items" Select the "COM Components" tab Select "Adobe PDF Reader" then click ok Drag & Drop the control on your form & modify the "src" Property to the PDF files you want to read i hope this helps

ITextSharp 允许您创建和操作 pdf,但不提供任何渲染选项,如 Bradley Smith 在上面的评论中所说

我很久以前做过类似的事情,我最终做的是使用 Ghostscript 从我的 pdf 生成 tiff 图像并显示它。显然,它只显示图像,因此如果您需要编辑 pdf,这对您不起作用。

Ghostscript 只是命令行,所以我认为你必须 运行 像这样:

       Process.Start(@"c:\gs\gs.exe",
            String.Format("-o {0} -sDEVICE=tiffg4 -dFirstPage={1} -dLastPage={2} {3}", "tiffPages.tif", fromPage, toPage, "inputfile.pdf"));

使用来自任何供应商的查看器控件怎么样?在 google 的第一页找到它:viewer control for windows forms

如果可以选择商业图书馆,请尝试 Amyuni PDF Creator .Net。您将能够以某种形式显示您的 PDF 文档、修改文档或对其进行加密。您将不需要依赖任何其他要安装的程序或任何外部进程。

正如其他答案和评论所提到的,iText 不是为显示 PDF 文档而设计的。

免责声明:我在 Amyuni Technologies 工作。