Large HTML to pdf

Technical support for Spire.PDF

Moderator: iceblue support

Large HTML to pdf

Postby shaileshggg » Thu Aug 14, 2014 12:25 pm

Hi Sir :

I am trying to convert html to pdf using this dll & its working very well.
But for large html pages, its not creating new pages and data is written only on first page in the pdf.
Rest data from html is getting skipping.
Please advice.
Code snippet :
Spire.Pdf.PdfDocument pp = new Spire.Pdf.PdfDocument();
Spire.Pdf.PdfPageSettings pst = new Spire.Pdf.PdfPageSettings();
pst.Orientation = Spire.Pdf.PdfPageOrientation.Portrait;
Spire.Pdf.HtmlConverter.PdfHtmlLayoutFormat lf = new Spire.Pdf.HtmlConverter.PdfHtmlLayoutFormat();
lf.Layout = Spire.Pdf.Graphics.PdfLayoutType.Paginate;
lf.FitToPage = Spire.Pdf.HtmlConverter.Clip.Both;
lf.FitToHtml = Spire.Pdf.HtmlConverter.Clip.Both;
lf.TrimPage = Spire.Pdf.HtmlConverter.Clip.Both;
pp.LoadFromHTML(f_strHTMLPath, true, true, false, pst, lf);
pp.SaveToFile(f_strPDFPath, Spire.Pdf.FileFormat.PDF);

Thanks,
Shailesh
shaileshggg
 
Posts: 34
Joined: Thu Aug 14, 2014 3:51 am

Re: Large HTML to pdf

Postby Gary.zhang » Fri Aug 15, 2014 3:14 am

Hello,

Thanks for your feedback.
We have posted the issue to our Dev team, once there are any update, we will let you know ASAP.
Sincerely,
Gary
E-iceblue support team
User avatar
Gary.zhang
 
Posts: 1345
Joined: Thu Apr 04, 2013 1:30 am

Re: Large HTML to pdf

Postby shaileshggg » Mon Aug 18, 2014 5:11 am

OK, Thanks.
Waiting for your reply...


Thanks,
Shailesh
shaileshggg
 
Posts: 34
Joined: Thu Aug 14, 2014 3:51 am

Re: Large HTML to pdf

Postby shaileshggg » Mon Aug 18, 2014 9:28 am

Also text in html getting cut.
Please check attachment.




Thanks,
Shailesh
You do not have the required permissions to view the files attached to this post.
shaileshggg
 
Posts: 34
Joined: Thu Aug 14, 2014 3:51 am

Re: Large HTML to pdf

Postby shaileshggg » Tue Aug 19, 2014 6:26 am

Any updates...


Thanks,
Shailesh
shaileshggg
 
Posts: 34
Joined: Thu Aug 14, 2014 3:51 am

Re: Large HTML to pdf

Postby Gary.zhang » Tue Aug 19, 2014 6:32 am

Hello,

Sorry that there is no any update. However, as soon as we have made some significant progress towards the resolution of this issue, we would be more than happy to update you with the status of correction. Please be patient and spare us little time. Your patience and comprehension is greatly appreciated in this regard.
Thanks,
Gary
E-iceblue support team
User avatar
Gary.zhang
 
Posts: 1345
Joined: Thu Apr 04, 2013 1:30 am

Re: Large HTML to pdf

Postby shaileshggg » Thu Aug 21, 2014 3:36 am

Hi :

Your development team is still in progress?
Are you releasing this fixes in your next version of library?
Probably when we will get this fixes?


Thanks,
Shailesh
shaileshggg
 
Posts: 34
Joined: Thu Aug 14, 2014 3:51 am

Re: Large HTML to pdf

Postby Gary.zhang » Thu Aug 21, 2014 7:47 am

Hello,

Sorry for inconvenience.
There are some update from our Dev team, when set the autoDetectPageBreak parameter to false, the PdfLayoutType will be set to onepage, so when you set the PdfLayoutType.Paginate, there is no effect, so you want to break page, please set autoDetectPageBreak parameter to true.
Regarding the issue that text in html getting cut, which is caused by the reason that the width is not enough, currently we have to set the width. Please refer the following codes.
Code: Select all
Spire.Pdf.PdfDocument pp = new Spire.Pdf.PdfDocument();
Spire.Pdf.PdfPageSettings pst = new Spire.Pdf.PdfPageSettings();
pst.Width = 750f;
pst.Orientation = Spire.Pdf.PdfPageOrientation.Portrait;
string testUrl = "http://www.e-iceblue.com";
Thread thread = new Thread(() =>
            {
                pp.LoadFromHTML(testUrl, true, true, true, pst);
            });
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
pp.SaveToFile("result.pdf", Spire.Pdf.FileFormat.PDF);

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar
Gary.zhang
 
