/// <summary>
        /// Инициализировать модуль PDFCreator
        /// </summary>
        private static PDFCreator.clsPDFCreator PdfCreatorInitialize()
        {
            KillAllPreviousProcess();
            var pdfCreator = new PDFCreator.clsPDFCreator();

            return(pdfCreator);
        }
        /// <summary>
        /// Напечатать PDF
        /// </summary>
        private IResultError PrintPdf(PDFCreator.clsPDFCreator pdfCreator, Func <IResultError> printFunction)
        {
            pdfCreator.eReady      += PdfCreatorReady;
            _readyState             = false;
            pdfCreator.cPrinterStop = false;

            var printFunctionResult = printFunction.Invoke();
            int waitingLimit        = 0;

            while (!_readyState && waitingLimit < WAITING_PRINTING_LIMIT_IN_SECONDS && printFunctionResult.OkStatus)
            {
                waitingLimit += 1;
                Thread.Sleep(1000);
            }

            pdfCreator.cPrinterStop = true;
            pdfCreator.cClose();
            KillAllPreviousProcess();

            return((_readyState || printFunctionResult.HasErrors ?
                    new ResultError() :
                    new ErrorCommon(ErrorConvertingType.PdfPrintingError, "Время создания PDF файла истекло").
                    ToResult()).
                   ConcatErrors(printFunctionResult.Errors));
        }
Exemple #3
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            string parameters;

            toolStripStatusLabel1.Text = "Status: Program is started.";

            pErr = new PDFCreator.clsPDFCreatorError();

            _PDFCreator         = new PDFCreator.clsPDFCreator();
            _PDFCreator.eError += new PDFCreator.__clsPDFCreator_eErrorEventHandler(_PDFCreator_eError);
            _PDFCreator.eReady += new PDFCreator.__clsPDFCreator_eReadyEventHandler(_PDFCreator_eReady);

            parameters = "/NoProcessingAtStartup";

            if (!_PDFCreator.cStart(parameters, false))
            {
                toolStripStatusLabel1.Text = "Status: Error[" + pErr.Number + "]: " + pErr.Description;
            }
            else
            {
                button1.Enabled = true;
                button2.Enabled = true;
                button3.Enabled = true;
                button4.Enabled = true;
                button5.Enabled = true;
                button6.Enabled = true;
            }
        }
        /// <summary>
        /// Установить опции печати PDF
        /// </summary>
        private static PDFCreator.clsPDFCreatorOptions GetPdfPrinterOptions(PDFCreator.clsPDFCreator pdfCreator, string filePath)
        {
            var pdfCreatorOptions = pdfCreator.cOptions;

            pdfCreatorOptions.UseAutosave          = 1;
            pdfCreatorOptions.UseAutosaveDirectory = 1;
            pdfCreatorOptions.AutosaveDirectory    = Path.GetDirectoryName(filePath);
            pdfCreatorOptions.AutosaveFilename     = Path.GetFileNameWithoutExtension(filePath);
            pdfCreatorOptions.AutosaveFormat       = 0; // сделать PDF
            return(pdfCreatorOptions);
        }
Exemple #5
0
 private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     _PDFCreator.cClose();
     while (_PDFCreator.cProgramIsRunning)
     {
         Application.DoEvents();
         System.Threading.Thread.Sleep(100);
     }
     pErr        = null;
     _PDFCreator = null;
 }
Exemple #6
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            string parameters;

            AddStatus("Status: Program is started.", true);

            pErr = new PDFCreator.clsPDFCreatorError();

            _PDFCreator         = new PDFCreator.clsPDFCreator();
            _PDFCreator.eError += new PDFCreator.__clsPDFCreator_eErrorEventHandler(_PDFCreator_eError);
            _PDFCreator.eReady += new PDFCreator.__clsPDFCreator_eReadyEventHandler(_PDFCreator_eReady);

            parameters = "/NoProcessingAtStartup";

            if (_PDFCreator.cStart(parameters, false))
            {
                button1.Enabled = true;
                button2.Enabled = true;
                _PDFCreator.cClearCache();
                _PDFCreator.set_cOption("UseAutosave", 0);
                _PDFCreator.cPrinterStop = false;
            }
        }
