【问题标题】:Cannot get ImageResizer to resize my Pdf无法让 ImageResizer 调整我的 Pdf 大小
【发布时间】:2016-07-01 05:37:24
【问题描述】:

我刚刚开始使用 ImageResizer 为我的图像创建缩略图,使用下面他们网站上的代码。

private void CreateThumbnail()
{
    Dictionary<string, string> versions = new Dictionary<string, string>();
    //Define the versions to generate
    versions.Add("_thumb", "width=100&height=100&crop=auto&format=jpg"); //Crop to square thumbnail
    versions.Add("_medium", "maxwidth=100&maxheight=100&format=jpg"); //Fit inside 400x400 area, jpeg
    versions.Add("_large", "maxwidth=1900&maxheight=1900&format=jpg"); //Fit inside 1900x1200 area

    //Loop through each uploaded file
    foreach (string fileKey in HttpContext.Current.Request.Files.Keys)
    {
        HttpPostedFile file = HttpContext.Current.Request.Files[fileKey];
        if (file.ContentLength <= 0) continue; //Skip unused file controls.

        //Get the physical path for the uploads folder and make sure it exists
        string uploadFolder = MapPath("~/Images");
        if (!Directory.Exists(uploadFolder)) Directory.CreateDirectory(uploadFolder);

        //Generate each version
        foreach (string suffix in versions.Keys)
        {
            //Generate a filename (GUIDs are best).
            string fileName = Path.Combine(uploadFolder, "AssetID" + suffix);

            //Let the image builder add the correct extension based on the output file type
            fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);                
        }
    }
}

但是,当我将此代码应用于 Pdf 时,它会崩溃并显示错误“文件可能已损坏、为空或可能包含单个尺寸大于 65,535 像素的 PNG 图像。” 我需要进行哪些更改才能调整 Pdf 的大小?我浏览了他们的文档,虽然它似乎会从 Pdf 创建一个缩略图,但这些示例都使用图像。

这是包括 PdfRenderer 在内的插件列表

【问题讨论】:

  • 您是否已完成imageresizing.net/docs/v4/plugins/pdfrenderer 中要求的设置?您是否使用 Adob​​e Acrobat 等 PDF 渲染器打开 PDF 以查看 PDF 是否真的损坏? Acrobat 有一个内置的预检工具,可以检查 PDF 中是否有任何错误。

标签: c# pdf thumbnails imageresizer


【解决方案1】:

未安装 PdfiumRenderer 或 PdfRenderer 插件(无论您选择哪个)。因此,主解码器无法解码图像。

您必须安装 PDF 插件才能使用。

PdfiumRenderer 是两者中的佼佼者。

http://imageresizing.net/docs/v4/plugins/pdfiumrenderer

【讨论】:

  • 我已经修改了我上面的文本以包含 NuGet 插件屏幕的副本,该屏幕显示我已经添加了 PdfRenderer
  • 这还不够。您必须按照说明进行注册。
  • 显示自诊断页面。
  • 诊断页面 - 线程 0x7124 已退出,代码为 259 (0x103)。 ImageResizer.dll 'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/32/ROOT-1-131027043435992643) 中发生了“ImageResizer.ImageCorruptedException”类型的第一次机会异常:已加载“C:\Windows\assembly\ GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'。线程 0xc390 已退出,代码为 259 (0x103)。
  • 我找不到任何关于注册 Pdfrenderer 的信息,我在哪里可以找到它或者更好的是我该怎么做?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-11-06
  • 2014-06-07
  • 2017-11-04
  • 1970-01-01
  • 2012-06-03
  • 1970-01-01
  • 2019-11-29
相关资源
最近更新 更多