简体   繁体   English

如何在HTML中使用iTextSharp将HTML转换为PDF文件并保存

[英]How to Convert an Html to a PDF file and save it Using iTextSharp in C#

    #region convert HTML To PDF
    static public void HTMLToPdf(string Contents, string FilePath, string strValue)
    {

        Document document = new Document(PageSize.A4, 10f, 10f, 10f, 0f);

        //PDF for compliance overdue report.
        if (strValue == "due")
        {

            PdfWriter.GetInstance(document, new FileStream(FilePath,FileMode.Create));
        }
        //PDF for other compliance reports.
        else
        {

            PdfWriter.GetInstance(document, new FileStream(FilePath, FileMode.Create));
        }
        document.Open();
        iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);

        hw.Parse(new StringReader(Contents));

        document.Close();
    }
    #endregion

I do not know how to do this,But you can try this: 我不知道该怎么做,但是您可以尝试以下操作:

HTML to PDF Online API HTML转PDF在线API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM