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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

PdfDocument: need to remove blue canvas

Thread ID:





120051 Aug 26,2015 05:04 PM UTC Oct 8,2015 06:27 AM UTC ASP.NET MVC 9
Tags: PDF
Asked On August 26, 2015 05:04 PM UTC

I have existing working code to create PdfDocument from web page with the help of HtmlConverter
Issue is extra blue canvas in result document (see attached example)
I tried some ways to change it(some code in comments)

                    doc = new PdfDocument();

                    doc.PageSettings.SetMargins(0, 10, 0, 10);
                    doc.PageSettings.Orientation = PdfPageOrientation.Portrait;
                    doc.PageSettings.Rotate = 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);
                    //height = convertor.ConvertToPixels(page.GetClientSize().Height, PdfGraphicsUnit.Point);

                    //PdfGraphics g = page.Graphics;
                    //PdfPageBase lpage = doc.Pages[0];
                    //PdfTemplate template = lpage.CreateTemplate();
                    //var b = new Bitmap(1, 1);
                    //b.SetPixel(0, 0, Color.White); 
                    //var backgr = new Bitmap(b, (int)width, 1024);
                    //PdfImage img = new PdfBitmap(b);
                    //g.DrawImage(img, new PointF());
                    //g.DrawPdfTemplate(template, PointF.Empty, page.Size);

                    using (var html = new Syncfusion.HtmlConverter.HtmlConverter())
                        html.EnableJavaScript = true;
                        html.AutoDetectPageBreak = true;
                        html.EnableHyperlinks = false;

                        HtmlToPdfResult result = html.Convert(url, ImageType.Metafile, (int)width, (int)height,
                        //htmltopdfresult result = html.convert(url, imagetype.metafile, (int) width, (int) height,
                        //                                      aspectratio.keepheight);

                        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.Width = result.RenderedImage.Size.Width;
                            //doc.PageSettings.Height = result.RenderedImage.Size.Height;
                            format.SplitTextLines = false;
                            format.SplitImages = false;
                            mf.Draw(page, new PointF(0, 0), format);
                            result.Render(page, format);

Attachment: company_profile__bf1ced0d.zip

Karthik Krishnaraj [Syncfusion]
Replied On August 27, 2015 11:38 AM UTC

Hi lyolikaa,
Thank you for using Syncfusion products,
I am afraid that I couldn’t able to reproduce the issue, I have attached a simple sample for your reference below please have a look through it. Can you please share us your input HTML file / URL for which the issue occurs so that it will be helpful for us to provide better solution at earliest.
Sample Link:

Replied On August 28, 2015 10:57 AM UTC

Input html file
Thank you

Attachment: html_f4978458.zip

Karthik Krishnaraj [Syncfusion]
Replied On August 31, 2015 06:54 AM UTC

Hi lyolikaa,
Thank you for your update,
We have checked with the provided input file, here the file has referred some external dependencies(CSS) in it so we could not reproduce the issue. Can you provide us the complete HTML with all the external dependencies(CSS/JS), so that it will be helpful for us to proceed further with this.
In the meantime we have found that output PDF document provided by you contains Bitmapped image. Html Converter make use of MSHTML (IE Rendering Engine) to convert Web pages to Image, and then convert to PDF. With IE 9 and above there is a known issue that it generates only raster image. You can get more information on this from the following link:

 As explained, to solve this, please follow the below UG link
After these changes please try to convert the Html to PDF which will produce the sharper selectable text. Please let me know if you have any concerns in this.

Replied On September 1, 2015 11:53 AM UTC

Thank you for advice, bit it did not give any effect.
Html file and styles are in attachment

Attachment: full_html_69ced479.zip

Karthik Krishnaraj [Syncfusion]
Replied On September 2, 2015 11:46 AM UTC

Hi lyolikaa,
Thanks for your update.
I am afraid that I could not able to reproduce this issue. I have attached the Snap shot of input HTML and output PDF document for your reference, here the output looks to be same as in input, and you can see that styles are not applied in input as well.
We have support for HTML to PDF using WebKit rendering engine, and we suggest you to test the input HTML with this converter. I have attached a blog link which contains detailed information regarding HTML to PDF using WebKit rendering engine. Please have a look through it and let us know if it satisfies your requirement.
Blog Link:
Output Document:


Replied On September 17, 2015 05:14 PM UTC

Hi! I trying to use WebKitHtmlConverter, but get another library version for existing binaries

Error 17 Assembly 'Syncfusion.WebKitHtmlConverter.Base, Version=12.3400.0.36, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89' uses 'Syncfusion.Pdf.Base, Version=12.3400.0.36, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89' which has a higher version than referenced assembly 'Syncfusion.Pdf.Base, Version=11.4450.0.26, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89'


Karthik Krishnaraj [Syncfusion]
Replied On September 18, 2015 06:27 AM UTC

Hi  lyolikaa,
You need to refer Syfusion.Pdf.Base.dll version same as 'Syncfusion.WebKitHtmlConverter.Base.dll (12.3400.0.36), but you have referred 11.4450.0.26. Please refer the assemblies as I mentioned and let us know if you have any concerns in this.

Replied On October 7, 2015 08:53 AM UTC

Thank you for help.
I found one bug in background style on my pages and problem was solved

Karthik Krishnaraj [Syncfusion]
Replied On October 8, 2015 06:27 AM UTC

Hi  lyolikaa,
Thank you for your update, please let me know if you have any other query.


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon