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.

PdfDocument: need to remove blue canvas

Thread ID:

Created:

Updated:

Platform:

Replies:

120051 Aug 26,2015 01:04 PM Oct 8,2015 02:27 AM ASP.NET MVC 9
loading
Tags: PDF
lyolikaa
Asked On August 26, 2015 01:04 PM

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

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

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:
http://www.syncfusion.com/downloads/support/forum/120051/ze/HtmlToPDFMVCSample-1077011390
Thanks,
Karthik.

lyolikaa
Replied On August 28, 2015 06:57 AM

Input html file
Thank you

Attachment: html_f4978458.zip

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

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:
http://msdn.microsoft.com/en-us/library/ee330732(v=vs.85).aspx#iviewobject_draw

 As explained, to solve this, please follow the below UG link
http://help.syncfusion.com/ug/windows%20forms/index.html#!Documents/resolution.htm 
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


lyolikaa
Replied On September 1, 2015 07:53 AM

Hi!
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 07:46 AM

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:
http://www.syncfusion.com/downloads/support/forum/120051/ze/Output-1920147


Thanks,
Karthik.

lyolikaa
Replied On September 17, 2015 01:14 PM

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


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

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.

lyolikaa
Replied On October 7, 2015 04:53 AM

Hi!
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 02:27 AM

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

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.

;