我正在使用 spire lib 为用户创建 pdf 文件。
string userId = User.Identity.GetUserId();
User trainee = _userDAL.GetUserByIdentityId(userId);
// Get the Employee scores
string fileNameTemplate = Server.MapPath(Url.Content("~/assets/cert1-{0}-{1}.docx"));
string nnn = string.Format("cert1-{0}-{1}.pdf", trainee.StaffID, DateTime.Now.Millisecond);
string serverPath = MainConfig.P_EXPORT;
var folder = Server.MapPath(serverPath);
使用 (Document document_test = new Document()) { document_test.LoadFromFile(fileNameTemplate);
//Update Text of Title
document_test.Replace("#trainee_name#", trainee.Name, false, true);
document_test.Replace("#course_name#", "Test", false, true);
document_test.Replace("#date_info#", DateTime.Today.ToShortDateString(), false, true);
document_test.SaveToFile(nnn, Spire.Doc.FileFormat.PDF, System.Web.HttpContext.Current.Response, HttpContentType.Attachment);
}
该代码在本地开发机器上完美运行,但是当我将其上传到 Azure Web 应用程序时,我收到一个一般错误:GDI+ 中发生一般错误。
堆栈跟踪:
[ExternalException (0x80004005): GDI+ 中发生一般错误。] System.Drawing.Imaging.Metafile..ctor(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, String description) +226801 System.Drawing.Imaging .Metafile..ctor(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type) +34 sprᲦ.ᜀ(PageSetup A_0, ImageType A_1, MemoryStream A_2, Int32 A_3, GraphicsUnit A_4) +255 sprᲦ.ᜀ(PageSetup A_0 , ImageType A_1, MemoryStream A_2, Int32 A_3) +19 sprᲦ.᜔() +224 sprᲦ.ᜁ(IDocument A_0) +234 spr᧤.ᜀ(Document A_0) +93 Spire.Doc.Document.ᜀ(Stream A_0) + 94 Spire.Doc.Document.SaveToFile(Stream stream, FileFormat fileFormat) +289 Spire.Doc.Document.SaveToFile(String fileName, FileFormat fileFormat, HttpResponse response,HttpContentType contentType) +673 LMSv1.Controllers.DisplayController.DownloadCertification(Nullable1 tid, Nullable
1 eid) +616 lambda_method(Closure , ControllerBase , Object[] ) +146 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase 控制器, Object[] 参数) +14 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary 2 parameters) +167
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 参数) +27 System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22 System.Web.Mvc.Async.WrappedAsyncResult 2.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49