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
close icon

Multiple pages image break issue in html to pdf conversion

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?

5 Replies

PV Prakash Viswanathan Syncfusion Team March 28, 2017 12:04 PM UTC

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


AA Ahsan Ashfaq April 3, 2017 06:12 PM UTC

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


PV Prakash Viswanathan Syncfusion Team April 4, 2017 07:11 AM UTC

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 



AA Ahsan Ashfaq April 4, 2017 01:07 PM UTC

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


ST SaBrena Toler Syncfusion Team April 7, 2017 01:27 PM UTC

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 


Loader.
Live Chat Icon For mobile
Up arrow icon