예제 #1
0
        public static string getMergePdfwithSig(string pathPdf)
        {
            string StartupPath = Path.GetDirectoryName(pathPdf);
            string FileName    = Path.GetFileNameWithoutExtension(pathPdf);
            string FileExt     = Path.GetExtension(pathPdf);

            //			string pathPdf = StartupPath + @"\dogovor_magomed.pdf";
            string filePdfNew = "";

            try
            {
                string fileName = StartupPath + @"\" + FileName + "_withSign" + FileExt;
                using (var fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.None))
                {
                    filePdfNew = StartupPath + @"\" + FileName + "_withSign" + FileExt;
                }
            }
            catch (IOException ioex)
            {
                filePdfNew = StartupPath + @"\" + FileName + "_withSign" + DateTime.Now.Millisecond + FileExt;
            }



            string tmpPdfSig = StartupPath + @"\sigToPdf.pdf";

            clSignature sig     = new clSignature();
            string      htmlSig = sig.getHtmlSig(pathPdf);


            //			using (FileStream htmlSource = File.Open(StartupPath + @"\USTUPKA.html", FileMode.Open))
            using (FileStream htmlSource = File.Open(htmlSig, FileMode.Open))
                using (FileStream pdfDest = File.Open(tmpPdfSig, FileMode.OpenOrCreate))
                {
                    ConverterProperties converterProperties = new ConverterProperties();
                    converterProperties.SetCharset("windows-1251");
                    HtmlConverter.ConvertToPdf(htmlSource, pdfDest, converterProperties);
                }

            PdfDocument pdfDocument  = new PdfDocument(new PdfReader(pathPdf), new PdfWriter(filePdfNew));
            PdfDocument pdfDocument2 = new PdfDocument(new PdfReader(tmpPdfSig));

            PdfMerger merger = new PdfMerger(pdfDocument);

            merger.Merge(pdfDocument2, 1, pdfDocument2.GetNumberOfPages());

            pdfDocument2.Close();
            pdfDocument.Close();


            return(filePdfNew);
        }