Hi ,
I am creating a pdf from html document and saving the file.
when I use
document.Save("htmltopdf.pdf");
It's works fine, but when I use:
document.Save(
"htmltopdf.pdf", Response, HttpReadType.Save);It gives error i.e. when I try to save file on client machine it doesn't work
Can you please help me out solve this problem.
I have attached the code.
Hi Prakash,
Thank you for using Syncfusion Products.
Please include the following mentioned line for generating
PDF without error.
Thread t = new Thread(new ThreadStart(converter));
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
Please let us know
if you have any concern.
Thanks,
Karthikeyan.C
Hi Prakash,
Thank you for your update.
Please use the HTML converter inside “Using” statement, here
is the code snippet:
using (HtmlConverter html = new
HtmlConverter())
{
Image img
= html.ConvertToImage("http://www.google.com",
ImageType.Metafile, (int)width, (int)pageSize.Height, AspectRatio.KeepWidth);
I have attached a sample for your reference.
Also make sure that web application deployed in full trust
mode.
We do not support for converting HTML to PDF in Medium
Trust.
Please refer the link for more details.
http://help.syncfusion.com/ug/wpf/pdf/default.htm#!documents/232webapplicationdeployment.htm
Please let us know if you have any concern.
Thanks,
Karthikeyan.C
Hello,
I have noticed that t.join in the below code is giving error when i deploy the code on server.
Thread t = new Thread(new ThreadStart(converter));t.SetApartmentState(
ApartmentState.STA);t.Start();
t.Join();
If i comment the join stmt it doesn't give error, it just display the blank page i.e. converter method doesn't get executed, can you please let me know the possible cause of error?
Thanks
Hello,
I got it working, the issue was Microsoft.MSHTML.dll was not there in GAC, but i got another issue my web page is more than one page but in pdf it renders only one page so i lost remaining data.
Can you please provide me the solution to this problem?
Thanks
Hi Prakash,
Thank you for your update.
Could you please set the Layout to Paginate.
Please see the code snippet below:
//Set the layout format
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Layout = PdfLayoutType.Paginate;
This will create the multipage Pdf document. The sample attached in the last update have these code snippet.
Please let us know if you have any concern.
Thanks,
Karthikeyan.C