static void Main(string[] args) { var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus, }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = File.ReadAllText("index.html"), WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings ={ FontSize =8, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 } } } }; var converter = new SynchronizedConverter(new PdfTools()); var bytes = converter.Convert(doc); File.WriteAllBytes("__output__.pdf", bytes); }
public ActionResult Contact() { DinkToPdf.Contracts.IConverter _converter = new SynchronizedConverter(new PdfTools()); var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = DinkToPdf.Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "Owned", Out = @"C:\Users\Jodson\test.pdf" }; var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = TemplateGenerator.GetHTMLString(), WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") }, HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true }, FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" } }; var pdf = new HtmlToPdfDocument() { GlobalSettings = globalSettings, Objects = { objectSettings } }; var file = _converter.Convert(pdf); return(File(file, "application/pdf")); }
public ActionResult PrintIndex(string id) { // CustomAssemblyLoadContext context = new CustomAssemblyLoadContext(); // context.LoadUnmanagedLibrary(path); var converter = new SynchronizedConverter(new PdfTools()); var doc = new HtmlToPdfDocument { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus, }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In consectetur mauris eget ultrices iaculis. Ut odio viverra, molestie lectus nec, venenatis turpis.", WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings = { FontSize = 9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 } } } }; byte[] pdf = converter.Convert(doc); return(File(pdf, "application/pdf")); }
public void ConvertHtmlToPdf(string html) { var converter = new SynchronizedConverter(new PdfTools()); var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Grayscale, Orientation = Orientation.Portrait, PaperSize = PaperKind.LetterSmall, }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = html, WebSettings ={ DefaultEncoding = "utf-8" }, } } }; byte[] pdf = converter.Convert(doc); var fileStream = new FileStream(PdfFilePath, FileMode.OpenOrCreate); fileStream.WriteAsync(pdf, 0, pdf.Length); fileStream.Close(); }
/// <summary> /// Method that receives a html document and /// converts it in a bytes array document /// </summary> /// <param name="htmlDocumentContent">Document content in HTML format</param> /// <param name="showHeader"></param> /// <returns>Document converted into PDF in the form of a bytes array</returns> public byte[] GetPdfFromHtlm(string htmlDocumentContent, bool showHeader = true) { var doc = new HtmlToPdfDocument() { GlobalSettings = { PaperSize = PaperKind.Letter, Orientation = Orientation.Portrait, Margins = showHeader ? new MarginSettings(20, 20, 20, 10) : new MarginSettings(10, 10, 10, 10), }, Objects = { new ObjectSettings() { HtmlContent = htmlDocumentContent, } } }; CustomAssemblyLoadContext context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(System.IO.Directory.GetCurrentDirectory() + "\\libwkhtmltox.dll"); var converter = new SynchronizedConverter(new PdfTools()); return(_converter.Convert(doc)); }
public async Task <IActionResult> GenerateSomeDocumentAsync() { var path = "C:\\Dev\\VSCode\\MailRoomSolution\\MailRoom.Api\\Utils\\v0.12.4\\64 bit\\libwkhtmltox.dll"; CustomAssemblyLoadContext context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(path); var converter = new SynchronizedConverter(new PdfTools()); var doc = converter.Convert(new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus, }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = "This is my Test PDF...", WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings ={ FontSize =9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 } } } }); return(File(doc, "application/pdf")); }
public async Task <ActionResult <PrintData> > GetPDF(int pkey) { var printout = await _context.PrintData.FindAsync(pkey); if (printout == null) { return(NotFound()); } var converter = new SynchronizedConverter(new PdfTools()); var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4 }, Objects = { new ObjectSettings() { PagesCount = true, //HtmlContent = printout.LetterData, HtmlContent = GetHtml("C:\\temp\\template.htm"), WebSettings ={ DefaultEncoding = "utf-8", PrintMediaType = true } } } }; byte[] pdf = converter.Convert(doc); return(File(pdf, "application/pdf")); }
public IEnumerable <string> Get() { var converter = new SynchronizedConverter(new PdfTools()); var output = converter.Convert(new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, //Orientation = Orientation.Portrait, //PaperSize = PaperKind.A4, //Margins = new MarginSettings() { Top = 10 }, Out = @"C:\temp\dinktopdf-test.pdf", }, Objects = { new ObjectSettings() { Page = "https://monatglobal.com", }, } }); return(new string[] { "value1", "value2" }); }
public IActionResult TestConvert() { var converter = new SynchronizedConverter(new PdfTools()); var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus, }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In consectetur mauris eget ultrices iaculis. Ut odio viverra, molestie lectus nec, venenatis turpis.", WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings ={ FontSize =9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 } } } }; byte[] pdf = converter.Convert(doc); var response = File(pdf, "application/octet-stream", "File.pdf"); // FileStreamResult return(response); }
public IActionResult ConvertFromUrl([FromQuery] string url, [FromBody] ConvertOptions options) { var webClient = new System.Net.WebClient(); var downloadedHtml = webClient.DownloadString(url); var converter = new SynchronizedConverter(new PdfTools()); var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus, }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = downloadedHtml, WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings ={ FontSize =9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 } } } }; byte[] pdf = converter.Convert(doc); var response = File(pdf, "application/octet-stream", "File.pdf"); // FileStreamResult return(response); }
public async Task <IActionResult> Create(string id) { var converter = new SynchronizedConverter(new PdfTools()); PatientUser user; if (id == null) { user = (PatientUser)await _userManager.GetUserAsync(HttpContext.User); } else { user = (PatientUser)await _userManager.FindByIdAsync(id); } var query = from appointment in _context.Appointments.AsEnumerable() where appointment.PatientID == user.Id && (DateTime.Parse(appointment.Date) < DateTime.Now) == true select appointment; PdfViewModel records = new PdfViewModel(); records.PatientName = user.FirstName + " " + user.LastName; records.Appointments = query; var documentContent = await _templateService.RenderTemplateAsync("Pdf/Records", records); var output = converter.Convert(new HtmlToPdfDocument() { Objects = { new ObjectSettings() { HtmlContent = documentContent } } }); return(File(output, "application/pdf")); }
public async Task <IActionResult> Get2() { var converter = new SynchronizedConverter(new PdfTools()); var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus, }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = @"<h2>Bastian ist der beste</h2>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In consectetur mauris eget ultrices iaculis. Ut odio viverra, molestie lectus nec, venenatis turpis.", WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings ={ FontSize =9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 } } } }; byte[] pdf = converter.Convert(doc); var stream = new MemoryStream(pdf); return(File(stream, "application/pdf", "rosi.pdf")); //return File(pdf, "application/pdf", "rosi.pdf"); }
static void MultiThreadExample(string htmlContent) { var converter = new SynchronizedConverter(new PdfTools()); var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus, }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = htmlContent, WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings ={ FontSize =9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 } } } }; var pdf = converter.Convert(doc); var base64 = Convert.ToBase64String(pdf); Console.WriteLine(base64); }
public static void GeneratePdf() { var page = "plain"; var slnpath = $@"{Directory.GetCurrentDirectory()}\..\..\..\.."; var htmlpath = $@"{slnpath}\HtmlTemplates\{page}.html"; var pdfpath = $@"{slnpath}\PdfFiles\{page}.pdf"; var dllpath = $@"{slnpath}\DinkNative64bit\libwkhtmltox.dll"; var html = new StringBuilder(File.ReadAllText(htmlpath)); var _converter = new SynchronizedConverter(new PdfTools()); var context = new CustomAssemblyLoadContext().LoadUnmanagedLibrary(dllpath); var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "PDF Report", //Out = @"D:\PDFCreator\Employee_Report.pdf" USE THIS PROPERTY TO SAVE PDF TO A PROVIDED LOCATION }; var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = html.ToString(), //Page = "https://code-maze.com/", USE THIS PROPERTY TO GENERATE PDF CONTENT FROM AN HTML PAGE WebSettings = { DefaultEncoding = "utf-8" }, //, UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") }, HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true }, FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }, }; var pdf = new HtmlToPdfDocument() { GlobalSettings = globalSettings, Objects = { objectSettings } }; //_converter.Convert(pdf); IF WE USE Out PROPERTY IN THE GlobalSettings CLASS, THIS IS ENOUGH FOR CONVERSION var file = _converter.Convert(pdf); File.WriteAllBytes(pdfpath, file); //return Ok("Successfully created PDF document."); //return File(file, "application/pdf", "EmployeeReport.pdf"); //USE THIS RETURN STATEMENT TO DOWNLOAD GENERATED PDF DOCUMENT //return File(file, "application/pdf"); }
public DinkReportGenerator(IOutputPersistence persistence, IHttpContextAccessor httpContextAccessor, IOptions <EcosetAppOptions> options, ILogger <DinkReportGenerator> logger) { _persistence = persistence; _context = httpContextAccessor; _converter = new SynchronizedConverter(new PdfTools()); _options = options.Value; _logger = logger; _converter.PhaseChanged += LogPhaseChanged; _converter.ProgressChanged += LogProgressChanged; _converter.Warning += LogWarning; _converter.Error += LogError; }
public static void Main(string[] args) { converter = new SynchronizedConverter(new PdfTools()); var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Grayscale, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings() { Top = 10 }, }, Objects = { new ObjectSettings() { Page = "http://www.color-hex.com/" } } }; Action(doc); var doc2 = new HtmlToPdfDocument() { GlobalSettings = { PaperSize = PaperKind.A4Small }, Objects = { new ObjectSettings() { Page = "http://google.com/", } } }; Action(doc2); Console.ReadKey(); }
private static void Init() { var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile("secrets/appsettings.secrets.json", optional: true) .AddEnvironmentVariables(); IConfigurationRoot Configuration = builder.Build(); // Retrieve configuration from sections ApplicationSettings.ConnectionString = Configuration.GetSection("ApplicationSettings:ConnectionString")?.Value; ApplicationSettings.DatabaseId = Configuration.GetSection("ApplicationSettings:DatabaseId")?.Value; ApplicationSettings.ReportCollection = Configuration.GetSection("ApplicationSettings:ReportCollection")?.Value; ApplicationSettings.RabbitMQUsername = Configuration.GetSection("ApplicationSettings:RabbitMQUsername")?.Value; ApplicationSettings.RabbitMQPassword = Configuration.GetSection("ApplicationSettings:RabbitMQPassword")?.Value; ApplicationSettings.RabbitMQHostname = Configuration.GetSection("ApplicationSettings:RabbitMQHostname")?.Value; ApplicationSettings.RabbitMQPort = Convert.ToInt16(Configuration.GetSection("ApplicationSettings:RabbitMQPort")?.Value); ApplicationSettings.DispatchQueueName = Configuration.GetSection("ApplicationSettings:DispatchQueueName")?.Value; ApplicationSettings.KeyVaultCertificateName = Configuration.GetSection("ApplicationSettings:KeyVaultCertificateName")?.Value; ApplicationSettings.KeyVaultClientId = Configuration.GetSection("ApplicationSettings:KeyVaultClientId")?.Value; ApplicationSettings.KeyVaultClientSecret = Configuration.GetSection("ApplicationSettings:KeyVaultClientSecret")?.Value; ApplicationSettings.KeyVaultIdentifier = Configuration.GetSection("ApplicationSettings:KeyVaultIdentifier")?.Value; ApplicationSettings.KeyVaultEncryptionKey = Configuration.GetSection("ApplicationSettings:KeyVaultEncryptionKey")?.Value; ApplicationSettings.SendGridAPIKey = Configuration.GetSection("ApplicationSettings:SendGridAPIKey")?.Value; mongoDBConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = ApplicationSettings.ConnectionString, DatabaseId = ApplicationSettings.DatabaseId, UserCollection = ApplicationSettings.ReportCollection }; keyVaultConnectionInfo = new KeyVaultConnectionInfo() { CertificateName = ApplicationSettings.KeyVaultCertificateName, ClientId = ApplicationSettings.KeyVaultClientId, ClientSecret = ApplicationSettings.KeyVaultClientSecret, KeyVaultIdentifier = ApplicationSettings.KeyVaultIdentifier }; using (KeyVaultHelper keyVaultHelper = new KeyVaultHelper(keyVaultConnectionInfo)) { secret = keyVaultHelper.GetVaultKeyAsync(ApplicationSettings.KeyVaultEncryptionKey).Result; } pdfTools = new PdfTools(); converter = new SynchronizedConverter(pdfTools); }
public void Print(CalculatedPriceModel priceModel) { string fileStoragePath = _configuration.GetValue <string>(Constants.FileStoragePath); if (string.IsNullOrWhiteSpace(fileStoragePath)) { throw new Exception(string.Format(ErrorMessageConstants.InvalidConfigurationKey, Constants.FileStoragePath)); } var context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll")); var _converter = new SynchronizedConverter(new PdfTools()); if (!Directory.Exists(fileStoragePath)) { Directory.CreateDirectory(fileStoragePath); } var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "PDF Report", Out = Path.Combine(fileStoragePath, "GoldPriceEstimation" + "_" + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss_fffff") + ".pdf") }; var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = HelperClass.GetHTMLString(priceModel), WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") }, HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true }, FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" } }; var pdf = new HtmlToPdfDocument() { GlobalSettings = globalSettings, Objects = { objectSettings } }; _converter.Convert(pdf); }
public static void Main(string[] args) { converter = new SynchronizedConverter(new PdfTools()); var doc = new HtmlToPdfDocument { GlobalSettings = { ColorMode = ColorMode.Grayscale, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 } }, Objects = { new ObjectSettings { Page = "http://www.color-hex.com/" } } }; var t1 = Task.Run(() => Action(doc)); var doc2 = new HtmlToPdfDocument { GlobalSettings = { PaperSize = PaperKind.A4Small }, Objects = { new ObjectSettings { Page = "http://google.com/" } } }; var t2 = Task.Run(() => Action(doc2)); Task.WaitAll(t1, t2); }
private static void HtmlToPdf() { var source = Path.Combine("Templates", "template.html"); Console.WriteLine(source); var html = ReadFile(source); var destination = Path.Combine("Files", DateTime.UtcNow.Ticks.ToString() + "test.pdf"); Console.WriteLine(destination); var converter = new SynchronizedConverter(new PdfTools()); var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus, }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = html, WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings ={ FontSize =9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 } } } }; byte[] pdf = converter.Convert(doc); if (!Directory.Exists("Files")) { Directory.CreateDirectory("Files"); } using (FileStream stream = new FileStream(destination, FileMode.Create)) { stream.Write(pdf, 0, pdf.Length); } }
public string Create(string guid, SynchronizedConverter converter, DispatchMessage dispatchMessage) { string result = string.Empty; converter.PhaseChanged += Converter_PhaseChanged; converter.ProgressChanged += Converter_ProgressChanged; converter.Finished += Converter_Finished; converter.Warning += Converter_Warning; converter.Error += Converter_Error; var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, //Out = $"{guid}.pdf", DocumentTitle = "PDF Report" }; var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = TemplateGenerator.GetHTMLString(dispatchMessage), WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = "styles.css" }, HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true }, FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" } }; var document = new HtmlToPdfDocument() { GlobalSettings = globalSettings, Objects = { objectSettings } }; byte[] pdf = converter.Convert(document); result = Convert.ToBase64String(pdf); return(result); }
private static byte[] BuildPdf(string html) { var pdfConverter = new SynchronizedConverter(new PdfTools()); return(pdfConverter.Convert(new HtmlToPdfDocument() { Objects = { new ObjectSettings { HtmlContent = html } }, GlobalSettings = new GlobalSettings() { DocumentTitle = "My dumb PDF document", Orientation = Orientation.Portrait } })); }
public IActionResult PdfSource([FromBody] HtmlSource htmlSource) //string htmlContent { //var converter = new BasicConverter(new PdfTools()); CustomAssemblyLoadContext context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(@"C:\Users\stani\Desktop\storemanagementsystemweb\StoreSystem.Web\libwkhtmltox.dll"); var converter = new SynchronizedConverter(new PdfTools()); var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings() { Top = 10 }, Out = @"D:\test.pdf", }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = htmlSource.Source, WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings ={ FontSize =9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 } } } }; converter.Convert(doc); return(StatusCode(200, "success")); }
public async Task <IActionResult> GetInvoicePdf(string orderNumber) { var searchCriteria = AbstractTypeFactory <CustomerOrderSearchCriteria> .TryCreateInstance(); searchCriteria.Number = orderNumber; searchCriteria.Take = 1; var orders = await _searchService.SearchCustomerOrdersAsync(searchCriteria); var order = orders.Results.FirstOrDefault(); if (order == null) { throw new InvalidOperationException($"Cannot find order with number {orderNumber}"); } var notification = new InvoiceEmailNotification { CustomerOrder = order }; await _notificationSender.SendNotificationAsync(notification, order.LanguageCode); var message = AbstractTypeFactory <NotificationMessage> .TryCreateInstance($"{notification.Kind}Message"); message.LanguageCode = order.LanguageCode; var emailNotificationMessage = (EmailNotificationMessage)notification.ToMessage(message, _notificationTemplateRenderer); var pdf = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus }, Objects = { new ObjectSettings { PagesCount = true, HtmlContent = emailNotificationMessage.Body } } }; var converter = new SynchronizedConverter(new PdfTools()); var byteArray = converter.Convert(pdf); Stream stream = new MemoryStream(byteArray); return(new FileStreamResult(stream, "application/pdf")); }
public static async Task <byte[]> CreatePdfReport(OrderViewModel order, string fileName, ILogger log) { try { var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus, }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = $"<div style='border:solid; border - width: thin; background - color:lightgrey'>Contoso Sport League - Purchase Receipt</div><br/>" + $"<div style = 'text-align:right;font-weight:bold'>Order ID: {order.OrderId}</ div >" + $"<div style = 'text-align:right;font-weight:bold'>Total: ${order.Total}</ div >" + $"<div style = 'text-align:center;font-weight:bold'>Thank you for your order {order.FirstName}</ div >", WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings ={ FontSize =9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 } } } }; var converter = new SynchronizedConverter(new PdfTools()); return(await Task.FromResult(converter.Convert(doc))); } catch (Exception ex) { log.LogError(ex, ex.Message); throw ex; } }
private PdfConvertorSingleton() { Converter = new SynchronizedConverter(new PdfTools()); }
public static void ClassInitialize(TestContext context) { Converter = new SynchronizedConverter(new PdfTools()); }
public PdfGenerator() { _isDisposed = false; _pdfTools = new PdfTools(); _synchronizedConverter = new SynchronizedConverter(_pdfTools); }
public static void Main(string[] args) { Console.WriteLine( $"RID: {RuntimeEnvironment.GetRuntimeIdentifier()}, " + $"OS: {RuntimeEnvironment.OperatingSystem}, " + $"OSPlatform: {RuntimeEnvironment.OperatingSystemPlatform}, " + $"OSVersion: {RuntimeEnvironment.OperatingSystemVersion}, " + $"Architecture: {RuntimeEnvironment.RuntimeArchitecture}, " + $"Framework: {Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName}" ); if (!Directory.Exists("Files")) { Directory.CreateDirectory("Files"); } _converter = new SynchronizedConverter(new PdfTools()); _converter.PhaseChanged += Converter_PhaseChanged; _converter.ProgressChanged += Converter_ProgressChanged; _converter.Finished += Converter_Finished; _converter.Warning += Converter_Warning; _converter.Error += Converter_Error; var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Grayscale, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings() { Top = 10 }, }, Objects = { new ObjectSettings() { Page = "https://www.color-hex.com/" } } }; var task = Task.Run(() => Action(doc)); var doc2 = new HtmlToPdfDocument() { GlobalSettings = { PaperSize = PaperKind.A4Small }, Objects = { new ObjectSettings() { Page = "https://google.com/" } } }; var task2 = Task.Run(() => Action(doc2)); Task.WaitAll(task, task2); if (!Debugger.IsAttached) { Console.ReadKey(); } }
public PdfController(IConverter converter) { PdfConverter = converter as SynchronizedConverter; }