Generate PDF based on HTML code (iTextSharp, PDFSharp?)

前端 未结 10 2077
南笙
南笙 2020-12-08 08:15

Does the library PDFSharp can - like iTextSharp - generate PDF files *take into account HTML formatting *? (bold (strong), spacing

10条回答
  •  粉色の甜心
    2020-12-08 08:37

    If you need simple parsing in your app and you have control over html input, you can write your own library for this.

    I have created one in one of my projects, but unfortunately it cannot be shared yet due to custom features related to specific application.

    Basically, you need to follow following logic to implement basic HTML to PDF:

    1. Simple HTML parsing of tags
    2. Create logic to recognize common styles i.e. bold, italic, left, centre etc and create PDFSharp class with these properties and assign to Para, which will be added as style attributes in HTML
    3. Handle table tags and add rows and columns in PDF
    4. Paragraph tags to add paragraphs.

    I have given very broad overview of logic here based on my implementation.

    You may be having much better idea :)

    You can also refer : Writing content of HTML table into PDF doc using iTextSharp in asp.net

提交回复
热议问题