示例#1
0
        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");
        }
示例#2
0
        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"));
            }
        }
示例#3
0
        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);
        }
示例#4
0
        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"));
        }
示例#5
0
        void TbbPrintPDFToScreenClick(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);

            FGfxPrinter = pdfPrinter;

            doc.EndPrint += new PrintEventHandler(this.PrintDocument_EndPrint);

            printPreviewControl1.Document = doc;
            printPreviewControl1.InvalidatePreview();

            printPreviewControl1.Rows = 1;
        }
示例#6
0
        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);
        }
示例#7
0
        /// <summary>
        /// initialise the server for each Web Request
        /// </summary>
        private static bool Init()
        {
            string ConfigFileName = string.Empty;

            // make sure the correct config file is used
            string Instance = HttpContext.Current.Request.Url.ToString().Replace("http://", "").Replace("https://", "");

            Instance = Instance.Substring(0, Instance.IndexOf(".")).Replace("op_", "op").Replace("op", "op_");

            // for demo etc
            if (!Instance.StartsWith("op_"))
            {
                Instance = "op_" + Instance;
            }

            ConfigFileName = "/home/" + Instance + "/etc/PetraServerConsole.config";

            if (File.Exists(ConfigFileName))
            {
                // we are in a multi tenant hosting scenario
            }
            else if (Environment.CommandLine.Contains("/appconfigfile="))
            {
                // this happens when we use fastcgi-mono-server4
                ConfigFileName = Environment.CommandLine.Substring(
                    Environment.CommandLine.IndexOf("/appconfigfile=") + "/appconfigfile=".Length);

                if (ConfigFileName.IndexOf(" ") != -1)
                {
                    ConfigFileName = ConfigFileName.Substring(0, ConfigFileName.IndexOf(" "));
                }
            }
            else
            {
                // this is the normal behaviour when running with local http server
                ConfigFileName = AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + "web.config";
            }

            TTypedDataTable.ResetStaticVariables();
            TPdfPrinter.ResetStaticVariables();
            THTTPUtils.ResetStaticVariables();
            TSharedDataCache.TMPartner.ResetStaticVariables();
            TServerManagerBase.ResetStaticVariables();
            TClientManager.ResetStaticVariables();

            TSession.InitThread("TOpenPetraOrgSessionManager.Init", ConfigFileName);

            if (HttpContext.Current != null)
            {
                HttpContext.Current.Server.ScriptTimeout = Convert.ToInt32(
                    TimeSpan.FromMinutes(TAppSettingsManager.GetInt32("WebRequestTimeOutInMinutes", 15)).
                    TotalSeconds);
            }

            // if the Login Method is called: reset cookie, ignore any old session
            if ((HttpContext.Current != null) && (HttpContext.Current.Request.PathInfo == "/Login"))
            {
                TSession.CloseSession();
                TSession.InitThread("TOpenPetraOrgSessionManager.Init Reset", ConfigFileName);
            }

            Catalog.Init();

            ErrorCodeInventory.Init();
            ErrorCodeInventory.BuildErrorCodeInventory(typeof(Ict.Petra.Shared.PetraErrorCodes));
            ErrorCodeInventory.BuildErrorCodeInventory(typeof(Ict.Common.Verification.TStringChecks));

            TServerManager.TheServerManager = new TServerManager();

            // initialise the cached tables and the delegates
            TSetupDelegates.Init();

            TLogging.LogAtLevel(4, "Server has been initialised");

            return(true);
        }
示例#8
0
        /// 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);
        }