0

我正在努力在 pdf 文档上渲染图像。渲染是在 C# 方法中完成的,如下所示:

    public void PrintPdf(System.Drawing.Image image, string htmlCode, string url)
    {
        PdfDocument Document = new PdfDocument();
        Document.Margins = new PdfDocumentMargins(20, 20, 20, 20);
        Document.ImagesCompression = 0;
        Document.Compress = false;
        Document.SerialNumber = "our-serial-number";

        PdfPage page = Document.AddPage(PdfPageSize.A4, Document.Margins, PdfPageOrientation.Portrait);

        PdfHtml overlayHtml = new PdfHtml(0, 0, htmlCode, url);
        overlayHtml.BrowserWidth = 740;
        overlayHtml.MediaType = "print";
        PdfLayoutInfo layoutInfo = page.Layout(overlayHtml);

        PdfImage pdfImage = new PdfImage(0, (float)115.5, image);
        layoutInfo = page.Layout(pdfImage);     // <-- this row causes exception from the HiQPdf library
    }

最后一行从 HiQPdf 库中引发以下异常。关于为什么的任何想法?

[HiQPdfException: Cannot layout the image]
   HiQPdf.PdfImage.LayoutObject(PdfCanvas objectsContainer) +7243
   HiQPdf.PdfPage.Layout(PdfObject pdfObject) +86

在我们将 HiQPdf 版本从 5.4.0.0 更新到 10.17.0.0 后,此错误开始发生

参数似乎没问题,htmlCode 中有正常的 html,我也没有看到图像有任何问题。图像本身可以下载为 png 和 pdf,效果很好。

4

0 回答 0