public IActionResult CreateHtmlString(string contratcIds, string request) { try { IContractRepository Repository = new ContractRepository(); List <Contract> contratcs = Repository.GetByIdStringList(contratcIds); var htmlContent = TemplateGenerator.GetHTMLString(contratcs, request); return(Content(htmlContent, "text/html")); } catch (System.Exception) { throw; } }
public async Task <string> GetHTMLString(int billId) { var bill = await _unitOfWork.Bills.GetByInclude(billId); if (bill == null) { throw new Exception( string.Format("Could not find bill with id: {0}", billId)); } var templateGenerator = new TemplateGenerator(); return(templateGenerator.GetHTMLString(bill)); }
public async Task <IActionResult> CreatePDF(ExportDatesViewModel model) { var user = this.User.Claims.ToList(); var getUserById = await _jitService.GetUserById(Convert.ToInt32(user[1].Value)); var getAllProjectsByUser = await _jitService.GetAllProjectsBetweenDates(Convert.ToInt32(user[1].Value), model.StartDate, model.EndDate); var projectsForPDFCreation = _mapper.Map <ICollection <ProjectDto>, ICollection <ProjectViewModel> >(getAllProjectsByUser); var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "PDF Report", }; //if we want to save it on our hard disk //Out = @"E:\Employee_Report.pdf" var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = TemplateGenerator.GetHTMLString(projectsForPDFCreation, getUserById.Username), WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "Helpers", "pdf-generator.css") }, HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true }, FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Tech Resources d.o.o." } }; var pdf = new HtmlToPdfDocument() { GlobalSettings = globalSettings, Objects = { objectSettings } }; var file = _converter.Convert(pdf); try { return(File(file, "application/pdf")); } catch (Exception) { return(RedirectToAction("NotFound", "Home")); } }
private void CreatePDFFileWithZip(ShapesDTO shapesDto, string fileName) { try { var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "PDF Report", Out = fileName }; var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = TemplateGenerator.GetHTMLString(shapesDto), 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); if (file != null) { } } catch (Exception exception) { Console.WriteLine(exception); throw; } }
public IActionResult CreatePDF() { CustomAssemblyLoadContext context = new CustomAssemblyLoadContext(); // var path = @"F:\ONIMTA IT API\OnimtaPrint\libwkhtmltox.dll"; var path = @"C:\Repos\Onimta\DevApi\OnimtaPrint\libwkhtmltox.dll"; context.LoadUnmanagedLibrary(path); var pdfId = Guid.NewGuid().ToString(); string location = @"F:\print\" + pdfId + "Employee_Report.pdf"; var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "PDF Report", Out = location }; 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 } }; _converter.Convert(pdf); return(Ok("Successfully created PDF document.")); }
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); }
public IActionResult CreatePDF() { var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "PDF Report", ViewportSize = "1920x1080", DPI = 300 }; var objectSettings = new ObjectSettings { WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "main.css"), }, UseLocalLinks = false, UseExternalLinks = false, ProduceForms = false, PagesCount = true, HtmlContent = TemplateGenerator.GetHTMLString(), //Page = "www.youtube.com", HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true }, FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report CS1" } }; var pdf = new HtmlToPdfDocument() { GlobalSettings = globalSettings, Objects = { objectSettings } }; var file = _converter.Convert(pdf); return(File(file, "application/pdf")); }
public IActionResult CreatePDF(long id) { var guest = _guestService.GetById(id); 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 = TemplateGenerator.GetHTMLString(guest), //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 = 25, Right = "Gdynia, " + DateTime.Now.ToString("dd.MM.yyyy"), Line = true }, FooterSettings = { FontName = "Arial", FontSize = 25, Line = true, Center = "MODERN PLACE" } }; 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); string invoiceName = "Faktura nr " + DateTime.Now.ToString("dd.MM.yyyy") + "-" + DateTime.Now.Millisecond + ".pdf"; //return Ok("Successfully created PDF document."); return(File(file, "application/pdf", invoiceName)); //return File(file, "application/pdf"); }
private async Task <bool> CreatePDfAsync(EstructuraDatosPDF datosPDF) { var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "PDF Report", Out = @"C:\PDFCreator\" + datosPDF.InfoGeneralCotizacion.Referencia + ".pdf" }; var templateGenerator = new TemplateGenerator(datosPDF); 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 } }; try { await Task.Run(() => _converter.Convert(pdf)).ConfigureAwait(false); return(true); } catch (Exception) { return(false); } }
public IActionResult CreatePDF() { var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "PDF Report", //Print pdf in local stroge //Out = @"C:\Users\User\Desktop\Pdfconvertor\Employee_Report.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 } }; //print pdf local stroge //_converter.Convert(pdf); //return Ok("Successfully created PDF document."); //print to Browser var file = _converter.Convert(pdf); return(File(file, "application/pdf")); //print to Browser }
public IActionResult CreatePDF() { 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 = TemplateGenerator.GetHTMLString(), //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); //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 async Task <IActionResult> CreatePDF(int addfare_seq) { // sudo apt-get install libgdiplus var addfare = await _pdf.Select(addfare_seq); var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DPI = 300, DocumentTitle = "", }; var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = TemplateGenerator.GetHTMLString(addfare), WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "style.css") }, HeaderSettings = { FontName = "NanumGothic", FontSize = 9, Right = "", Line = false }, FooterSettings = { FontName = "NanumGothic", FontSize = 9, Right = "", Line = false } }; var pdf = new HtmlToPdfDocument() { GlobalSettings = globalSettings, Objects = { objectSettings } }; var file = _converter.Convert(pdf); return(File(file, "application/pdf", addfare.name + "님_지급명세서_" + addfare.addfare_date.ToString("yyyy-MM-dd") + ".pdf")); // for downloading as sample.pdf }
public IActionResult CreatePDF([FromBody] DownloadPdf data) { CommonResponse commonResponse = new CommonResponse(); var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "PDF Report", Out = @"D:\DMS\Employee_Report.pdf" }; var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = TemplateGenerator.GetHTMLString(data), WebSettings = { DefaultEncoding = "utf -8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "Styles.css") }, HeaderSettings = { FontName = "Georgia", FontSize = 9, Right = "Page [page] of [toPage]", Line = true }, FooterSettings = { FontName = "Georgia", FontSize = 9, Line = true, Center = "Shiftwise Employee Details" } }; var pdf = new HtmlToPdfDocument { GlobalSettings = globalSettings, Objects = { objectSettings } }; converter.Convert(pdf); commonResponse.isStatus = true; commonResponse.response = appSettings.ImageUrl + "Employee_Report.pdf"; //var file = converter.Convert(pdf); //return File(file, "application/pdf","Employee.pdf"); return(Ok(commonResponse)); }
public IActionResult CreatePDF(int countPerPage = 10, int page = 1) { _stockCollection = _xmlToCollection.Execute(); List <Stock> list = _stockCollection.Stocks.Skip(countPerPage * (page - 1)).Take(countPerPage).ToList(); var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "PDF Reports", }; var objectSetting = new ObjectSettings { PagesCount = true, HtmlContent = TemplateGenerator.GetHTMLString(list), WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "Assets", "style.css") }, HeaderSettings = { FontName = "Arial", FontSize = 12, Right = "Page [Page] of [toPage]", Line = true }, FooterSettings = { FontName = "Arial", FontSize = 12, Center = "Report Footer", Line = true } }; var pdf = new HtmlToPdfDocument { GlobalSettings = globalSettings, Objects = { objectSetting } }; var file = _converter.Convert(pdf); return(File(file, "application/pdf")); }
public IActionResult Buy(int id) { var ticket = _unitOfWork.TicketRepository.Get(id.ToString()); var flight = _unitOfWork.FlightRepository.GetAll().Where(t => t.Id == ticket.FlightId).FirstOrDefault(); var user = _unitOfWork.UserRepository.GetAll().Where(t => t.Email == User.Identity.Name).First(); var viewTicket = new TicketViewModel() { Id = ticket.Id, Price = ticket.Price, FlightArrivingDate = flight.FlightArrivingDate, FlightDepartmentDate = flight.FlightDepartmentDate, LocationFrom = flight.LocationFrom, LocationTo = flight.LocationTo }; var listTicket = new List <TicketViewModel>(); listTicket.Add(viewTicket); var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "PDF Report", Out = @"C:\Ticket.pdf" }; var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = TemplateGenerator.GetHTMLString(listTicket), 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); var boughtTicket = new BoughtTicket() { LocationFrom = viewTicket.LocationFrom, LocationTo = viewTicket.LocationTo, Price = viewTicket.Price, User = user }; _unitOfWork.BoughtTicketRepository.Create(boughtTicket); _unitOfWork.TicketRepository.Delete(ticket.Id.ToString()); return(RedirectToAction("Index", "Cart")); }