0

我正在尝试使用 EVOHTMLTOPDF 创建 PDF 文件。但是生成的pdf是错误的,内容的字体很小,我什至无法阅读。

这是我在网络服务中使用的当前代码

        HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();
        htmlToPdfConverter.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

        htmlToPdfConverter.HtmlViewerWidth = int.Parse("1024");
        htmlToPdfConverter.PdfDocumentOptions.PdfPageSize = EvoPdf.PdfPageSize.Letter;
        htmlToPdfConverter.PdfDocumentOptions.PdfPageOrientation = EvoPdf.PdfPageOrientation.Portrait;
        htmlToPdfConverter.PdfDocumentOptions.TopMargin = 15f;
        htmlToPdfConverter.PdfDocumentOptions.RightMargin = 15f;
        htmlToPdfConverter.PdfDocumentOptions.BottomMargin = 15f;
        htmlToPdfConverter.PdfDocumentOptions.LeftMargin = 15f;
        byte[] outPdfBuffer = null;
        outPdfBuffer = htmlToPdfConverter.ConvertHtml(DocContent, baseUrl);
        HttpContext.Current.Response.ContentType = "application/pdf";
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + filename);
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

        File.WriteAllBytes(sourcepath, outPdfBuffer);

我还附上了截图

有时我收到这个错误,上面写着“PDF太大”

请任何人提供解决方案,因为我想创建一个 pdf 并将 pdf 下载到用户计算机。

4

2 回答 2

0

您能否尝试查看可以显示您转换的 HTML 页面内容的浏览器窗口的最小宽度?

如果内容宽度非常大,它将按比例缩小以适合 PDF 页面宽度。解决方案是修改您的 HTML 页面以允许内容在不同的浏览器窗口宽度下重排。

您可以在HTML to PDF Scaling Options Demo中找到测试各种缩放选项的现场演示。例如,如果 HTML 内容太宽,您可以选中“剪辑 HTML 内容宽度”选项以截断 HTML 内容。

关于“PDF 太大”,你什么时候收到这个错误?创建 PDF 时,在查看器中打开 PDF 等时。这似乎不是库中的错误。

于 2016-09-14T08:50:56.127 回答
0

为了在 html 中设置字体,我做了一个公式:

htmlToPdfConverter.HtmlViewerWidth = 800 - (int)((htmlToPdfConverter.PdfDocumentOptions.RightMargin + htmlToPdfConverter.PdfDocumentOptions.LeftMargin) * 1.33);

之后,来自 Evo 转换器的 pdf 中的字体大小是正确的,并且等于使用 MS Word 创建的 pdf 文档的字体大小(导出为 pdf)。

于 2020-02-12T14:53:01.330 回答