如何在C#中使用Ghostscript更改图像方向

时间:2014-08-04 11:53:20

标签: c# image visual-studio ghostscript ghostscript.net

我已经使用Ghostscrpt将一些pdf文件转换为jpg。一切都很好,但图像是水平的。如何更改图像方向?

源代码:

[HttpPost]
    public ActionResult PreprocessPDF(string fileTempName)
    {
        var path = ConfigurationManager.AppSettings["TemporaryDirectory"].ToString();
        string file = Path.Combine(path, fileTempName);

        System.IO.Directory.CreateDirectory(path + @"\" + fileTempName + "_temp"); // create temporary directory for storing slides

        //for pdf's
        int desired_x_dpi = 96;
        int desired_y_dpi = 96;

        _lastInstalledVarsion = GhostscriptVersionInfo.GetLastInstalledVersion();
        _rasterizer = new GhostscriptRasterizer();
        _rasterizer.Open(file, _lastInstalledVarsion, false);

        int countSlides = _rasterizer.PageCount;

        for (int pageNumber = 1; pageNumber <= _rasterizer.PageCount; pageNumber++)
        {
            string pageFilePath = Path.Combine(path + @"\" + fileTempName + "_temp", "Slide" + pageNumber.ToString() + ".jpg");
            Image img = _rasterizer.GetPage(desired_x_dpi, desired_y_dpi, pageNumber);
            img.Save(pageFilePath, ImageFormat.Jpeg);
            Console.Write(" ");
        }
        _rasterizer.Close();
        return Json(new { success = true, slides = countSlides }, "json/application");
    }

1 个答案:

答案 0 :(得分:2)

好的,我找到了解决这个问题的方法。

  1. 将Ghostscript.NET升级到v 1.1.9
  2. 将原生Ghostscript库升级到9.14版本。