Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hey guys,

I am really tired running into problems on generating the PDF file form the HTML page.
Can any1 help me generate a PDF file from the HTML page along with the user input. My Aspx page does not have tables and cells,
It has combo box, text box and dropdowns just like a form used to enter details. I have a code right now working but it jus generates the PDF based on the URL. and my URL does not change for the values selected for each and every dropdowns, so it just simply generates the initial form without the inputs.
I have tried using all the possible HTML to PDF converts and nothing works even itextSharp, nw i am using WnVhtmltopdf and running into the above mentioned issue.
Can anyone look into my code and give me a solution on getting the PDF after the user input or suggest me with someother converter and working solution please..

C#
PdfConverter pdfConverter = new PdfConverter(); 
pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait;
pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true;
pdfConverter.PdfDocumentOptions.ShowFooter = false;
pdfConverter.PdfDocumentOptions.ShowHeader = false;
pdfConverter.LicenseKey = "abcdefghijklmnopqrstuvwxyz";

string a = Request.Url.ToString();
byte[] downloadBytes = pdfConverter.GetPdfFromUrlBytes(a);        
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.AddHeader("Content-Type", "binary/octet-stream");
response.AddHeader("Content-Disposition","attachment; filename=" + "Rendered.pdf" + "; size=" + downloadBytes.Length.ToString());
response.Flush();
response.BinaryWrite(downloadBytes);
response.Flush();
response.End();


Thanks in advance
Aaditya
Posted
Updated 25-Feb-11 10:17am
v3
Comments
Yusuf 25-Feb-11 16:17pm    
hmmm, I don't know if I want to the license key.

You can always try Virtual Image Printer driver[^] - it's (surprise) a virtual printer - so you can print the html page to a pdf file.

It's worth a try - as I guess you are running out of other options - good luck!

Regards
Espen Harlinn
 
Share this answer
 
Comments
Abhinav S 26-Feb-11 9:57am    
Very good advice!
Espen Harlinn 26-Feb-11 10:01am    
Thank you Abhinav - it's an option :)
Sorry pal, what you trying to can't be done with straight HTML to PDF conversion. What you want can only be done using PDF forms. Now, I am not aware of any tool that can take HTML and convert to PDF form, you would need to craft your own code to do that.
 
Share this answer
 
Comments
Aadityaganesan 25-Feb-11 17:58pm    
Thanks for your reply,

Is it possible to jus take a snap shot of the entire form after the user inputs the values and send it thro mail. ultimately it jus a notification that is sent with info..I thought about it but the form scrolls and I was worried whether the snap shot would turn out better.
If it is possible jus let me know about the method pls.

Thank you so much,

Aaditya

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