0

I need to display this data to pdf please help me how to convert this html data to pdf

RichEditDocumentServer srv = new RichEditDocumentServer();
srv.LoadDocument("<html>fdhsdfd dshdsfgds</html>");       

using(Stream str= File.Create(@"D:test.pdf"))
{
     srv .ExportToPdf(str);
} 
Process.Start(@"D:test.pdf");
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
pavani
  • 11
  • 4
  • What problem are you facing? This didn't work? Do you show any errors? – frikinside Jul 16 '14 at 11:20
  • actually this data needs to convert into pdf. i used above code but it is showing error please help me – pavani Jul 16 '14 at 11:22
  • Illegal characters in path this is my error – pavani Jul 16 '14 at 11:23
  • In wich line? File.Create or Process.Start? Anyway, could yo put a `\ ` en the path? `D:\test.pdf` – frikinside Jul 16 '14 at 11:40
  • i no need to put the path. if i put the path it will be work. i need that data convert the pdf plz help me – pavani Jul 16 '14 at 11:44
  • There are a lot of ways to convert HTML to PDF, I see that you choose RichEditDocumentServer from DevExpress so I guess that the solutions has to be attached to that! Your code looks good, you need to generate something, even an empty pdf, but ExportToPdf needs a Stream so why do you don't need to put the path? It seems like a basic requierement for .EportToPdf. Anyway, if you are simply trying method and you aren't attached to use a RichEditDocumentServer, check this link, maybe help you: http://stackoverflow.com/questions/564650/convert-html-to-pdf-in-net?rq=1 – frikinside Jul 16 '14 at 11:58
  • my requirement is like that. no needs to convert entire file. when user enter some data that time it should be convert into pdf using dev express – pavani Jul 16 '14 at 12:18

1 Answers1

1

There are several commercial packages like AbcPdf and maybe Aspose and others.

If you are looking for a free solution, the best option might be WkHtmlToPdf, which is an EXE you call and send the URL or HTML to turn into PDF.

You don't have to write the Process.Start() code yourself though. It's kinda popular tool so there are several examples of how to use it including from C#, like: https://gist.github.com/johnnyreilly/2341776

There's also iTextSharp, but I think its CSS support is not that good.

Meligy
  • 35,654
  • 11
  • 85
  • 109