Пример #1
0
 /// <summary>
 /// Register HtmlToX libraries.
 /// </summary>
 private void RegisterHtmlToXLibraries()
 {
     WkHtmlToXLibrariesManager.Register(new Linux32NativeBundle());
     WkHtmlToXLibrariesManager.Register(new Linux64NativeBundle());
     WkHtmlToXLibrariesManager.Register(new Win32NativeBundle());
     WkHtmlToXLibrariesManager.Register(new Win64NativeBundle());
 }
Пример #2
0
 private void Init()
 {
     if (_instanse == null)
     {
         /// Copies wkhtmltox0.dll to the assembly directory
         WkHtmlToXLibrariesManager.Register(new Win32NativeBundle());
         _instanse = new WkHtmlToPdfConverter();
     }
 }
Пример #3
0
        private void TryRegisterLibraryBundles()
        {
            var ignore = Environment.GetEnvironmentVariable("WKHTMLTOXSHARP_NOBUNDLES");

            if (ignore == null || ignore.ToLower() != "true")
            {
                // Register all available bundles..
                WkHtmlToXLibrariesManager.Register(new Linux32NativeBundle());
                WkHtmlToXLibrariesManager.Register(new Linux64NativeBundle());
                WkHtmlToXLibrariesManager.Register(new Win32NativeBundle());
            }
        }
Пример #4
0
        public XPdfer()
        {
            if (nativeBundle == null)
            {
                if (WkHtmlToXLibrariesManager.RunningIn64Bits)
                {
                    nativeBundle = new Win64NativeBundle();
                }
                else
                {
                    nativeBundle = new Win32NativeBundle();
                }

                WkHtmlToXLibrariesManager.Register(nativeBundle);
            }
        }
Пример #5
0
        public ReporterPDF(ReportData inputData, ref ReportNode rnRoot
                           , string templatePath, string outputFilePath)
        {
            // absolute output file path
            string absOutputFilePath;

            if (Path.IsPathRooted(outputFilePath))
            {
                absOutputFilePath = outputFilePath;
            }
            else
            {
                absOutputFilePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), outputFilePath));
            }
            // absolute template path
            string absTemplatePath;

            if (Path.IsPathRooted(templatePath))
            {
                absTemplatePath = templatePath;
            }
            else
            {
                absTemplatePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), templatePath));
            }

            // does output directory exists
            string outDir = Path.GetDirectoryName(absOutputFilePath);

            if (!Directory.Exists(outDir))
            {
                try { Directory.CreateDirectory(outDir); }
                catch (UnauthorizedAccessException /*ex*/)
                { throw new UnauthorizedAccessException(string.Format("User not allowed to write under {0}", Directory.GetParent(outDir).FullName)); }
                catch (Exception ex)
                { throw new Exception(string.Format("Directory {0} does not exist, and could not be created.", outDir), ex); }
            }
            // html file path
            string htmlFilePath = Path.ChangeExtension(absOutputFilePath, "html");

            BuildAnalysisReport(inputData, ref rnRoot, absTemplatePath, htmlFilePath);

            try
            {
                var ignore = Environment.GetEnvironmentVariable("WKHTMLTOXSHARP_NOBUNDLES");

                if (ignore == null || ignore.ToLower() != "true")
                {
                    // Register all available bundles
                    WkHtmlToXLibrariesManager.Register(new Win32NativeBundle());
                    WkHtmlToXLibrariesManager.Register(new Win64NativeBundle());
                }

                using (IHtmlToPdfConverter converter = new MultiplexingConverter())
                {
                    converter.GlobalSettings.Margin.Top    = "0cm";
                    converter.GlobalSettings.Margin.Bottom = "0cm";
                    converter.GlobalSettings.Margin.Left   = "0cm";
                    converter.GlobalSettings.Margin.Right  = "0cm";
                    converter.GlobalSettings.Orientation   = PdfOrientation.Portrait;
                    converter.GlobalSettings.Size.PageSize = PdfPageSize.A4;

                    converter.ObjectSettings.Page = htmlFilePath;
                    converter.ObjectSettings.Web.EnablePlugins      = true;
                    converter.ObjectSettings.Web.EnableJavascript   = true;
                    converter.ObjectSettings.Web.Background         = true;
                    converter.ObjectSettings.Web.LoadImages         = true;
                    converter.ObjectSettings.Load.LoadErrorHandling = LoadErrorHandlingType.ignore;

                    byte[] bufferPDF = converter.Convert();
                    File.WriteAllBytes(absOutputFilePath, bufferPDF);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
 static HtmlToPdfPrinter()
 {
     WkHtmlToXLibrariesManager.Register(new Win32NativeBundle());
     WkHtmlToXLibrariesManager.Register(new Win64NativeBundle());
 }
Пример #7
0
 static Converter()
 {
     WkHtmlToXLibrariesManager.Register(new Win64NativeBundle());
     WkHtmlToXLibrariesManager.Register(new Win32NativeBundle());
 }