Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
i am trying to convert html to pdf using google api wkhtmltopdf in asp.net.
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
process.Start();
 
//wait until the conversion is done
process.WaitForExit();
 
// read the exit code, close process    
int returnCode = process.ExitCode;
process.Close();
 
//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
fs.Close();
 
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 1:46am
Edited 8-May-13 2:11am
(no name)114.3K
v2
Comments
sri senthil kumar at 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
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 8 May 2013
Copyright © CodeProject, 1999-2014
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