public ProductProfitReport(string PriceSymbol) { this.PriceSymbol = PriceSymbol; WidhtMillimeters = 210 - 40; // html right20 + left20 margin 40 HeightMillimeters = 280 - 20; // html top10 + bottom10 margin 20 MarginsMillimeters = PaperMargins.All(Length.Millimeters(0)); }
public ProductLabelMedium(string PriceSymbol) { this.PriceSymbol = PriceSymbol; WidhtMillimeters = 40; HeightMillimeters = 30; MarginsMillimeters = PaperMargins.None(); }
public SummaryReport(string PriceSymbol) { this.PriceSymbol = PriceSymbol; WidhtMillimeters = 48; MarginsMillimeters = PaperMargins.None(); IsThermalPrinter = true; }
public ImportMiddleReport(Import import, List <Product> productList, Printer printer, int heightMillimeters, string PriceSymbol, long Lang = -1) { this.Import = import; this.ProductList = productList; this.Printer = printer; this.Lang = Lang; this.PriceSymbol = PriceSymbol; WidhtMillimeters = 200; HeightMillimeters = heightMillimeters - 10; MarginsMillimeters = PaperMargins.All(Length.Millimeters(5)); }
public ImportReport(Import import, List <Product> productList, Printer printer, string PriceSymbol, long Lang = -1) { this.Import = import; this.ProductList = productList; this.Printer = printer; this.Lang = Lang; this.PriceSymbol = PriceSymbol; WidhtMillimeters = 48; MarginsMillimeters = PaperMargins.None(); IsThermalPrinter = true; }
public BackstageTakeoutReport(Takeout takeout, List <Product> productList, Printer printer, List <Request> Requests, long Lang = -1) { this.Takeout = takeout; this.ProductList = productList; this.Printer = printer; this.Lang = Lang; this.Requests = Requests; this.BillLang = takeout.Lang; WidhtMillimeters = 72.1; MarginsMillimeters = PaperMargins.None(); IsThermalPrinter = true; }
public OrderCheckoutMiddleReport(Order order, List <Product> productList, Printer printer, int heightMillimeters, string PriceSymbol, long Lang = -1) { this.Order = order; this.ProductList = productList; this.Printer = printer; this.Lang = Lang; this.PriceSymbol = PriceSymbol; this.BillLang = order.Lang; WidhtMillimeters = 200; HeightMillimeters = heightMillimeters - 10; MarginsMillimeters = PaperMargins.All(Length.Millimeters(5)); }
public OrderCheckoutReport(Order order, List <Product> productList, Printer printer, string PriceSymbol, long Lang = -1) { this.Order = order; this.ProductList = productList; this.Printer = printer; this.Lang = Lang; this.PriceSymbol = PriceSymbol; this.BillLang = order.Lang; WidhtMillimeters = 48; MarginsMillimeters = PaperMargins.None(); IsThermalPrinter = true; }
public TakeoutCheckoutReport(Takeout takeout, List <Product> productList, Printer printer, string PriceSymbol, long Lang = -1) { this.Takeout = takeout; this.ProductList = productList; this.Printer = printer; this.Lang = Lang; this.PriceSymbol = PriceSymbol; this.BillLang = takeout.Lang; WidhtMillimeters = 48; MarginsMillimeters = PaperMargins.None(); IsThermalPrinter = true; }
/// <summary> /// Runs the report returning the number of statements that were generated /// </summary> public int RunReport() { UpdateProgress("Connecting..."); // Login and setup options for REST calls RockConfig rockConfig = RockConfig.Load(); _rockRestClient = new RockRestClient(rockConfig.RockBaseUrl); _rockRestClient.Login(rockConfig.Username, rockConfig.Password); UpdateProgress("Getting Recipients..."); var recipientList = _rockRestClient.PostDataWithResult <Rock.StatementGenerator.StatementGeneratorOptions, List <Rock.StatementGenerator.StatementGeneratorRecipient> >("api/FinancialTransactions/GetStatementGeneratorRecipients", this.Options); this.RecordCount = recipientList.Count; this.RecordIndex = 0; var tasks = new List <Task>(); // initialize the pdfStreams list for all the recipients so that it can be populated safely in the pdf generation threads List <Stream> pdfStreams = recipientList.Select(a => ( Stream )null).ToList(); UpdateProgress("Getting Statements..."); foreach (var recipent in recipientList) { StringBuilder sbUrl = new StringBuilder(); sbUrl.Append($"api/FinancialTransactions/GetStatementGeneratorRecipientResult?GroupId={recipent.GroupId}"); if (recipent.PersonId.HasValue) { sbUrl.Append($"&PersonId={recipent.PersonId.Value}"); } var recipentResult = _rockRestClient.PostDataWithResult <Rock.StatementGenerator.StatementGeneratorOptions, Rock.StatementGenerator.StatementGeneratorRecipientResult>(sbUrl.ToString(), this.Options); int documentNumber = this.RecordIndex; if ((this.Options.ExcludeOptedOutIndividuals && recipentResult.OptedOut) || (recipentResult.Html == null)) { // don't generate a statement if opted out or no statement html pdfStreams[documentNumber] = null; } else { var html = recipentResult.Html; var footerHtml = recipentResult.FooterHtml; var task = Task.Run(() => { var pdfGenerator = Pdf.From(html); string footerHtmlPath = Path.ChangeExtension(Path.GetTempFileName(), "html"); string footerUrl = null; if (!string.IsNullOrEmpty(footerHtml)) { File.WriteAllText(footerHtmlPath, footerHtml); footerUrl = "file:///" + footerHtmlPath.Replace('\\', '/'); } if (footerUrl != null) { pdfGenerator = pdfGenerator.WithObjectSetting("footer.htmlUrl", footerUrl); } else { pdfGenerator = pdfGenerator.WithObjectSetting("footer.fontSize", "10"); pdfGenerator = pdfGenerator.WithObjectSetting("footer.right", "Page [page] of [topage]"); } var pdfBytes = pdfGenerator .WithMargins(PaperMargins.All(Length.Millimeters(10))) .WithoutOutline() .Portrait() .Content(); var pdfStream = new MemoryStream(pdfBytes); System.Diagnostics.Debug.Assert(pdfStreams[documentNumber] == null, "Threading issue: pdfStream shouldn't already be assigned"); pdfStreams[documentNumber] = pdfStream; if (File.Exists(footerHtmlPath)) { File.Delete(footerHtmlPath); } }); tasks.Add(task); tasks = tasks.Where(a => a.Status != TaskStatus.RanToCompletion).ToList(); } this.RecordIndex++; UpdateProgress("Processing..."); } Task.WaitAll(tasks.ToArray()); UpdateProgress("Creating PDF..."); this.RecordIndex = 0; // remove any statements that didn't get generated due to OptedOut pdfStreams = pdfStreams.Where(a => a != null).ToList(); this.RecordCount = pdfStreams.Count(); int maxStatementsPerChapter = RecordCount; bool useChapters = this.Options.StatementsPerChapter.HasValue; if (this.Options.StatementsPerChapter.HasValue) { maxStatementsPerChapter = this.Options.StatementsPerChapter.Value; } if (maxStatementsPerChapter < 1) { // just in case they entered 0 or a negative number useChapters = false; maxStatementsPerChapter = RecordCount; } int statementsInChapter = 0; int chapterIndex = 1; PdfDocument resultPdf = new PdfDocument(); try { if (pdfStreams.Any()) { var lastPdfStream = pdfStreams.LastOrDefault(); foreach (var pdfStream in pdfStreams) { UpdateProgress("Creating PDF..."); this.RecordIndex++; PdfDocument pdfDocument = PdfReader.Open(pdfStream, PdfDocumentOpenMode.Import); foreach (var pdfPage in pdfDocument.Pages.OfType <PdfPage>()) { resultPdf.Pages.Add(pdfPage); } statementsInChapter++; if (useChapters && ((statementsInChapter >= maxStatementsPerChapter) || pdfStream == lastPdfStream)) { string filePath = string.Format(@"{0}\{1}-chapter{2}.pdf", this.Options.SaveDirectory, this.Options.BaseFileName, chapterIndex); SavePdfFile(resultPdf, filePath); resultPdf.Dispose(); resultPdf = new PdfDocument(); statementsInChapter = 0; chapterIndex++; } } if (useChapters) { // just in case we still have statements that haven't been written to a pdf if (statementsInChapter > 0) { string filePath = string.Format(@"{0}\{1}-chapter{2}.pdf", this.Options.SaveDirectory, this.Options.BaseFileName, chapterIndex); SavePdfFile(resultPdf, filePath); } } else { string filePath = string.Format(@"{0}\{1}.pdf", this.Options.SaveDirectory, this.Options.BaseFileName); SavePdfFile(resultPdf, filePath); } } } finally { resultPdf.Dispose(); } UpdateProgress("Complete"); return(this.RecordCount); }
/// <summary> /// 生成PDF /// </summary> /// <param name="htmlText"></param> /// <param name="widthMillimeters"></param> /// <param name="heightMillimeters"></param> /// <param name="IsThermalPrinter"></param> internal byte[] GetPDF(string htmlText, double widthMillimeters, ref double heightMillimeters, bool IsThermalPrinter, PaperMargins margins) { int dpi = GetDPI(); double zoom = 1 * (GetWindowsScaling() / 100.0); OpenHtmlToPdf.PaperSize size = null; if (IsThermalPrinter) { size = new OpenHtmlToPdf.PaperSize(Length.Millimeters(widthMillimeters), Length.Millimeters(10)); } else { size = new OpenHtmlToPdf.PaperSize(Length.Millimeters(widthMillimeters), Length.Millimeters(heightMillimeters)); } IPdfDocument doc = Pdf.From(htmlText).EncodedWith("utf-8"); byte[] finalPDF = null; finalPDF = doc.WithResolution(dpi).WithObjectSetting("load.zoomFactor", zoom.ToString()).WithObjectSetting("web.enableIntelligentShrinking", "false").WithMargins(margins).OfSize(size).Content(); var document = PdfReader.Open(new MemoryStream(finalPDF), PdfDocumentOpenMode.InformationOnly); int numberOfPages = document.PageCount; if (numberOfPages > 1 && IsThermalPrinter) { heightMillimeters = 10 * numberOfPages; finalPDF = doc.WithResolution(dpi).WithObjectSetting("load.zoomFactor", zoom.ToString()).WithObjectSetting("web.enableIntelligentShrinking", "false").WithMargins(margins).OfSize(new OpenHtmlToPdf.PaperSize(Length.Millimeters(widthMillimeters), Length.Millimeters(heightMillimeters))).Content(); } //File.WriteAllText("y:\\test1111.html", htmlText); //using (FileStream fs = new FileStream("y:\\test1111.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite)) //{ // fs.Write(finalPDF, 0, finalPDF.Length); //} return(finalPDF); }