0

我正在使用 Winnovative Html 到 pdf 转换器

 try
        {
            PdfConverter pdfConverter = new PdfConverter();
            pdfConverter.LicenseKey = "********************";

            pdfConverter.PdfDocumentOptions.AutoSizePdfPage = true;
            pdfConverter.PdfDocumentInfo.Title = docTitle;
            pdfConverter.PdfDocumentInfo.AuthorName = docAuthor;
            pdfConverter.PdfDocumentInfo.CreatedDate = DateTime.Today;

            Document pdfDocument = new Document(COVER_PATH + docCover);
            pdfDocument.LicenseKey = "************************";
            // Render the HTML from the content URL on a new page after the cover.
            PdfPage newPage = pdfDocument.Pages.AddNewPage(PdfPageSize.Letter, new Margins(10, 10, 10, 10), PdfPageOrientation.Portrait);

            pdfDocument.DocumentInformation.Title = docTitle;

            //HtmlToPdfElement contentPdf = new HtmlToPdfElement(0, 0, contentText, cssUrl);
            PageElement contentPdf = new HtmlToPdfElement(0, 0, contentText, cssUrl);
            //contentPdf.Paginate = true;
            File.AppendAllText(OUTPUT_PATH + "debug.txt", "cp-3\n");

            try
            {
                **AddElementResult addResult = newPage.AddElement(contentPdf);**
            }
            catch (Exception ex)
            {
                File.AppendAllText(OUTPUT_PATH + "debug.txt", ex + " cp1234\n");
            }

            Byte[] pdfBytes = null;

            if (outputPdf == "")
            {
                outputPdf = "default";
            }
            File.AppendAllText(OUTPUT_PATH + "debug.txt", "cp-4\n");
            try
            {
                pdfBytes = pdfDocument.Save();
                File.WriteAllBytes(OUTPUT_PATH + outputPdf, pdfBytes);
            }
            catch (Exception ex)
            {
                File.AppendAllText(OUTPUT_PATH + "debug.txt", ex.Message + " cp1");
            }
            finally
            {
                pdfDocument.Close();
            }
        }
        catch (Exception ex)
        {
            File.AppendAllText(OUTPUT_PATH + "debug.txt", ex.Message + " cp2");
        }

创建pdf时显示异常

 System.Exception: Could not create image object. Parameter is not valid.
           at Winnovative.ImgConverter.ᜀ(String A_0, String A_1, String A_2, ᜪ& A_3, Hashtable& A_4)
           at Winnovative.HtmlToPdfElement.Render(ElementsRenderer renderer)
           at Winnovative.PdfPage.AddElement(PageElement pageElement)

它在 localhost 上也可以正常工作,但是当我在 azure 上发布时,它会在此代码行中抛出异常 AddElementResult addResult = newPage.AddElement(contentPdf);

                try
                {
                    **AddElementResult addResult = newPage.AddElement(contentPdf);**
                }
                catch (Exception ex)
                {
                    File.AppendAllText(OUTPUT_PATH + "debug.txt", ex + " cp1234\n");
                }

是dll错误还是一些代码错误?

4

0 回答 0