2016-12-01 12 views
1

私はpdfファイルをイメージに変換しようとしていて、うまくいきました。しかし、私はそれを実行するためにghostscriptをインストールする必要があります。 ghostscriptをインストールせずに必要なDLLをコピーする方法はありますか? Ghostscript用のC#ラッパーがありますか?その場合、どうすれば使用できますか?ImageMagicでは、GhostscriptをASP.NET MVCで実行する必要がありますか?

public ActionResult UploadPdf(HttpPostedFileBase file) 
     { 
      MemoryStream fileStream = new MemoryStream(); 
      file.InputStream.CopyTo(fileStream); 
      byte[] ss = fileStream.ToArray(); 
      MagickReadSettings settings = new MagickReadSettings(); 
      settings.Density = new Density(100, 100); 
      List<ImageModel> model = new List<ImageModel>(); 
      using (MagickImageCollection images = new MagickImageCollection()) 
      { 
       images.Read(ss, settings); // Read PDF file 
       MemoryStream convertedFile; 
       foreach (MagickImage image in images) 
       { 
        convertedFile = new MemoryStream(); 
        ImageModel innerModle = new ImageModel(); 
        image.Write(convertedFile, MagickFormat.Png); 
        byte[] byteArray = convertedFile.ToArray(); 
        innerModle.Images = byteArray; 
        model.Add(innerModle); 
        convertedFile.Flush(); 
        convertedFile.Dispose(); 
       } 
      } 
      return View(model); 
     } 

ビューモデル::

public class ImageModel 
    { 
     public byte[] Images{ get; set; } 
    } 

ビュー:

@model List<DocumentViewerPoc.Models.ImageModel> 


<h2>UploadPdf</h2> 
@foreach (var item in Model) 
{ 
    var base64 = Convert.ToBase64String(item.Images); 
    var imgSrc = String.Format("data:image/gif;base64,{0}", base64); 
    <img src="@imgSrc" /> 
} 
+0

model-view-controllerタグは、パターンに関する質問用です。 ASP.NET-MVCの実装には特定のタグがあります。 –

+0

それを心に留めておきます:) – user3159792

答えて

1

Magick.NET(私が書いた)のドキュメントには素晴らしい答えがあります。

EPS/PDF/PSファイルを変換する場合は、Ghostscriptをインストールする必要があります。同じプラットフォームでGhostScriptのバージョンのみをインストールしてください。 Magick.NETの64ビット版を使用している場合は、Ghostscriptの64ビット版もインストールする必要があります。 64ビット版と32ビット版を同時に使用することはできますが、プラットフォームを同じにしておくとパフォーマンスが向上します。 Ghostscriptはhttp://www.ghostscript.com/download/gsdnld.htmlからダウンロードできます。あなたのマシンにGhostscriptをインストールしたくない場合は、gsdll32.dll/gsdl64.dllとgswin32c.exe/gswin64c.exeをあなたのサーバにコピーして、Magick.NETに以下のコードでファイルがどこにあるのかを伝えます。

MagickNET.SetGhostscriptDirectory(@"C:\MyProgram\Ghostscript"); 

Ghostscriptを商用で使用する場合は、ライセンスが必要です。

0

ありGhostscript.NETだとシャープなGhostscriptで は、ここに私のコードです。アプリケーションを配布し、どちらかを使用する場合は、AGPLの条項のもとでアプリケーションをオープンソースにするか、商用ライセンスを取得する必要があります。

関連する問題