Posts: 1345
Joined: Thu Apr 04, 2013 1:30 am

Re: Large HTML to pdf

Postby shaileshggg » Thu Aug 21, 2014 10:52 am

Hi :

Thanks for your instant reply.
I have applied solution you provided, long image issue is solved by passing autoDetectPageBreak = true.
Also I have applied pst.Width = 750f; , this resolved text cutting issue for some html but still there are some html files in which text is cutting.
Can you please tell me , how to set that width according to multiple html files or any generic solution?


Thanks,
Shailesh
shaileshggg
 
Posts: 34
Joined: Thu Aug 14, 2014 3:51 am

Re: Large HTML to pdf

Postby Gary.zhang » Fri Aug 22, 2014 3:44 am

Hello,

Sorry that currently there is no method to set that width according to multiple html files, it is only applied as fixed width.
Sincerely,
Gary
E-iceblue support team
User avatar
Gary.zhang
 
Posts: 1345
Joined: Thu Apr 04, 2013 1:30 am

Re: Large HTML to pdf

Postby shaileshggg » Fri Aug 22, 2014 5:32 am

OK.
Thanks for your support.


Thanks,
Shailesh
shaileshggg
 
Posts: 34
Joined: Thu Aug 14, 2014 3:51 am

Re: Large HTML to pdf

Postby ppratapwar » Tue Jun 13, 2017 3:39 pm

I am facing exactly same issue - for large html pages, its not creating new pages and data is written only on first page in the pdf.
I tried the solution mentioned in the POST - autoDetectPageBreak parameter to true but NO Luck

I am trying it from last 6 hours but no luck. Your help will be appreciated.

_msPDF = new MemoryStream();
_doc = new PdfDocument();
_doc.UseHighQualityImage = true;

var htmlLayoutFormat = new PdfHtmlLayoutFormat();
htmlLayoutFormat.IsWaiting = false;

var setting = new PdfPageSettings();
setting.Size = PdfPageSize.A4;

var relativeUrl = HttpContext.Current.Request.Url.ToString().Split('?')[0];
var absoluteUrl = HttpContext.Current.Request.Url.AbsolutePath.ToString();
var domain = relativeUrl.Replace(absoluteUrl, "");
var url = String.Concat(domain, DecryptURL());

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string result = sr.ReadToEnd();
sr.Close();
myResponse.Close();

Thread thread = new Thread(() =>
{ _doc.LoadFromHTML(result, true, setting, htmlLayoutFormat); });
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
_doc.SaveToStream(_msPDF);
Response.AppendHeader("Content-Length", _msPDF.ToArray().Length.ToString());
Response.ContentType = "application/pdf";
Response.BinaryWrite(_msPDF.ToArray());

if (_msPDF != null)
_msPDF.Dispose();

_doc.Close();
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.Flush();
Response.End();

Thanks,
Parag
ppratapwar
 
Posts: 2
Joined: Tue Jun 13, 2017 3:25 pm

Re: Large HTML to pdf

Postby Jane.Bai » Wed Jun 14, 2017 4:09 am

Hello ppratapwar,

Thanks for your inquiry.
Your code works well on my side, if you were using the old version, please first upgrade to the latest hotfix(Spire.PDF Pack(Hot Fix) Version:3.9.141) and have a try. If the issue still exists after using the hotfix, please contact us again.

Sincerely,
Jane
E-iceblue support team
User avatar
Jane.Bai
 
Posts: 417
Joined: Tue Nov 29, 2016 1:47 am

Re: Large HTML to pdf

Postby Jane.Bai » Tue Jun 20, 2017 7:28 am

Hello ppratapwar,

How is your issue now?
Could you please give us some feedback at your convenience?

Sincerely,
Jane
E-iceblue support team
User avatar
Jane.Bai
 
Posts: 417
Joined: Tue Nov 29, 2016 1:47 am


Return to Spire.PDF

Who is online

Users browsing this forum: No registered users and 1 guest