简体   繁体   中英

How to create given html format and convert it in pdf in asp.net using itextsharp

Can you please tell me how to create html format and convert to pdf in asp.net using itextsharp?

Here is Image of invoice format of pdf :

From itext documentation

You can use:

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

or:

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

Example with 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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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