[英]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?您能告诉我如何使用 itextsharp 创建 html 格式并在 asp.net 中转换为 pdf 吗?
Here is Image of invoice format of pdf :这是 pdf 发票格式的图像:
From itext documentation来自itext 文档
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
: 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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.