Click here to Skip to main content
13,095,004 members (80,539 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i am trying to convert html to pdf using google api wkhtmltopdf in
i want to convert a string instead of a web page. can somebody tells me how to do it. here is the code.
string url = HttpContext.Current.Server.MapPath("HTMLPage.htm");
//this will be the output path of pfd file
string filepath = HttpContext.Current.Server.MapPath("PDF/saif.pdf");
//variable to store pdf file content
byte[] fileContent = null;
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
//set the executable location
process.StartInfo.FileName = HttpContext.Current.Server.MapPath("PDFConverter/wkhtmltopdf.exe");
//set the arguments to the exectuable
// wkhtmltopdf [OPTIONS]... <input fileContent> [More input fileContents] <output filecontent="">
process.StartInfo.Arguments = url + " "  + filepath;
// process.StartInfo.Arguments = "this is the test"+""+filepath;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
//run the executable
//wait until the conversion is done
// read the exit code, close process    
int returnCode = process.ExitCode;
//initialize the filestream with filepath
FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
fileContent = new byte[(int)fs.Length];
//read the content
fs.Read(fileContent, 0, (int)fs.Length);
//close the stream
return fileContent;

i want to insert a string in url instead of htmlpage.html. how to do it.
thanks in advance.
Posted 8-May-13 0:46am
sri senthil kumar 8-May-13 8:40am
If you want to convert a string you have given into a pdf doc, Why dont you use PDFSharf/MigraDoc it will be much easier when you want to set the UI perfectly and load content/UI dynamically?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 8 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100