We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Error while saving pdf using save method of PdfDocument

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.

 



syncfusiontest_83e8accc.rar

6 Replies

KC Karthikeyan Chandrasekar Syncfusion Team April 24, 2013 08:55 AM UTC

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



PM Prakash Makhija April 28, 2013 11:25 PM UTC

Thanks!!

It works when I created a project in my machine and executed but when i deployed on server and try to call aspx page on click of button it doesn't work.

Can you please let me know the possible causes?




KC Karthikeyan Chandrasekar Syncfusion Team May 1, 2013 09:01 AM UTC

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.

WebApplication1.zip

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

 



PM Prakash Makhija May 22, 2013 08:55 AM UTC

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



PM Prakash Makhija May 22, 2013 12:17 PM UTC

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

 



KC Karthikeyan Chandrasekar Syncfusion Team May 27, 2013 03:55 AM UTC

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

 


Loader.
Live Chat Icon For mobile
Up arrow icon