我使用ImageMagick.NET從pdf生成圖像。它的工作,但轉換過程太慢。代碼 - >ImageMagick Pdf到圖像轉換太慢
public void ProcessRequest(HttpContext context)
{
if (context.Request["id"] != null)
{
string id = context.Request["id"].ToString();
MagickReadSettings settings = new MagickReadSettings();
settings.Density = new MagickGeometry(300, 300);
using (MagickImageCollection images = new MagickImageCollection())
{
images.Read(System.Web.HttpContext.Current.Server.MapPath(string.Format("~/Reciepts/order{0}.pdf", id)), settings);
MagickImage vertical= images.AppendVertically();
using (var memoryStream = new MemoryStream())
{
vertical.ToBitmap().Save(memoryStream, ImageFormat.Jpeg);
var d = memoryStream.GetBuffer();
context.Response.Clear();
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(d);
context.Response.End();
}
}
}
}
我在哪裏可以改進?
ImageMagick.NET是否需要安裝GhostScript? –
只有在閱讀.PDF/.EPS文件時才需要Ghostscript。 – dlemstra
感謝您的信息。 –