c# - 使用 ephtmltopdf 将 html 转换为 pdf

标签 c# html html-to-pdf

我一直在尝试将我的 html 页面保存为 pdf 格式。我正在使用 ephtmltopdf。它存储我的 Pdf 文件,但缺少表格。现在我对如何解决这个问题不太了解。我的 C# 代码如下:

            string url = "http://localhost:50306/ColumnChart.aspx";
            string path = "d:\\";
            string downloadName = path + "/" + "Student" + "-Registration_Form.pdf";
            SizeF sf = new SizeF();
            sf.Height = (float)635;//635;900
            sf.Width = (float)816;//8161000

            PdfConverter pdfConverter = new PdfConverter();
            pdfConverter.PageWidth = 816; //8161000
            pdfConverter.PdfDocumentOptions.TopMargin = 50;
            pdfConverter.PdfDocumentOptions.BottomMargin = 105;
            pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true;
            pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.Letter;
            pdfConverter.PdfDocumentOptions.CustomPdfPageSize = sf;//new SizeF( 595, 842 );
            pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
            pdfConverter.PdfDocumentOptions.ShowHeader = false;
            pdfConverter.PdfDocumentOptions.ShowFooter = false;
            pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait;
            pdfConverter.PdfDocumentOptions.FitWidth = false;
            pdfConverter.PdfDocumentOptions.EmbedFonts = true;
            pdfConverter.PdfDocumentOptions.ShowFooter = false;
            pdfConverter.PdfDocumentOptions.ShowHeader = false;


            pdfConverter.SavePdfFromUrlToFile(url, downloadName);

            Response.ContentType = "application/pdf";
            Response.AppendHeader("Content-Disposition", "attachment; filename=Student-Registration_Form.pdf");
            Response.TransmitFile("d:\\Student-Registration_Form.pdf");
            Response.End();

我的 html 代码如下:

<table >
        <tr>
            <td style="vertical-align: text-top;">

                <table border="1" id="CompleteTimeline">
                    <tr>
                        <th>
                            Complete<br />Timeline
                        </th>
                        <th>
                            Time
                        </th>
                    </tr>
                </table>
            </td>
            <td style="vertical-align: text-top;">
                <table border="1" id="PlayBackTable">
                    <tr>
                        <th>
                            Play<br />Back Id
                        </th>
                        <th>
                            Duration
                        </th>
                        <th>
                            Start Time
                        </th>
                        <th>
                            End Time
                        </th>
                    </tr>
                </table>
            </td>
            <asp:Button ID="button" Text="click" runat="server" OnClick="b1_click" />
            <td style="vertical-align: text-top;">
                <table border="1" id="MissingStartEnd">
                    <tr>
                        <th>
                            Missing<br />Start
                        </th>
                        <th>
                            Time
                        </th>
                        <th>
                            Missing<br />End
                        </th>
                        <th>
                            Time
                        </th>
                    </tr>
                </table>
            </td>
            <td style="vertical-align: text-top;">
                <table border="1" id="UnmatchedRegions">
                    <tr>
                        <th>
                            Unmatched<br />Time
                        </th>
                        <th>
                            Duration
                        </th>
                    </tr>
                </table>
            </td>
        </tr>
    </table>

PLz 帮我解决这个问题。望指教

最佳答案

请尝试放置此部分

 // set the header HTML area

pdfConverter.PdfHeaderOptions.HtmlToPdfArea = new HtmlToPdfArea("http://localhost:50306/ColumnChart.aspx");

许可证 key 是 secret 的,有人可能会滥用它。请从这篇文章中删除它。但请将其保留在您的代码中。

关于c# - 使用 ephtmltopdf 将 html 转换为 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28063896/

相关文章:

c# - 使用 LINQ 连接字符串

html - 如何使 Material-UI 数据表响应窗口大小

HTML 到 PDF 转换。固定页脚在页面底部

javascript - 根据点击的链接显示/隐藏 UL

angular - 如何在angular2中将HTML转换为pdf?

python - wkhtmltopdf 以非零代码退出 {0} django html to pdf on server

javascript - 更新谷歌热图

C#:固定语句对空字符串的行为是什么?

c# - 如何检查一个对象是否等于同一类的新对象?

javascript - 使用 JavaScript 删除 TABLE 行 TR