我正在使用spire库为用户创建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(Nullable
1 tid, Nullable
1 eid) +616
lambda_method(Closure , ControllerBase , Object[] ) +146
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +167
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 parameters) +27
System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49