3

我正在使用 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, Nullable1 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, IDictionary2 参数) +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.WrappedAsyncResultBase1.End() +49

4

4 回答 4

3

Azure Web Apps 运行的沙盒有一些限制,会阻止某些调用,这很可能是您使用 GDI+ 时遇到的问题。

您可以在https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#win32ksys-user32gdi32-restrictions上找到有关这些沙盒限制的更多信息。

于 2016-04-06T16:51:27.940 回答
3

使用以下代码似乎已经解决了这个问题。在此处查看类似的帖子和解决方案。

Document doc = new Document();
doc.LoadFromFile(fileName);
ToPdfParameterList tpl = new ToPdfParameterList{

    UsePSCoversion = true;           
    //azure          
};  
doc.SaveToFile(resultName);
于 2017-09-28T09:51:35.640 回答
0

粗略的猜测:您隐式引用了另一个 dll,或者安装在 GAC 中,或者未设置为复制本地。因此,尽管您编译的大部分代码都部署到 Azure,但有问题的神秘 dll 并未部署到 azure。

于 2016-04-06T05:35:34.583 回答
0

另一个暗中猜测:也许检查http://www.e-iceblue.com/Introduce/free-pdf-component.html上的文档以查看在 Azure 中运行时是否存在任何已知问题。

于 2016-04-06T05:55:31.983 回答