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.
Unfortunately, activation email could not send to your email. Please try again.

Multiple pages image break issue in html to pdf conversion

Thread ID:

Created:

Updated:

Platform:

Replies:

129814 Mar 27,2017 08:43 AM Apr 7,2017 09:27 AM General Discussion 5
loading
Tags: General Discussion
Ahsan Ashfaq
Asked On March 27, 2017 08:43 AM

I am trying to convert html string to pdf along with some necessary css styles. Everything was working fine but now i have many records in one pdf and when it convert my table start on page 1 and ends on page 2 but pdf is looking like a broken image. Is there any work around for this in syncfusion?

Prakash Viswanathan [Syncfusion]
Replied On March 28, 2017 08:04 AM

Hi Ahsan, 
 
Thanks for contacting Syncfusion support. 
 
We suspect that the broken images may occurs due to HTML converter cannot find the resources which are used in the input HTML string. While converting HTML string to PDF, we need to specify the base URL of the resources (Image, styles, scripts etc.,) used in the HTML document. If we not provide the base URL then the resources will be skipped in the result. We have attached sample for converting HTML string to PDF with image using our WebKit HTML converter. 
 
 
If still the issue occurs, please provide the input HTML string, output PDF document and code snippet used for conversion, that will helpful for us to proceed further. 
 
Regards, 
Prakash V

Ahsan Ashfaq
Replied On April 3, 2017 02:12 PM

Well i was meant to say that i am creating a table from html string and that table is breaking up when it gets to second page. I am using following code to generate Pdf document 

        private void CreateDocument(Func<string> templateFunction)
        {

            //Create a PDF document in PDF_A1B standard
            doc = new PdfDocument(PdfConformanceLevel.Pdf_A1B);

            //Set page margins
            doc.PageSettings.SetMargins(10);
            //Set page orientation
            doc.PageSettings.Orientation = PdfPageOrientation.Portrait;

            //Set rotation
            doc.PageSettings.Rotate = (PdfPageRotateAngle)Enum.Parse(typeof(PdfPageRotateAngle), "RotateAngle0");

            PdfPage page = null;
            SizeF pageSize = SizeF.Empty;
            PdfUnitConvertor convertor = new PdfUnitConvertor();
            float width = -1;
            float height = -1;

            page = doc.Pages.Add();
            pageSize = page.GetClientSize();
            width = convertor.ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);

            if (_showHeader)
            {
                //Adding Header
                this.AddHeader(doc, "AMARK", "We belive in safety.");
            }

            if (_showFooter)
            {
                //Adding Footer
                this.AddFooter(doc, "A-Mark Precious Metals, Inc. © " + DateTime.Now.Year);
            }

            HtmlConverter html = new HtmlConverter();
            // setting Javascript
            html.EnableJavaScript = false;

            //// Setting Pagebreak
            html.AutoDetectPageBreak = false;
            // html.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly;
            //// set hyperlink
            html.EnableHyperlinks = true;

            var str = templateFunction();

            HtmlToPdfResult result = html.Convert(str, sourceUrl, ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth);

            if (result != null)
            {
                PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);
                mf.Quality = 100;

                PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
                format.Break = PdfLayoutBreakType.FitPage;
                format.Layout = PdfLayoutType.Paginate;
                doc.PageSettings.Height = result.RenderedImage.Size.Height;

                format.SplitTextLines = true;
                format.SplitImages = false;

                result.Render(page, format);
            }
        }



Also attached the sample report and sample html string so that you can have a better idea. Main pin point for issue is " where table is continuing when page 1 ends and page starts "

Thanks
Ahsan Ashfaq






Attachment: broken_page_issue_71eca4fe.rar

Prakash Viswanathan [Syncfusion]
Replied On April 4, 2017 03:11 AM

Hi Ahsan, 
 
Thanks for the update.  
  
We have analyzed the documents and code snippet you have provided. In our IE based HTML to PDF converter, we internally make use of MSHTML (IE rendering engine) to convert HTML to vector images. From the images, we will render the PDF document. Microsoft has changed its behavior from IE 9 and above, that IE will generate bitmap images instead of vector images. So, we could not parse the text in the image and could not handle the text splitting in our converter. To overcome this behavior, we have to enable legacy drawing from the registry settings. Please refer below kb link to avoid bitmapped output,   
 
  
After enabling legacy drawing you can avoid text split by using below code snippet,  
//Set false to avoid text split between pages  
format.SplitTextLines = false; 
 
We have attached output PDF document which is converted after enabling legacy drawing. 
 
Note: If the input HTML contains HTML-5 or CSS-3, IE(MSHTML) will only generate bitmapped output images, and this issue could not be fixed with IE HTML converter.   
   
Suggestion: We suggest you try our new WebKit HTML converter. WebKit converter never produces bitmap document and it has more features and enhancement than IE based HTML converter. Kindly refer below link for more information of our WebKit converter.  
 
Please let us know if you need any further assistance on this. 
 
Regards, 
Prakash V 


Ahsan Ashfaq
Replied On April 4, 2017 09:07 AM

Thanks for your reply. I just wanted to check that what would be the price for Html to Pdf converter plugin only and please note that we are using it in Asp.net MVC.

Please reply asap

Thanks
Ahsan Ashfaq

SaBrena Toler [Syncfusion]
Replied On April 7, 2017 09:27 AM

Hello Ahsan, 
I'm following up on your pricing inquiry.  It appears a sales representative attempted to contact you to discuss pricing.  
Please let me know if you have any additional questions. 
Best,
SaBrena 
  
 
SaBrena Wallace | Customer Service/Renewals and Training Manager 
2501 Aerial Center Pkwy, Suite 200 | Morrisville, NC 27560 | USA 
Direct: +1 919.481.2330 |  Fax: +1 919.573.0306 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;