Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
i have a string which is a html page content, and i want to draw this content as pdf file , or converting html page to a pdf file . i searched a lot before and i have found a lot of codes but all of them using ready made libraries such as iTextSharp and DynamicPDF...., and i didn't want this, if any body know any other solution, please tell me

thanks
Posted
Updated 18-May-13 20:51pm
v2

This is one of the approaches, open-source pandoc: http://johnmacfarlane.net/pandoc/[^].

I hope you know HTML. You can create PDF using iText, or its .NET port, iTextSharp:
http://en.wikipedia.org/wiki/IText[^],
http://itextpdf.com/[^],
http://sourceforge.net/projects/itextsharp/[^],
http://www.javatips.net/blog/2011/09/create-pdf-with-itext-java-tutorial[^].

I provided Java reference, too, because most of the documentation is there. If you know C#, you won't have problem to understand it.

Note that HTML and PDF concepts are very different, so one-to-one correspondence cannot be established. HTML is fluid, but PDF is more like a fixed in its formatting paper document. You can create some reasonable mapping (perhaps with options) for some typical cases of HTML rendering.

—SA
 
Share this answer
 
when i wrote this code using ITextSharp, an exception tells me "The path is not of a legal form."
C#
string table1 = GetHtmlPage(MY HTML CODE);
       StringReader reader = new StringReader(table1);
       Document document = new Document(PageSize.A4);
       HTMLWorker parser = new HTMLWorker(document);
       string PDF_FileName = Server.MapPath("~") + "/Shopping_cart/billformat/PDF_File.pdf";
       PdfWriter.GetInstance(document, new FileStream(PDF_FileName, FileMode.OpenOrCreate));
       document.Open();
       try
       {
           parser.Parse(reader);
       }
       catch (Exception ex)
       {
           Paragraph paragraph = new Paragraph("Error!" + ex.Message);
           Chunk text = paragraph.Chunks[0] as Chunk;
           if (text != null)
           {
               text.Font.Color = BaseColor.RED;
           }
           document.Add(paragraph);
       }
       finally
       {
           document.Close();
       }


ANY HELP!!!!!!!!!!!!!!!!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900