0

我已经使用 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");
    }
4

1 回答 1

2

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

  1. 将 Ghostscript.NET 升级到 v 1.1.9
  2. 将原生 Ghostscript 库升级到 9.14 版本。
于 2014-08-06T09:29:20.760 回答