Ejemplo n.º 1
0
        public static byte[] ConvertToPdf(PDFHelper.DataType type, string data, string documentName)
        {
            var webSettings = new WebSettings
            {
                EnableJavascript = true,
                LoadImages = true,
                EnableIntelligentShrinking = true
            };

            ObjectSettings objSettings = null;

            if (type == DataType.HTML)
                objSettings = new ObjectSettings { HtmlText = data, WebSettings = webSettings };
            else
                objSettings = new ObjectSettings { PageUrl = data, WebSettings = webSettings };

            var document = new HtmlToPdfDocument
            {
                GlobalSettings =
                {
                    ProduceOutline = true,
                    DocumentTitle = documentName,
                    PaperSize = PaperKind.Letter,
                    UseCompression = true,
                    ImageDPI = 600,
                    ImageQuality = 100,


                    //DPI = 1200,
                    Margins =
                    {
                        Top = 1,
                        Right = 0.5,
                        Bottom = 1,
                        Left = 0.5,
                        Unit = Unit.Centimeters
                    }
                },
                Objects = {
                   objSettings
                }
            };

            return converter.Convert(document);
        }
Ejemplo n.º 2
0
 private static void SetWebSettings()
 {
     _webSettings = new WebSettings()
     {
         EnableIntelligentShrinking = true,
         DefaultEncoding = "utf-8",
         EnableJavascript = true,
         EnablePlugins = false,
         LoadImages = true,
         PrintBackground = true,
         PrintMediaType = true,
         UserStyleSheet = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + @"App_Data\PDF.all.min.css"
     };
 }