/// <summary> /// /// </summary> /// <param name="AllLetters">HTML text (could be several pages)</param> /// <param name="APathForImagesBase">Could be null if I'm not printing images!</param> public void PreviewOrPrint(String AllLetters, String APathForImagesBase) { System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument(); bool printerInstalled = printDocument.PrinterSettings.IsValid; if (!printerInstalled) { MessageBox.Show(Catalog.GetString("There is no printer, so printing is not possible")); return; } FGfxPrinter = new TGfxPrinter(printDocument, TGfxPrinter.ePrinterBehaviour.eFormLetter); try { TPrinterHtml htmlPrinter = new TPrinterHtml(AllLetters, APathForImagesBase, FGfxPrinter); FGfxPrinter.Init(eOrientation.ePortrait, htmlPrinter, eMarginType.ePrintableArea); this.ppvLetters.InvalidatePreview(); this.ppvLetters.Document = FGfxPrinter.Document; this.ppvLetters.Zoom = 1; FGfxPrinter.Document.EndPrint += new PrintEventHandler(this.EndPrint); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Use a .NET PrintPreview Dialog to print (or not print) this (possibly multi-page) HTML document. /// </summary> /// <param name="HtmlPages"></param> public static void PreviewOrPrint(String HtmlPages) { System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument(); bool printerInstalled = printDocument.PrinterSettings.IsValid; if (!printerInstalled) { MessageBox.Show(Catalog.GetString("There is no printer, so printing is not possible")); return; } TGfxPrinter GfxPrinter = new TGfxPrinter(printDocument, TGfxPrinter.ePrinterBehaviour.eFormLetter); TPrinterHtml htmlPrinter = new TPrinterHtml(HtmlPages, TAppSettingsManager.GetValue("Formletters.Path"), GfxPrinter); GfxPrinter.Init(eOrientation.ePortrait, htmlPrinter, eMarginType.ePrintableArea); CoolPrintPreviewDialog PrintDlg = new CoolPrintPreviewDialog(); PrintDlg.Document = GfxPrinter.Document; PrintDlg.ClientSize = new System.Drawing.Size(500, 720); try { PrintDlg.ShowDialog(); } catch (Exception) // if the user presses Cancel, an exception may be raised! { } }
void TbbPreviewClick(object sender, EventArgs e) { PrintDocument doc = new PrintDocument(); FGfxPrinter = new TGfxPrinter(doc, TGfxPrinter.ePrinterBehaviour.eFormLetter); TPrinterHtml htmlPrinter = new TPrinterHtml(txtHTMLText.Text, String.Empty, FGfxPrinter); FGfxPrinter.Init(eOrientation.ePortrait, htmlPrinter, eMarginType.ePrintableArea); doc.EndPrint += new PrintEventHandler(this.PrintDocument_EndPrint); printPreviewControl1.Document = doc; printPreviewControl1.InvalidatePreview(); printPreviewControl1.Rows = 1; }
/// <summary> /// /// </summary> /// <param name="APaymentNum"></param> /// <param name="ALedgerNumber"></param> public void PrintRemittanceAdvice(Int32 APaymentNum, Int32 ALedgerNumber) { FLedgerNumber = ALedgerNumber; txtPaymentNum.NumberValueInt = APaymentNum; AccountsPayableTDS PaymentDetails = TRemote.MFinance.AP.WebConnectors.LoadAPPayment(ALedgerNumber, APaymentNum); if (PaymentDetails.AApPayment.Rows.Count == 0) // unable to load this payment.. { lblLoadStatus.Text = String.Format(Catalog.GetString("Error - can't load Payment number {0}."), APaymentNum); return; } SortedList <string, List <string> > FormValues = new SortedList <string, List <string> >(); // // load my own country code, so I don't print it on letters to my own country. // string LocalCountryCode = TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetCountryCodeFromSiteLedger(); // // These are the fields that I will pull out of the TDS... // FormValues.Add("SupplierName", new List <string>()); FormValues.Add("SupplierAddress", new List <string>()); FormValues.Add("PaymentDate", new List <string>()); FormValues.Add("OurReference", new List <string>()); FormValues.Add("InvoiceDate", new List <string>()); FormValues.Add("InvoiceNumber", new List <string>()); FormValues.Add("InvoiceAmount", new List <string>()); FormValues.Add("TotalPayment", new List <string>()); FormValues["SupplierName"].Add(PaymentDetails.PPartner[0].PartnerShortName); if (PaymentDetails.PLocation[0].CountryCode == LocalCountryCode) { PaymentDetails.PLocation[0].CountryCode = ""; // Don't print country code it it's the same as my own. } FormValues["SupplierAddress"].Add(Calculations.DetermineLocationString(PaymentDetails.PLocation[0], Calculations.TPartnerLocationFormatEnum.plfHtmlLineBreak)); String DatePattern = Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongDatePattern; DatePattern = "dd MMMM yyyy"; // The long pattern above is no good in UK, although it might be OK in other cultures... FormValues["PaymentDate"].Add(PaymentDetails.AApPayment[0].PaymentDate.Value.ToString(DatePattern)); FormValues["OurReference"].Add(PaymentDetails.AApSupplier[0].OurReference); foreach (AApDocumentRow Row in PaymentDetails.AApDocument.Rows) { FormValues["InvoiceDate"].Add(Row.DateIssued.ToString(DatePattern)); FormValues["InvoiceNumber"].Add(Row.DocumentCode); FormValues["InvoiceAmount"].Add(Row.TotalAmount.ToString("n2") + " " + PaymentDetails.AApSupplier[0].CurrencyCode); } FormValues["TotalPayment"].Add(PaymentDetails.AApPayment[0].Amount.ToString("n2") + " " + PaymentDetails.AApSupplier[0].CurrencyCode); String TemplateFilename = TAppSettingsManager.GetValue("Formletters.Path") + "\\ApRemittanceAdvice.html"; if (!File.Exists(TemplateFilename)) { lblLoadStatus.Text = String.Format(Catalog.GetString("Error - unable to load HTML template from {0}"), TemplateFilename); return; } FHtmlDoc = TFormLettersTools.PrintSimpleHTMLLetter(TemplateFilename, FormValues); System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument(); bool printerInstalled = printDocument.PrinterSettings.IsValid; if (!printerInstalled) { lblLoadStatus.Text = Catalog.GetString("There is no printer, so printing is not possible"); return; } FGfxPrinter = new TGfxPrinter(printDocument, TGfxPrinter.ePrinterBehaviour.eFormLetter); try { TPrinterHtml htmlPrinter = new TPrinterHtml(FHtmlDoc, TAppSettingsManager.GetValue("Formletters.Path"), FGfxPrinter); FGfxPrinter.Init(eOrientation.ePortrait, htmlPrinter, eMarginType.ePrintableArea); this.ppvLetters.InvalidatePreview(); this.ppvLetters.Document = FGfxPrinter.Document; this.ppvLetters.Zoom = 1; // GfxPrinter.Document.EndPrint += new PrintEventHandler(this.EndPrint); } catch (Exception ex) { MessageBox.Show(ex.Message); } btnPDF.Visible = true; btnCopy.Visible = true; lblLoadStatus.Text = ""; }