Exemple #7
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            string parameters;
            AddStatus("Status: Program is started.", true);

            pErr = new PDFCreator.clsPDFCreatorError();

            _PDFCreator = new PDFCreator.clsPDFCreator();
            _PDFCreator.eError  += new PDFCreator.__clsPDFCreator_eErrorEventHandler(_PDFCreator_eError);
            _PDFCreator.eReady  += new PDFCreator.__clsPDFCreator_eReadyEventHandler(_PDFCreator_eReady);

            parameters = "/NoProcessingAtStartup";

            if (_PDFCreator.cStart(parameters, false))
            {
                button1.Enabled = true;
                button2.Enabled = true;
                _PDFCreator.cClearCache();
                _PDFCreator.set_cOption("UseAutosave", 0);
                _PDFCreator.cPrinterStop = false;
            }
        }
Exemple #8
0
 private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     _PDFCreator.cClose();
     while (_PDFCreator.cProgramIsRunning)
     {
         Application.DoEvents();
         System.Threading.Thread.Sleep(100);
     }
     pErr = null;
     _PDFCreator = null;
 }
Exemple #9
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            string parameters;
            toolStripStatusLabel1.Text = "Status: Program is started.";

            pErr = new PDFCreator.clsPDFCreatorError();

            _PDFCreator = new PDFCreator.clsPDFCreator();
            _PDFCreator.eError += new PDFCreator.__clsPDFCreator_eErrorEventHandler(_PDFCreator_eError);
            _PDFCreator.eReady += new PDFCreator.__clsPDFCreator_eReadyEventHandler(_PDFCreator_eReady);

            parameters = "/NoProcessingAtStartup";

            if (!_PDFCreator.cStart(parameters, false))
            {
                toolStripStatusLabel1.Text = "Status: Error[" + pErr.Number + "]: " + pErr.Description;
            }
            else
            {
                button1.Enabled = true;
                button2.Enabled = true;
                button3.Enabled = true;
                button4.Enabled = true;
                button5.Enabled = true;
                button6.Enabled = true;
            }
        }
        public void ConvertToPdf(string filePath, string pdfDestinationPath)
        {
            try
            {
                ReadyState = false;

                string parameters;

                pErr = new PDFCreator.clsPDFCreatorError();

                _PDFCreator = new PDFCreator.clsPDFCreator();
                _PDFCreator.eError += new PDFCreator.__clsPDFCreator_eErrorEventHandler(_PDFCreator_eError);
                _PDFCreator.eReady += new PDFCreator.__clsPDFCreator_eReadyEventHandler(_PDFCreator_eReady);

                //System.Threading.Thread.Sleep(5000);

                parameters = "/NoProcessingAtStartup";

                if (!_PDFCreator.cStart(parameters, false))
                    throw new Exception("Error starting PdfCreator: [" + pErr.Number + "]: " + pErr.Description);

                //System.Threading.Thread.Sleep(5000);

                if (!_PDFCreator.cIsPrintable(filePath))
                    throw new Exception("PdfCreator says that file '" + filePath + "' is not printable!");

                PDFCreator.clsPDFCreatorOptions opt;
                opt = _PDFCreator.cOptions;

                // Store previous option values:
                int useautosave = opt.UseAutosave;
                int useautosaveDir = opt.UseAutosaveDirectory;
                string autosaveDir = opt.AutosaveDirectory;
                int autosaveformat = opt.AutosaveFormat;
                string autosavefilename = opt.AutosaveFilename;

                //System.Threading.Thread.Sleep(5000);

                // Set new options to save to the desired file:
                opt.UseAutosave = 1;
                opt.UseAutosaveDirectory = 1;
                opt.AutosaveDirectory = Path.GetDirectoryName(pdfDestinationPath);
                opt.AutosaveFormat = 0;
                opt.AutosaveFilename = Path.GetFileNameWithoutExtension(pdfDestinationPath);

                // Print:
                _PDFCreator.cOptions = opt;
                _PDFCreator.cClearCache();
                string DefaultPrinter = _PDFCreator.cDefaultPrinter;
                _PDFCreator.cDefaultPrinter = "PDFCreator";
                _PDFCreator.cPrintFile(filePath);
                _PDFCreator.cPrinterStop = false;

                // Wait until print ends
                timer.Interval = maxTime * 1000;
                timer.Enabled = true;
                while (!ReadyState && timer.Enabled)
                {
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(100); // Wait 100 miliseconds.
                }
                timer.Enabled = false;

                // Restore previous options values:
                opt.UseAutosave = useautosave;
                opt.UseAutosaveDirectory = useautosaveDir;
                opt.AutosaveDirectory = autosaveDir;
                opt.AutosaveFormat = autosaveformat;
                opt.AutosaveFilename = autosavefilename;
                _PDFCreator.cOptions = opt;

                if (!ReadyState)
                    throw new Exception("PdfCreator printing timeout");

                _PDFCreator.cPrinterStop = true;
                _PDFCreator.cDefaultPrinter = DefaultPrinter;
            }
            finally
            {
                try
                {
                    // Close the PDF com object:
                    if (_PDFCreator != null)
                    {
                        _PDFCreator.cClose();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(_PDFCreator);
                        //_PDFCreator = null;
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pErr);
                        pErr = null;
                        GC.Collect();
                    }
                }
                catch { }
            }
        }
