Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Magick.net将PDF转换为图像;无法创建临时文件'';:没有此类文件或目录@error/pdf.c/ReadPDFImage/476“;_C#_Pdf_Imagick_Magick.net_Imagemagick.net - Fatal编程技术网

C# Magick.net将PDF转换为图像;无法创建临时文件'';:没有此类文件或目录@error/pdf.c/ReadPDFImage/476“;

C# Magick.net将PDF转换为图像;无法创建临时文件'';:没有此类文件或目录@error/pdf.c/ReadPDFImage/476“;,c#,pdf,imagick,magick.net,imagemagick.net,C#,Pdf,Imagick,Magick.net,Imagemagick.net,我试图在控制台应用程序中使用Magick.net来渲染PDF中的图像,但似乎无法解决这个问题 调用“MagickImageCollection.Read(byte[],settings)”时,我总是得到一个 无法创建临时文件“”:没有此类文件或目录@ 错误/pdf.c/ReadPDFImage/476“ 例外 我试过: 将x86和64位Ghostscript DLL都放置在bin文件夹中 使用AnyCPU、x86、64版本的Magick.net和GS版本的组合 将MagickNET.SetGh

我试图在控制台应用程序中使用Magick.net来渲染PDF中的图像,但似乎无法解决这个问题

调用“MagickImageCollection.Read(byte[],settings)”时,我总是得到一个

无法创建临时文件“”:没有此类文件或目录@ 错误/pdf.c/ReadPDFImage/476“

例外

我试过:

  • 将x86和64位Ghostscript DLL都放置在bin文件夹中
  • 使用AnyCPU、x86、64版本的Magick.net和GS版本的组合
  • 将MagickNET.SetGhostscriptDirectory设置为程序文件GS bin文件夹
  • 将MagickNET.SetTempDirectory设置为c:/temp中的文件夹,并确认我的应用程序可以通过编程方式将文件移动到其中进行访问
  • 将MagickAnyCPU.CacheDirectory设置为c:/temp中的文件夹
我不知道我会做错什么

    using (MagickImageCollection images = new MagickImageCollection())
    {
        // Add all the pages of the pdf file to the collection
        images.Read(file, settings);

        switch (orientation)
        {
            case Orientation.Horizontal:
                using (MagickImage image = (MagickImage)images.AppendHorizontally())
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        image.Write(ms);

                        return ms.ToArray();
                    }

                }
            case Orientation.Vertical:
                using (MagickImage image = (MagickImage)images.AppendHorizontally())
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        image.Write(ms);

                        return ms.ToArray();
                    }
                }
        }
    }

我最终成功地克服了这个问题,我将错误的读取设置传递给MagickImageCollection.read(字节[],设置)

我告诉Magick阅读PNG格式的PDF,而不是将结果写入PNG

MagickReadSettings settings = new MagickReadSettings();
settings.Format = MagickFormat.Png;
我觉得有点傻,但是错误信息完全通过我传递出去了