【问题标题】:How to create given html format and convert it in pdf in asp.net using itextsharp如何使用 itextsharp 在 asp.net 中创建给定的 html 格式并将其转换为 pdf
【发布时间】:2023-03-08 07:53:01
【问题描述】:

您能告诉我如何在 asp.net 中使用 itextsharp 创建 html 格式并转换为 pdf 吗?

Here is Image of invoice format of pdf:

【问题讨论】:

    标签: c# html asp.net itext


    【解决方案1】:

    来自itext documentation

    你可以使用:

    HtmlConverter.convertToPdf("<p>input</p>", new FileOutputStream("output.pdf"));
    

    或:

    HtmlConverter.convertToPdf(new File("input.html"), new File("output.pdf"));
    

    ConverterProperties 为例:

    public void createPdf(String baseUri, String src, String dest) throws IOException { 
        ConverterProperties properties = new ConverterProperties();
        properties.setBaseUri(baseUri);
        List<IElement> elements =
            HtmlConverter.convertToElements(new FileInputStream(src), properties);
        PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
        Document document = new Document(pdf);
        for (IElement element : elements) {
            document.add(new Paragraph(element.getClass().getName()));
            document.add((IBlockElement)element);
        }
        document.close();
    }
    

    【讨论】:

    • 它不工作请给我另一个解决方案
    猜你喜欢
    • 2010-10-22
    • 2014-09-29
    • 2022-03-07
    • 2014-12-05
    • 1970-01-01
    • 1970-01-01
    • 2014-01-01
    相关资源
    最近更新 更多