DataGrids <LocalApplicationData>\Syncfusion\EssentialStudio\12.2.0.36\MVC\Samples\web\bin\syncfusion.Core.dll <LocalApplicationData>\Syncfusion\EssentialStudio\12.2.0.36\MVC\Samples\web\bin\Syncfusion.HtmlConverter.Base.dll <LocalApplicationData>\Syncfusion\EssentialStudio\12.2.0.36\MVC\Samples\web\bin\Syncfusion.Pdf.Base.dll <RuntimeDirectory>\System.Windows.Forms.dll Syncfusion.HtmlConverter Syncfusion.Pdf Syncfusion.Pdf.Graphics Syncfusion.Pdf.HtmlToPdf Syncfusion.Pdf.Interactive System.Drawing System.Drawing.Imaging void Main() { string destPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "delmetest.pdf"); ConvertToPdf("http://it.wikipedia.org/wiki/Pagina_principale", destPath); Process.Start(destPath); } void ConvertToPdf(string url, string pathToSave) { PdfDocument doc; doc = new PdfDocument(); PdfPage page = null; SizeF pageSize = SizeF.Empty; PdfUnitConvertor convertor = new PdfUnitConvertor(); float width = -1; float height = -1; //Set page margins doc.PageSettings.SetMargins(0); //Set page orientation doc.PageSettings.Orientation = PdfPageOrientation.Portrait; //Set Orientation doc.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle0; page = doc.Pages.Add(); pageSize = page.GetClientSize(); width = convertor.ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point); //Adding Header AddHeader(doc, "Syncfusion Essential PDF", " "); //Adding Footer AddFooter(doc, "@Copyright 2008"); using (HtmlConverter html = new HtmlConverter()) { // setting Javascript html.EnableJavaScript = false; // Setting Pagebreak html.AutoDetectPageBreak = false; // set hyperlink html.EnableHyperlinks = true; HtmlToPdfResult result = html.Convert(url, 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 = false; format.SplitImages = true; result.Render(page, format); } else "Errore".Dump(); } doc.Save(pathToSave); } /// /// Adds header to the document /// /// /// /// private void AddHeader(PdfDocument doc, string title, string description) { RectangleF rect = new RectangleF(0, 0, doc.PageSettings.Width, 50); Font f = new Font("Helvetica", 24, FontStyle.Regular); //Create page template PdfPageTemplateElement header = new PdfPageTemplateElement(rect); PdfFont font = new PdfTrueTypeFont(f, true); float doubleHeight = font.Height * 2; Color activeColor = Color.FromArgb(44, 71, 120); SizeF imageSize = new SizeF(110f, 35f); //Locating the logo on the right corner of the Drawing Surface PointF imageLocation = new PointF(doc.PageSettings.Width - imageSize.Width - 20, 5); // PdfImage img = new PdfBitmap(ResolveApplicationDataPath("logo.png")); // // //Draw the image in the Header. // header.Graphics.DrawImage(img, imageLocation, imageSize); PdfSolidBrush brush = new PdfSolidBrush(activeColor); PdfPen pen = new PdfPen(Color.DarkBlue, 3f); f = new Font("Helvetica", 16, FontStyle.Bold); font = new PdfTrueTypeFont(f, true); //font = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold); //Set formattings for the text PdfStringFormat format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Center; format.LineAlignment = PdfVerticalAlignment.Middle; //Draw title header.Graphics.DrawString(title, font, brush, new RectangleF(0, 0, header.Width, header.Height), format); brush = new PdfSolidBrush(Color.Gray); f = new Font("Helvetica", 6, FontStyle.Bold); font = new PdfTrueTypeFont(f, true); format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Left; format.LineAlignment = PdfVerticalAlignment.Bottom; //Draw description header.Graphics.DrawString(description, font, brush, new RectangleF(0, 0, header.Width, header.Height - 8), format); //Draw some lines in the header pen = new PdfPen(Color.DarkBlue, 0.7f); header.Graphics.DrawLine(pen, 0, 0, header.Width, 0); pen = new PdfPen(Color.DarkBlue, 2f); header.Graphics.DrawLine(pen, 0, 03, header.Width + 3, 03); pen = new PdfPen(Color.DarkBlue, 2f); header.Graphics.DrawLine(pen, 0, header.Height - 3, header.Width, header.Height - 3); header.Graphics.DrawLine(pen, 0, header.Height, header.Width, header.Height); //Add header template at the top. doc.Template.Top = header; } /// /// Adds footer to the document /// /// /// private void AddFooter(PdfDocument doc, string footerText) { RectangleF rect = new RectangleF(0, 0, doc.PageSettings.Width, 50); //Create a page template PdfPageTemplateElement footer = new PdfPageTemplateElement(rect); Font f = new Font("Helvetica", 8, FontStyle.Regular); PdfFont font = new PdfTrueTypeFont(f, true); PdfSolidBrush brush = new PdfSolidBrush(Color.Gray); PdfPen pen = new PdfPen(Color.DarkBlue, 3f); f = new Font("Helvetica", 6, FontStyle.Bold); font = new PdfTrueTypeFont(f, true); PdfStringFormat format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Center; format.LineAlignment = PdfVerticalAlignment.Middle; footer.Graphics.DrawString(footerText, font, brush, new RectangleF(0, 18, footer.Width, footer.Height), format); format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Right; format.LineAlignment = PdfVerticalAlignment.Bottom; //Create page number field PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush); //Create page count field PdfPageCountField count = new PdfPageCountField(font, brush); PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count); compositeField.Bounds = footer.Bounds; compositeField.Draw(footer.Graphics, new PointF(470, 40)); //Add the footer template at the bottom doc.Template.Bottom = footer; } /// /// Data folder path is resolved from requested page physical path /// /// /// // protected string ResolveApplicationDataPath(string fileName) // { // string dataPath = string.Format("{0}\\Common\\Images\\PDF\\", Request.PhysicalPath.ToLower().Split(new string[] { "\\web" }, StringSplitOptions.None)); // return string.Format("{0}\\{1}", dataPath, fileName); // }