在 WinForms 中创建 PDF 缩略图 C#

kak*_*ppa 2 c# pdf

我正在寻找一个简单的免费组件,可以在其中生成给定的 pdf 文件缩略图。

我已经调查过PDFBoxGhostScript并且Abobe InteropGhostScript部署太重(文件太多),Abobe Interop需要安装 Acrobat Pro 7 或更高版本,否则 COM 异常和 PDFBox 渲染功能仍然无法实现。Win-forms 有免费的简单组件吗?

我也查看了http://tallcomponents.net/ PDF Thumbnailing 组件,显然它仅适用于 Web

提前致谢。

Ada*_*hes 5

看看PDFLibNet。它是一个可用于查看 PDF 的 DLL。您可以使用它为每个页面生成预览图像,如下所示:

Image RenderPage(PDFLibNet.PDFWrapper doc, int page)
{
    doc.CurrentPage = page + 1;
    doc.CurrentX = 0;
    doc.CurrentY = 0;

    using (var box = new PictureBox())
    {
        // have to give the document a handle to render into
        doc.RenderPage(box.Handle);

        // create an image to draw the page into
        var buffer = new Bitmap(doc.PageWidth, doc.PageHeight);
        doc.ClientBounds = new Rectangle(0, 0, doc.PageWidth, doc.PageHeight);
        using (var g = Graphics.FromImage(buffer))
        {
            var hdc = g.GetHdc();
            try
            {
                doc.DrawPageHDC(hdc);
            }
            finally
            {
                g.ReleaseHdc();
            }
        }

        return buffer;
    }
}
Run Code Online (Sandbox Code Playgroud)