-2

I used itextsharp with vb before, I was doing it with some HTML coding, like passing the whole html to itextsharp to create a PDF, but now I am working on c# and I have lost all my previous works, is there any link or hints that van help me to do that?.

I know I can simply create pdf with itextsharp, but I can't seems to find a way to layout my content properly, that's why I want to use HTML styling to help.

Please let me know if there is a better way to layout the pdf with itextsharp or any other library.

Thanks

cutecutebj
  • 179
  • 1
  • 15
  • @Daniel Casserly -> it's is no "can I render pdf" but "that library don't read my css" – zchpit Mar 23 '15 at 08:28
  • @zchpit Indeed `HtmlWorker` doesn't read CSS, but XML Worker does. – Bruno Lowagie Mar 23 '15 at 08:31
  • You'll also benefit from reading [The Best iText Questions on StackOverflow](http://pages.itextpdf.com/ebook-stackoverflow-questions.html). It's a free ebook that contains hundreds of examples and it introduces different ways to create templates (HTML is only one option). – Bruno Lowagie Mar 23 '15 at 08:36
  • @benji_Wong -> if any answare was helpfull, don't forget to upvote :) – zchpit Mar 23 '15 at 09:47
  • @zchpit I think I should change my question a bit. I don't have to use HTML to PDF. The reason why I wanna use it is because I can't seems to find a way to format the document properly with itextsharp itself, is there a better way to format it? – cutecutebj Mar 24 '15 at 03:05

1 Answers1

0

Check these link :

  1. How to convert html to pdf - itextsharp
  2. Another conversion example

Example of usage (without html):

            MemoryStream output = new MemoryStream();
            iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10, 10, 20, 20);
            PdfWriter writer = PdfWriter.GetInstance(document, output);

            document.Open(); // open doc to write 

            // add things to your document
            // example: document.Add(new Paragraph("Test"));

            document.Close();
            writer.Close();

            byte[] pdfBytes = output.ToArray();
Community
  • 1
  • 1
Cosmin
  • 2,184
  • 21
  • 38
  • The first link is OK. It is indeed a duplicate of the question that is asked here. The second link is not OK as it uses `HTMLWorker`, a class that has been abandoned in favor of XML Worker and that is no longer supported. – Bruno Lowagie Mar 23 '15 at 08:34
  • The example you added is irrelevant because the OP explains that he is able to create a PDF. He says: *I know I can simply create pdf with itextsharp.* Hence you should have voted to close the question as a duplicate rather than adding an answer. – Bruno Lowagie Mar 23 '15 at 08:38