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

PdfDocument: need to remove blue canvas

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,
                                                              AspectRatio.KeepWidth);
                        //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

9 Replies

KK Karthik Krishnaraj Syncfusion Team 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:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/HtmlToPDFMVCSample-1077011390-578902537.zip
Thanks,
Karthik.


LY lyolikaa August 28, 2015 10:57 AM UTC

Input html file
Thank you

Attachment: html_f4978458.zip


KK Karthik Krishnaraj Syncfusion Team 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:
https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/general-info/ee330732(v=vs.85)?redirectedfrom=MSDN#iviewobject_draw

 As explained, to solve this, please follow the below UG link
https://help.syncfusion.com/windowsforms/overview 
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.
Thanks,
Karthik



LY lyolikaa September 1, 2015 11:53 AM UTC

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

Attachment: full_html_69ced479.zip


KK Karthik Krishnaraj Syncfusion Team 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:
https://www.syncfusion.com/blogs/post/HTML-to-PDF-Conversion-by-using-the-WebKit-Rendering-Engine.aspx
Output Document:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/Output-19201471037374134.zip


Thanks,
Karthik.


LY lyolikaa 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'

Thanks



KK Karthik Krishnaraj Syncfusion Team 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.
Thanks,
Karthik.


LY lyolikaa October 7, 2015 08:53 AM UTC

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


KK Karthik Krishnaraj Syncfusion Team October 8, 2015 06:27 AM UTC

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

Loader.
Up arrow icon