public void TestPDFPrinter() { const string FileName = "../../csharp/ICT/Testing/lib/Common/Printing/test.html"; string TextToPrint; if (!File.Exists(FileName)) { TextToPrint = "<html><body>" + String.Format("Cannot find file {0}", FileName) + "</body></html>"; } else { StreamReader r = new StreamReader(FileName); TextToPrint = r.ReadToEnd(); r.Close(); } TPdfPrinter pdfPrinter = new TPdfPrinter(TPdfPrinter.ePrinterBehaviour.eFormLetter); TPrinterHtml htmlPrinter = new TPrinterHtml(TextToPrint, String.Empty, pdfPrinter); pdfPrinter.Init(eOrientation.ePortrait, htmlPrinter, eMarginType.ePrintableArea); pdfPrinter.SavePDF("test.pdf"); }
void BtnPrintReportPDFClick(object sender, EventArgs e) { OpenFileDialog DialogOpen = new OpenFileDialog(); // see file in sub directory test data. // create file with method TResultList.WriteBinaryFile DialogOpen.Filter = "Binary Report File (*.bin)|*.bin"; DialogOpen.RestoreDirectory = true; DialogOpen.Title = "Open Binary Report File"; if (DialogOpen.ShowDialog() == DialogResult.OK) { TResultList Results = new TResultList(); TParameterList Parameters; Results.ReadBinaryFile(DialogOpen.FileName, out Parameters); TPetraIdentity PetraIdentity = new TPetraIdentity( "TESTUSER", "", "", "", "", DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, 0, -1, -1, false, false, false); UserInfo.GUserInfo = new TPetraPrincipal(PetraIdentity, null); PrintDocument doc = new PrintDocument(); TPdfPrinter pdfPrinter = new TPdfPrinter(doc, TGfxPrinter.ePrinterBehaviour.eReport); TReportPrinterLayout layout = new TReportPrinterLayout(Results, Parameters, pdfPrinter, true); pdfPrinter.Init(eOrientation.ePortrait, layout, eMarginType.ePrintableArea); pdfPrinter.SavePDF("test.pdf"); System.Diagnostics.Process.Start(Path.GetFullPath("test.pdf")); } }
private bool PrintToPDF(string AFilename, bool AWrapColumn) { PrintDocument doc = new PrintDocument(); TPdfPrinter pdfPrinter = new TPdfPrinter(doc, TGfxPrinter.ePrinterBehaviour.eReport); TReportPrinterLayout layout = new TReportPrinterLayout(FResultList, FParameterList, pdfPrinter, AWrapColumn); pdfPrinter.Init(eOrientation.ePortrait, layout, eMarginType.ePrintableArea); pdfPrinter.SavePDF(AFilename); return(true); }
void TbbSavePDFClick(object sender, EventArgs e) { PrintDocument doc = new PrintDocument(); TPdfPrinter pdfPrinter = new TPdfPrinter(doc, TGfxPrinter.ePrinterBehaviour.eFormLetter); TPrinterHtml htmlPrinter = new TPrinterHtml(txtHTMLText.Text, String.Empty, pdfPrinter); pdfPrinter.Init(eOrientation.ePortrait, htmlPrinter, eMarginType.ePrintableArea); pdfPrinter.SavePDF("test.pdf"); System.Diagnostics.Process.Start(Path.GetFullPath("test.pdf")); }
private bool PrintToPDF(string AFilename, bool AWrapColumn) { PrintDocument doc = new PrintDocument(); TPdfPrinter pdfPrinter = new TPdfPrinter(doc, TGfxPrinter.ePrinterBehaviour.eReport); TReportPrinterLayout layout = new TReportPrinterLayout(FResultList, FParameterList, pdfPrinter, AWrapColumn); eOrientation Orientation; if (pdfPrinter.Document.DefaultPageSettings.Landscape) { Orientation = eOrientation.eLandscape; } else { Orientation = eOrientation.ePortrait; } pdfPrinter.Init(Orientation, layout, eMarginType.ePrintableArea); pdfPrinter.SavePDF(AFilename); return(true); }
/// create PDF public static string GeneratePDF(Int64 APartnerKey, string ACountryCode, TApplicationFormData AData, out string ADownloadIdentifier) { string FileName = TFormLettersTools.GetRoleSpecificFile(TAppSettingsManager.GetValue("Formletters.Path"), "ApplicationPDF", AData.registrationcountrycode, AData.formsid, "html"); string HTMLText = string.Empty; if (!File.Exists(FileName)) { HTMLText = "<html><body>" + String.Format("Cannot find file {0}", FileName) + "</body></html>"; } else { StreamReader r = new StreamReader(FileName); HTMLText = r.ReadToEnd(); r.Close(); } if ((AData.existingpartnerkey != null) && AData.existingpartnerkey.StartsWith("If you cannot find it")) { AData.RawData = AData.RawData.Replace(AData.existingpartnerkey, "N/A"); AData.existingpartnerkey = ""; } if (AData.groupwish == null) { Regex regex = new Regex(@"^.*#GROUPWISH.*$", RegexOptions.Multiline); HTMLText = regex.Replace(HTMLText, ""); } HTMLText = TJsonTools.ReplaceKeywordsWithData(AData.RawData, HTMLText); HTMLText = HTMLText.Replace("#DATE", StringHelper.DateToLocalizedString(DateTime.Today)); HTMLText = HTMLText.Replace("#FORMLETTERPATH", TAppSettingsManager.GetValue("Formletters.Path")); HTMLText = HTMLText.Replace("#REGISTRATIONID", StringHelper.FormatStrToPartnerKeyString(APartnerKey.ToString())); HTMLText = HTMLText.Replace("#PHOTOPARTICIPANT", TAppSettingsManager.GetValue("Server.PathData") + Path.DirectorySeparatorChar + "photos" + Path.DirectorySeparatorChar + APartnerKey.ToString() + ".jpg"); HTMLText = HTMLText.Replace("#HTMLRAWDATA", TJsonTools.DataToHTMLTable(AData.RawData)); PrintDocument doc = new PrintDocument(); TPdfPrinter pdfPrinter = new TPdfPrinter(doc, TGfxPrinter.ePrinterBehaviour.eFormLetter); TPrinterHtml htmlPrinter = new TPrinterHtml(HTMLText, String.Empty, pdfPrinter); pdfPrinter.Init(eOrientation.ePortrait, htmlPrinter, eMarginType.ePrintableArea); string pdfPath = TAppSettingsManager.GetValue("Server.PathData") + Path.DirectorySeparatorChar + "pdfs"; if (!Directory.Exists(pdfPath)) { Directory.CreateDirectory(pdfPath); } string pdfFilename = pdfPath + Path.DirectorySeparatorChar + APartnerKey.ToString() + ".pdf"; pdfPrinter.SavePDF(pdfFilename); string downloadPath = TAppSettingsManager.GetValue("Server.PathData") + Path.DirectorySeparatorChar + "downloads"; if (!Directory.Exists(downloadPath)) { Directory.CreateDirectory(downloadPath); } // Create a link file for this PDF ADownloadIdentifier = TPatchTools.GetMd5Sum(pdfFilename); StreamWriter sw = new StreamWriter(downloadPath + Path.DirectorySeparatorChar + ADownloadIdentifier + ".txt"); sw.WriteLine("pdfs"); sw.WriteLine(Path.GetFileName(pdfFilename)); sw.Close(); return(pdfFilename); }