Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tools"></param>
        /// <param name="outputFileName"></param>
        /// <param name="flattenForm"></param>
        /// <param name="fieldData"></param>
        /// <returns></returns>
        public static bool StampSimplePDFWithFormFields(
            PdfSharpTools tools,
            string outputFileName, bool flattenForm,
            Dictionary <string, string> fieldData)
        {
            if (tools == null)
            {
                return(false);
            }
            //Prepare the tools for stamping
            tools.PrepForStamping(outputFileName);

            //Ensure that the tools are ready
            if (tools.ReadyForWrite)
            {
                //Loop through the dictionary
                if (!tools.StampPdfOutputFile(fieldData, flattenForm))
                {
                    if (FileLogger.Instance.IsLogError)
                    {
                        FileLogger.Instance.logMessage(LogLevel.ERROR, "PDFITextSharpUtilities", "Error occurred while stamping pdf file {0} from input file {1}", tools.OutputFileName, tools.InputFileName);
                    }
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="tools"></param>
        public static void OpenPDFFile(string fileName, out PdfSharpTools tools)
        {
            //Reset output object
            tools = null;

            //Create tools
            tools = new PdfSharpTools(fileName);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ipAddress"></param>
        /// <param name="ipPort"></param>
        /// <param name="numberCopies"></param>
        /// <param name="tools"></param>
        /// <returns></returns>
        public static bool PrintOutputPDFFile(string ipAddress, string ipPort, int numberCopies, PdfSharpTools tools)
        {
            if (tools == null ||
                string.IsNullOrEmpty(ipAddress) ||
                string.IsNullOrEmpty(ipPort))
            {
                if (FileLogger.Instance.IsLogError)
                {
                    FileLogger.Instance.logMessage(LogLevel.ERROR, "PDFITextSharpUtilities",
                                                   "Cannot print PDF file {0} to {1}:{2}",
                                                   ((tools == null) ? "null" :
                                                    ((string.IsNullOrEmpty(tools.OutputFileName) ? "null" : tools.OutputFileName))),
                                                   (string.IsNullOrEmpty(ipAddress) ? "null" : ipAddress),
                                                   (string.IsNullOrEmpty(ipPort) ? "null" : ipPort));
                }
                return(false);
            }

            //Correct number copies if less than one
            if (numberCopies < 1)
            {
                if (FileLogger.Instance.IsLogWarn)
                {
                    FileLogger.Instance.logMessage(LogLevel.WARN, "PDFITextSharpUtilities",
                                                   "Number of copies specified is invalid. Changed number of copies to 1 instead of {0}",
                                                   numberCopies);
                }
                numberCopies = 1;
            }

            //Validate port number
            int ipPortNum = Utilities.GetIntegerValue(ipPort);

            if (ipPortNum < 0 || ipPortNum > 65535)
            {
                if (FileLogger.Instance.IsLogError)
                {
                    FileLogger.Instance.logMessage(LogLevel.ERROR, "PDFITextSharpUtilities",
                                                   "IP Port Invalid(Must be a number between 0 and 65535.  Cannot print {0} to {1}:{2}",
                                                   tools.OutputFileName, ipAddress, ipPort);
                }
                return(false);
            }
            try
            {
                //Open printer socket
                var           tcpClient     = new TcpClient(ipAddress, ipPortNum);
                NetworkStream networkStream = tcpClient.GetStream();
                var           binaryWriter  = new BinaryWriter(networkStream);

                //Read entire data file into the byte buffer
                FileStream inStream     = File.OpenRead(tools.OutputFileName);
                var        binaryReader = new BinaryReader(inStream);
                var        inLength     = (int)binaryReader.BaseStream.Length;
                byte[]     buffer       = binaryReader.ReadBytes(inLength);

                //Repeat the binary write operation for as many copies as requested
                for (int i = 1; i <= numberCopies; ++i)
                {
                    binaryWriter.Write(buffer);
                    binaryWriter.Flush();
                }

                //Close binary streams
                binaryWriter.Close();
                binaryReader.Close();
            }
            catch (System.Exception eX)
            {
                if (FileLogger.Instance.IsLogError)
                {
                    FileLogger.Instance.logMessage(LogLevel.ERROR, "PDFITextSharpUtilities",
                                                   "Exception thrown while printing {0} to {1}:{2} :: {3}",
                                                   tools.OutputFileName,
                                                   ipAddress, ipPort,
                                                   eX);
                }
                return(false);
            }

            return(true);
        }