Exemple #11
0
        public void ConvertToPdf(string filePath, string pdfDestinationPath)
        {
            try
            {
                PrintingFinished = false;

                string parameters;

                pErr = new PDFCreator.clsPDFCreatorError();

                _PDFCreator         = new PDFCreator.clsPDFCreator();
                _PDFCreator.eError += new PDFCreator.__clsPDFCreator_eErrorEventHandler(_PDFCreator_eError);
                _PDFCreator.eReady += new PDFCreator.__clsPDFCreator_eReadyEventHandler(_PDFCreator_eReady);

                parameters = "/NoProcessingAtStartup";

                if (!_PDFCreator.cStart(parameters, false))
                {
                    throw new Exception("Error starting PdfCreator: [" + pErr.Number + "]: " + pErr.Description);
                }

                if (!_PDFCreator.cIsPrintable(filePath))
                {
                    throw new Exception("PdfCreator says that file '" + filePath + "' is not printable!");
                }

                PDFCreator.clsPDFCreatorOptions opt;
                opt = _PDFCreator.cOptions;

                // Store previous option values:
                int    useautosave      = opt.UseAutosave;
                int    useautosaveDir   = opt.UseAutosaveDirectory;
                string autosaveDir      = opt.AutosaveDirectory;
                int    autosaveformat   = opt.AutosaveFormat;
                string autosavefilename = opt.AutosaveFilename;

                // Set new options to save to the desired file:
                opt.UseAutosave          = 1;
                opt.UseAutosaveDirectory = 1;
                opt.AutosaveDirectory    = Path.GetDirectoryName(pdfDestinationPath);
                opt.AutosaveFormat       = 0;
                opt.AutosaveFilename     = Path.GetFileNameWithoutExtension(pdfDestinationPath);

                // Print:
                _PDFCreator.cOptions = opt;
                _PDFCreator.cClearCache();
                string DefaultPrinter = _PDFCreator.cDefaultPrinter;
                _PDFCreator.cDefaultPrinter = "PDFCreator";
                _PDFCreator.cPrintFile(filePath);
                _PDFCreator.cPrinterStop = false;

                // Wait until print ends
                PrintTimeoutTimer.Interval = MAXPRINTTIME * 1000;
                PrintTimeoutTimer.Enabled  = true;
                while (!PrintingFinished && PrintTimeoutTimer.Enabled)
                {
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(100); // Wait 100 miliseconds.
                }
                PrintTimeoutTimer.Enabled = false;

                // Restore previous options values:
                opt.UseAutosave          = useautosave;
                opt.UseAutosaveDirectory = useautosaveDir;
                opt.AutosaveDirectory    = autosaveDir;
                opt.AutosaveFormat       = autosaveformat;
                opt.AutosaveFilename     = autosavefilename;
                _PDFCreator.cOptions     = opt;

                if (!PrintingFinished)
                {
                    throw new Exception("PdfCreator printing timeout");
                }

                _PDFCreator.cPrinterStop    = true;
                _PDFCreator.cDefaultPrinter = DefaultPrinter;
            }
            finally
            {
                try
                {
                    // Close the PDF com object:
                    if (_PDFCreator != null)
                    {
                        _PDFCreator.cClose();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(_PDFCreator);
                        //_PDFCreator = null;
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pErr);
                        pErr = null;
                        GC.Collect();
                    }
                }
                catch { }
            }
        }