Inheritance: PdfTemplate
Example #1
0
        /**
         * Add an imported page to our output
         * @param iPage an imported page
         * @throws IOException, BadPdfFormatException
         */
        public void AddPage(PdfImportedPage iPage)
        {
            int pageNum = SetFromIPage(iPage);

            PdfDictionary       thePage = reader.GetPageN(pageNum);
            PRIndirectReference origRef = reader.GetPageOrigRef(pageNum);

            reader.ReleasePage(pageNum);
            RefKey key = new RefKey(origRef);
            PdfIndirectReference pageRef;
            IndirectReferences   iRef;

            indirects.TryGetValue(key, out iRef);
            if (iRef != null && !iRef.Copied)
            {
                pageReferences.Add(iRef.Ref);
                iRef.SetCopied();
            }
            pageRef = CurrentPage;
            if (iRef == null)
            {
                iRef           = new IndirectReferences(pageRef);
                indirects[key] = iRef;
            }
            iRef.SetCopied();
            PdfDictionary newPage = CopyDictionary(thePage);

            root.AddPage(newPage);
            ++currentPageNumber;
        }
Example #2
0
        /**
         * Add an imported page to our output
         * @param iPage an imported page
         * @throws IOException, BadPdfFormatException
         */
        public void AddPage(PdfImportedPage iPage)
        {
            int pageNum = SetFromIPage(iPage);

            PdfDictionary       thePage = reader.GetPageN(pageNum);
            PRIndirectReference origRef = reader.GetPageOrigRef(pageNum);

            reader.ReleasePage(pageNum);
            RefKey key = new RefKey(origRef);
            PdfIndirectReference pageRef;
            IndirectReferences   iRef = (IndirectReferences)indirects[key];

            // if we already have an iref for the page (we got here by another link)
            if (iRef != null)
            {
                pageRef = iRef.Ref;
            }
            else
            {
                pageRef        = body.PdfIndirectReference;
                iRef           = new IndirectReferences(pageRef);
                indirects[key] = iRef;
            }
            pageReferences.Add(pageRef);
            ++currentPageNumber;
            if (!iRef.Copied)
            {
                iRef.SetCopied();
                PdfDictionary newPage = CopyDictionary(thePage);
                newPage.Put(PdfName.PARENT, topPageParent);
                AddToBody(newPage, pageRef);
            }
            root.AddPage(pageRef);
            pageNumbersToRefs.Add(pageRef);
        }
Example #3
0
        public void ConvertToImage(string _rutaPDF, int width, int height)
        {
            iTextSharp.text.pdf.PdfReader reader = null;
            int currentPage = 1;
            int pageCount   = 0;

            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            reader = new iTextSharp.text.pdf.PdfReader(_rutaPDF);
            reader.RemoveUnusedObjects();
            pageCount = reader.NumberOfPages;
            string ext = System.IO.Path.GetExtension(_rutaPDF);

            for (int i = 1; i <= 1; i++)
            {
                iTextSharp.text.pdf.PdfReader reader1 = new iTextSharp.text.pdf.PdfReader(_rutaPDF);
                string outfile = _rutaPDF.Replace((System.IO.Path.GetFileName(_rutaPDF)), (System.IO.Path.GetFileName(_rutaPDF).Replace(".pdf", "") + "_" + i.ToString()) + ext);
                reader1.RemoveUnusedObjects();
                iTextSharp.text.Document    doc    = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(currentPage));
                iTextSharp.text.pdf.PdfCopy pdfCpy = new iTextSharp.text.pdf.PdfCopy(doc, new System.IO.FileStream(outfile, System.IO.FileMode.Create));
                doc.Open();
                for (int j = 1; j <= 1; j++)
                {
                    iTextSharp.text.pdf.PdfImportedPage page = pdfCpy.GetImportedPage(reader1, currentPage);
                    pdfCpy.SetFullCompression();
                    pdfCpy.AddPage(page);
                    currentPage += 1;
                }
                doc.Close();
                pdfCpy.Close();
                reader1.Close();
                reader.Close();
            }
        }
        public void AddPdf(string sInFilePath, ref iTextSharp.text.Document oPdfDoc, ref PdfWriter oPdfWriter)
        {
            iTextSharp.text.pdf.PdfContentByte oDirectContent = oPdfWriter.DirectContent;
            iTextSharp.text.pdf.PdfReader      oPdfReader     = new iTextSharp.text.pdf.PdfReader(sInFilePath);
            int iNumberOfPages = oPdfReader.NumberOfPages;
            int iPage          = 0;

            while ((iPage < iNumberOfPages))
            {
                iPage += 1;

                int iRotation = oPdfReader.GetPageRotation(iPage);
                iTextSharp.text.pdf.PdfImportedPage oPdfImportedPage = oPdfWriter.GetImportedPage(oPdfReader, iPage);
                oPdfDoc.SetPageSize(oPdfReader.GetPageSizeWithRotation(iPage));
                oPdfDoc.NewPage();

                if ((iRotation == 90) | (iRotation == 270))
                {
                    oDirectContent.AddTemplate(oPdfImportedPage, 0, -1f, 1f, 0, 0, oPdfReader.GetPageSizeWithRotation(iPage).Height);
                }
                else
                {
                    oDirectContent.AddTemplate(oPdfImportedPage, 1f, 0, 0, 1f, 0, 0);
                }
            }
        }
Example #5
0
 public override void AddPage(PdfImportedPage iPage)
 {
     if (currentPdfReaderInstance.Reader != reader)
     {
         serialized.Clear();
     }
     base.AddPage(iPage);
 }
        /// <summary>
        /// Create a page stamp. New content and annotations, including new fields, are allowed.
        /// The fields added cannot have parents in another pages. This method modifies the PdfReader instance.
        /// The general usage to stamp something in a page is:
        ///
        ///
        /// PdfImportedPage page = copy.getImportedPage(reader, 1);
        /// PdfCopy.PageStamp ps = copy.createPageStamp(page);
        /// ps.addAnnotation(PdfAnnotation.createText(copy, new Rectangle(50, 180, 70, 200), "Hello", "No Thanks", true, "Comment"));
        /// PdfContentByte under = ps.getUnderContent();
        /// under.addImage(img);
        /// PdfContentByte over = ps.getOverContent();
        /// over.beginText();
        /// over.setFontAndSize(bf, 18);
        /// over.setTextMatrix(30, 30);
        /// over.showText("total page " + totalPage);
        /// over.endText();
        /// ps.alterContents();
        /// copy.addPage(page);
        ///
        /// </summary>
        /// <param name="iPage">an imported page</param>
        /// <returns>the  PageStamp </returns>
        public PageStamp CreatePageStamp(PdfImportedPage iPage)
        {
            var pageNum = iPage.PageNumber;
            var reader  = iPage.PdfReaderInstance.Reader;
            var pageN   = reader.GetPageN(pageNum);

            return(new PageStamp(reader, pageN, this));
        }
Example #7
0
        /**
         * convenience method. Given an importedpage, set our "globals"
         */
        protected int SetFromIPage(PdfImportedPage iPage)
        {
            int pageNum            = iPage.PageNumber;
            PdfReaderInstance inst = currentPdfReaderInstance = iPage.PdfReaderInstance;

            reader = inst.Reader;
            SetFromReader(reader);
            return(pageNum);
        }
        /// <summary>
        /// convenience method. Given an importedpage, set our "globals"
        /// </summary>
        protected int SetFromIPage(PdfImportedPage iPage)
        {
            var pageNum = iPage.PageNumber;
            var inst    = CurrentPdfReaderInstance = iPage.PdfReaderInstance;

            Reader = inst.Reader;
            SetFromReader(Reader);
            return(pageNum);
        }
        /// <summary>
        /// Gets the content stream of a page as a PdfStream object.
        /// @since   2.1.3 (the method already existed without param compressionLevel)
        /// </summary>
        /// <param name="pageNumber">the page of which you want the stream</param>
        /// <param name="compressionLevel">the compression level you want to apply to the stream</param>
        /// <returns>a PdfStream object</returns>
        internal PdfStream GetFormXObject(int pageNumber, int compressionLevel)
        {
            PdfDictionary page     = reader.GetPageNRelease(pageNumber);
            PdfObject     contents = PdfReader.GetPdfObjectRelease(page.Get(PdfName.Contents));
            PdfDictionary dic      = new PdfDictionary();

            byte[] bout = null;
            if (contents != null)
            {
                if (contents.IsStream())
                {
                    dic.Merge((PrStream)contents);
                }
                else
                {
                    bout = reader.GetPageContent(pageNumber, File);
                }
            }
            else
            {
                bout = new byte[0];
            }
            dic.Put(PdfName.Resources, PdfReader.GetPdfObjectRelease(page.Get(PdfName.Resources)));
            dic.Put(PdfName.TYPE, PdfName.Xobject);
            dic.Put(PdfName.Subtype, PdfName.Form);
            PdfImportedPage impPage = (PdfImportedPage)ImportedPages[pageNumber];

            dic.Put(PdfName.Bbox, new PdfRectangle(impPage.BoundingBox));
            PdfArray matrix = impPage.Matrix;

            if (matrix == null)
            {
                dic.Put(PdfName.Matrix, Identitymatrix);
            }
            else
            {
                dic.Put(PdfName.Matrix, matrix);
            }
            dic.Put(PdfName.Formtype, One);
            PrStream stream;

            if (bout == null)
            {
                stream = new PrStream((PrStream)contents, dic);
            }
            else
            {
                stream = new PrStream(reader, bout);
                stream.Merge(dic);
            }
            return(stream);
        }
        /**
         * Gets the content stream of a page as a PdfStream object.
         * @param   pageNumber          the page of which you want the stream
         * @param   compressionLevel    the compression level you want to apply to the stream
         * @return  a PdfStream object
         * @since   2.1.3 (the method already existed without param compressionLevel)
         */
        internal PdfStream GetFormXObject(int pageNumber, int compressionLevel)
        {
            PdfDictionary page     = reader.GetPageNRelease(pageNumber);
            PdfObject     contents = PdfReader.GetPdfObjectRelease(page.Get(PdfName.CONTENTS));
            PdfDictionary dic      = new PdfDictionary();

            byte[] bout = null;
            if (contents != null)
            {
                if (contents.IsStream())
                {
                    dic.Merge((PRStream)contents);
                }
                else
                {
                    bout = reader.GetPageContent(pageNumber, file);
                }
            }
            else
            {
                bout = new byte[0];
            }
            dic.Put(PdfName.RESOURCES, PdfReader.GetPdfObjectRelease(page.Get(PdfName.RESOURCES)));
            dic.Put(PdfName.TYPE, PdfName.XOBJECT);
            dic.Put(PdfName.SUBTYPE, PdfName.FORM);
            PdfImportedPage impPage = importedPages[pageNumber];

            dic.Put(PdfName.BBOX, new PdfRectangle(impPage.BoundingBox));
            PdfArray matrix = impPage.Matrix;

            if (matrix == null)
            {
                dic.Put(PdfName.MATRIX, IDENTITYMATRIX);
            }
            else
            {
                dic.Put(PdfName.MATRIX, matrix);
            }
            dic.Put(PdfName.FORMTYPE, ONE);
            PRStream stream;

            if (bout == null)
            {
                stream = new PRStream((PRStream)contents, dic);
            }
            else
            {
                stream = new PRStream(reader, bout);
                stream.Merge(dic);
            }
            return(stream);
        }
        public void OnOpenDocument(PdfWriter writer, Document document)
        {
            _baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
            _frontPageFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED);
            _content = writer.DirectContent;

            if (!string.IsNullOrEmpty(_settings.PageTemplate))
            {
                var reader = new PdfReader(_settings.PageTemplate);
                _template = writer.GetImportedPage(reader, 1);
            }

            WriteFrontPage(writer, document);
        }
Example #12
0
        private void StartThread()
        {
            List <String> filePaths = new List <string>();

            // create one-page pdfs first
            iTextSharp.text.pdf.PdfReader reader = null;
            int    currentPage = 1;
            int    pageCount   = 0;
            String filepath    = textBox_file.Text;

            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            reader = new iTextSharp.text.pdf.PdfReader(filepath);
            reader.RemoveUnusedObjects();
            pageCount = reader.NumberOfPages;
            string ext = System.IO.Path.GetExtension(filepath);

            for (int i = 1; i <= pageCount; i++)
            {
                iTextSharp.text.pdf.PdfReader reader1 = new iTextSharp.text.pdf.PdfReader(filepath);
                string outfile = filepath.Replace((System.IO.Path.GetFileName(filepath)), (System.IO.Path.GetFileName(filepath).Replace(".pdf", "") + "_" + i.ToString()) + ext);
                reader1.RemoveUnusedObjects();
                iTextSharp.text.Document    doc    = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(currentPage));
                iTextSharp.text.pdf.PdfCopy pdfCpy = new iTextSharp.text.pdf.PdfCopy(doc, new System.IO.FileStream(outfile, System.IO.FileMode.Create));
                doc.Open();
                for (int j = 1; j <= 1; j++)
                {
                    iTextSharp.text.pdf.PdfImportedPage page = pdfCpy.GetImportedPage(reader1, currentPage);
                    pdfCpy.AddPage(page);
                    currentPage += 1;
                }
                doc.Close();
                pdfCpy.Close();
                reader1.Close();
                reader.Close();

                filePaths.Add(outfile);
            }

            DecomposeData decompose = new DecomposeData
            {
                filePathsPdf = filePaths,
                folder       = textBox_destFolder.Text
            };

            backgroundWorker1.RunWorkerAsync(decompose);

            label_status.Text      = localization.GetValueForItem(LocalizedItem.TextSearchStarted).Replace("%i", filePaths.Count.ToString());
            label_status.ForeColor = Color.Blue;
        }
Example #13
0
        internal PdfImportedPage GetImportedPage(int pageNumber)
        {
            if (pageNumber < 1 || pageNumber > reader.NumberOfPages)
            {
                throw new ArgumentException("Invalid page number");
            }
            PdfImportedPage pageT = (PdfImportedPage)importedPages[pageNumber];

            if (pageT == null)
            {
                pageT = new PdfImportedPage(this, writer, pageNumber);
                importedPages[pageNumber] = pageT;
            }
            return(pageT);
        }
Example #14
0
        private void AddTextForPage(PdfCopy pdfCopyProvider, PdfImportedPage importedPage, TextForPage textForPage)
        {
            PdfCopy.PageStamp stamper = pdfCopyProvider.CreatePageStamp(importedPage);

            ColumnText.ShowTextAligned(stamper.GetOverContent(), Element.ALIGN_CENTER, new Phrase(textForPage.PageNubmer,
                new Font()), 820f, 15, 0);
            stamper.AlterContents();

            AddParagraph(stamper, textForPage.Header, importedPage.Width / 2,
                importedPage.Height - 30, Element.ALIGN_CENTER, 1);

            AddParagraph(stamper, textForPage.Footer, importedPage.Width / 2,
                30, Element.ALIGN_CENTER, 1);

            stamper.AlterContents();
        }
        internal PdfImportedPage getImportedPage(int pageNumber)
        {
            if (pageNumber < 1 || pageNumber > pages.Length)
            {
                throw new IllegalArgumentException("Invalid page number");
            }
            int             i     = pageNumber;
            PdfImportedPage pageT = (PdfImportedPage)importedPages[i];

            if (pageT == null)
            {
                pageT = new PdfImportedPage(this, writer, pageNumber);
                importedPages.Add(i, pageT);
            }
            return(pageT);
        }
Example #16
0
        /// <summary>
        /// Splits the PDF file
        /// </summary>
        /// <param name="filepath">The file to split</param>
        private void Split(string filepath)
        {
            this.statut.Text = "Début de la division";
            this.statut.Refresh();
            this.document.Text = Path.GetFileName(filepath);
            this.document.Refresh();
            PdfReader reader      = null;
            int       currentPage = 1;
            int       pageCount   = 0;
            string    dirPath     = Path.GetDirectoryName(filepath);

            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            reader = new iTextSharp.text.pdf.PdfReader(filepath);
            reader.RemoveUnusedObjects();
            pageCount = reader.NumberOfPages;
            string ext = System.IO.Path.GetExtension(filepath);

            for (int i = 1; i <= pageCount; i++)
            {
                this.statut.Text = "En cours de division " + i + " / " + pageCount;
                this.statut.Refresh();
                iTextSharp.text.pdf.PdfReader reader1 = new iTextSharp.text.pdf.PdfReader(filepath);
                string outfile = filepath.Replace(System.IO.Path.GetFileName(filepath), (System.IO.Path.GetFileName(filepath).Replace(FileExtension.PDF, string.Empty) + "_" + i.ToString()) + ext);
                outfile = outfile.Substring(0, dirPath.Length).Insert(dirPath.Length, string.Empty) + "\\" + Path.GetFileName(filepath).Replace(FileExtension.PDF, string.Empty) + "_" + i.ToString() + ext;
                reader1.RemoveUnusedObjects();
                iTextSharp.text.Document    doc    = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(currentPage));
                iTextSharp.text.pdf.PdfCopy pdfCpy = new iTextSharp.text.pdf.PdfCopy(doc, new System.IO.FileStream(outfile, System.IO.FileMode.OpenOrCreate));
                doc.Open();
                for (int j = 1; j <= 1; j++)
                {
                    iTextSharp.text.pdf.PdfImportedPage page = pdfCpy.GetImportedPage(reader1, currentPage);
                    pdfCpy.AddPage(page);
                    currentPage += 1;
                }

                this.progressBar1.PerformStep();
                this.progressPages = this.progressPages + 1;
                this.label1.Text   = this.progressPages + " / " + this.nbpages;
                this.label1.Refresh();
                this.statut.Text = "Fin de la division " + i + " / " + pageCount;
                this.statut.Refresh();
                doc.Close();
                pdfCpy.Close();
                reader1.Close();
                reader.Close();
            }
        }
Example #17
0
        private bool EncryptPDF(String strPath, String StrDesPath, String strOpenPassWord, String strOwnerPassWord)
        {
            try
            {
                PdfReader itextPdfReader          = new PdfReader(strPath);
                iTextSharp.text.Document document = new iTextSharp.text.Document();
                FileStream fileStream             = new FileStream(StrDesPath, FileMode.Create);
                PdfWriter  pdfWriter = PdfWriter.GetInstance(document, fileStream);
                String     strOpenPas, strOwnerPas;
                strOpenPas  = this.OpenFilPassWText.Text;
                strOwnerPas = this.PerrmisionPassText.Text;
                pdfWriter.SetEncryption(PdfWriter.STRENGTH40BITS, strOpenPas, strOwnerPas, PdfWriter.AllowCopy);
                document.Open();

                //Setting PDF file enctyption page count
                document.SetPageSize(iTextSharp.text.PageSize.LEDGER.Rotate());
                iTextSharp.text.pdf.PdfContentByte oDirectContent = pdfWriter.DirectContent;
                int iNUmberOfPages = itextPdfReader.NumberOfPages;
                int iPage          = 0;

                while (iPage < iNUmberOfPages)
                {
                    iPage += 1;
                    document.SetPageSize(itextPdfReader.GetPageSizeWithRotation(iPage));
                    document.NewPage();
                    iTextSharp.text.pdf.PdfImportedPage oPdfImportedPage = pdfWriter.GetImportedPage(itextPdfReader, iPage);
                    int iRotation = itextPdfReader.GetPageRotation(iPage);
                    if (iRotation == 90 || iRotation == 270)
                    {
                        oDirectContent.AddTemplate(oPdfImportedPage, 0, -1.0F, 1.0F, 0, 0, itextPdfReader.GetPageSizeWithRotation(iPage).Height);
                    }
                    else
                    {
                        oDirectContent.AddTemplate(oPdfImportedPage, 1.0F, 0, 0, 1.0F, 0, 0);
                    }
                }
                document.Close();
                return(true);
            }catch (Exception e)
            {
                //e.ToString();

                return(false);
            }
        }
        internal PdfImportedPage GetImportedPage(int pageNumber)
        {
            if (!reader.IsOpenedWithFullPermissions)
            {
                throw new ArgumentException(MessageLocalization.GetComposedMessage("pdfreader.not.opened.with.owner.password"));
            }
            if (pageNumber < 1 || pageNumber > reader.NumberOfPages)
            {
                throw new ArgumentException(MessageLocalization.GetComposedMessage("invalid.page.number.1", pageNumber));
            }
            PdfImportedPage pageT;

            if (!importedPages.TryGetValue(pageNumber, out pageT))
            {
                pageT = new PdfImportedPage(this, writer, pageNumber);
                importedPages[pageNumber] = pageT;
            }
            return(pageT);
        }
Example #19
0
        internal PdfImportedPage GetImportedPage(int pageNumber)
        {
            if (!reader.IsOpenedWithFullPermissions)
            {
                throw new ArgumentException("PdfReader not opened with owner password");
            }
            if (pageNumber < 1 || pageNumber > reader.NumberOfPages)
            {
                throw new ArgumentException("Invalid page number: " + pageNumber);
            }
            PdfImportedPage pageT = (PdfImportedPage)importedPages[pageNumber];

            if (pageT == null)
            {
                pageT = new PdfImportedPage(this, writer, pageNumber);
                importedPages[pageNumber] = pageT;
            }
            return(pageT);
        }
        /// <summary> iTextSharp_PNG 无法正常进行展出操作
        ///
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="outputPath"></param>
        /// <returns></returns>
        List <PPTPage> SplitePDF(string filepath, string outputPath)
        {
            List <PPTPage> pages = new List <PPTPage>();

            iTextSharp.text.pdf.PdfReader reader = null;
            int currentPage = 1;
            int pageCount   = 0;

            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            reader = new iTextSharp.text.pdf.PdfReader(filepath);
            reader.RemoveUnusedObjects();
            pageCount = reader.NumberOfPages;

            for (int i = 1; i <= pageCount;)
            {
                string outfile = System.IO.Path.Combine(outputPath, i + ".png");
                iTextSharp.text.Document    doc    = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(currentPage));
                iTextSharp.text.pdf.PdfCopy pdfCpy = new iTextSharp.text.pdf.PdfCopy(doc, new System.IO.FileStream(outfile, System.IO.FileMode.Create));
                doc.Open();
                for (int j = 1; j <= 1; j++)
                {
                    iTextSharp.text.pdf.PdfImportedPage page = pdfCpy.GetImportedPage(reader, currentPage);
                    pdfCpy.SetFullCompression();
                    pdfCpy.AddPage(page);
                    currentPage += 1;
                }

                Console.WriteLine("PDF TO IMAGES - {0}/{1}", ++i, pageCount);
                pages.Add(new PPTPage()
                {
                    Cover = outfile
                });

                pdfCpy.Flush();
                doc.Close();
                pdfCpy.Close();
                reader.Close();
            }

            return(pages);
        }
Example #21
0
        public static void SplitePDF(string filepath)
        {
            iTextSharp.text.pdf.PdfReader reader = null;
            int currentPage = 1;
            int pageCount   = 0;

            //string filepath_New = filepath + "\\PDFDestination\\";

            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            //byte[] arrayofPassword = encoding.GetBytes(ExistingFilePassword);
            reader = new iTextSharp.text.pdf.PdfReader(filepath);
            reader.RemoveUnusedObjects();
            pageCount = reader.NumberOfPages;
            string ext = System.IO.Path.GetExtension(filepath);

            for (int i = 1; i <= pageCount; i++)
            {
                iTextSharp.text.pdf.PdfReader reader1 = new iTextSharp.text.pdf.PdfReader(filepath);
                string outfile = filepath.Replace((System.IO.Path.GetFileName(filepath)), (System.IO.Path.GetFileName(filepath).Replace(".pdf", "") + "_" + i.ToString()) + ext);
                reader1.RemoveUnusedObjects();
                iTextSharp.text.Document    doc    = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(currentPage));
                iTextSharp.text.pdf.PdfCopy pdfCpy = new iTextSharp.text.pdf.PdfCopy(doc, new System.IO.FileStream(outfile, System.IO.FileMode.Create));
                pdfCpy.SetFullCompression();
                doc.Open();
                for (int j = 1; j <= 1; j++)
                {
                    iTextSharp.text.pdf.PdfImportedPage page = pdfCpy.GetImportedPage(reader1, currentPage);
                    pdfCpy.AddPage(page);
                    currentPage += 1;
                }
                doc.Close();
                pdfCpy.Close();
                reader1.Close();
                reader.Close();
            }
        }
Example #22
0
 public override PageStamp CreatePageStamp(PdfImportedPage iPage) {
     CheckPdfAInfo(iPage.readerInstance.Reader);
     return base.CreatePageStamp(iPage);
 }
Example #23
0
        static void Main(string[] args)
        {
            // Changes \ to / in the path string
            string oldstr            = @"\";
            string newstr            = @"/";
            string pdf_path_original = string.Empty;

            // Tells the file path
            Console.WriteLine("FILE PATH: ");
            Console.OutputEncoding = Encoding.GetEncoding(932);
            Console.WriteLine("ファイル パス: ");
            pdf_path_original = Console.ReadLine();
            string pdf_path = pdf_path_original.Replace(oldstr, newstr);

            // Tells the file name
            Console.WriteLine(".pdf`s Name: ");
            Console.OutputEncoding = Encoding.GetEncoding(932);
            Console.WriteLine("ファイルの名前は: ");
            string pdf_file_name = Console.ReadLine();
            string path_n_name   = pdf_path + "/" + pdf_file_name + ".pdf";

            // Tells the file alignment
            Console.WriteLine("Text alignment: ");
            Console.OutputEncoding = Encoding.GetEncoding(932);
            Console.WriteLine("テキスト配置: ");
            Console.WriteLine("1: Left (左), and Right (右), or 2: Middle (真ん中)");
            string caseSwitch = Console.ReadLine();

            Console.WriteLine();


            // Tells the file start page and end page
            Console.WriteLine(".pdf`s Initial Page ");
            Console.OutputEncoding = Encoding.GetEncoding(932);
            Console.WriteLine("最初のページは: ");
            string startpage_string = Console.ReadLine();
            int    startpage        = Int32.Parse(startpage_string);

            Console.WriteLine(".pdf`s Last Page ");
            Console.OutputEncoding = Encoding.GetEncoding(932);
            Console.WriteLine("最後のページは: ");
            string endpage_string = Console.ReadLine();
            int    endpage        = Int32.Parse(endpage_string);

            // Creates blank pdf files
            for (int i = startpage; i <= endpage; i++)
            {
                string convi = i.ToString();
                // Creates a temp folder for the pdf files
                System.IO.Directory.CreateDirectory(pdf_path + "/" + "temp");
                System.IO.FileStream pdf_creator = new System.IO.FileStream(pdf_path + "/" + "temp" + "/" + convi + ".pdf", System.IO.FileMode.Create);
                pdf_creator.Close();
            }


            // Tells the attributes from the new pdf files, and the original pdf source
            iTextSharp.text.pdf.PdfReader       reader          = null;
            iTextSharp.text.Document            sourceDocument  = null;
            iTextSharp.text.pdf.PdfCopy         pdfCopyProvider = null;
            iTextSharp.text.pdf.PdfImportedPage importedPage    = null;

            reader         = new iTextSharp.text.pdf.PdfReader(path_n_name);
            sourceDocument = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(startpage));
            sourceDocument.Open();

            // Creates a .docx to receive the pdf's text
            Spire.Doc.Document word_doc = new Spire.Doc.Document();

            // Word doc formatting
            Spire.Doc.Section             word_doc_section        = word_doc.AddSection();
            Spire.Doc.Documents.Paragraph word_doc_paragraph      = word_doc_section.AddParagraph();
            Spire.Doc.Documents.Paragraph word_doc_paragraph_page = word_doc_section.AddParagraph();


            // Update those blank pdf files, inserting the copied pages into it
            try
            {
                for (int i = startpage; i <= endpage; i++)
                {
                    string convi = i.ToString();
                    pdfCopyProvider = new PdfCopy(sourceDocument, new System.IO.FileStream(pdf_path + "/" + "temp" + "/" + convi + ".pdf", System.IO.FileMode.Append));
                    sourceDocument.Open();
                    importedPage = pdfCopyProvider.GetImportedPage(reader, i);
                    pdfCopyProvider.AddPage(importedPage);
                }


                sourceDocument.Close();
                reader.Close();
            }


            // ERROR
            catch (Exception ex)
            {
                Console.WriteLine("Error! ");
                Console.OutputEncoding = Encoding.GetEncoding(932);
                Console.WriteLine("エラー ! ");
                throw ex;
            }


            // Collects the text without furigana from the listed pdf files
            switch (caseSwitch)
            {
            // case 1 reffers to the left and right alignments of the pdf text
            case "1":
                Console.WriteLine();
                for (int i = startpage; i <= endpage; i++)
                {
                    // the following refers to the int counter of pages being converted into string
                    string convi = i.ToString();
                    Console.OutputEncoding = Encoding.GetEncoding(932);
                    Console.WriteLine("今のページ: " + convi);
                    Console.WriteLine("Current Page: " + convi);

                    // the following refers to the bitmiracle api pdf to get the texts
                    using (BitMiracle.Docotic.Pdf.PdfDocument pdf_1 = new BitMiracle.Docotic.Pdf.PdfDocument(pdf_path + "/" + "temp" + "/" + convi + ".pdf"))
                    {
                        BitMiracle.Docotic.Pdf.PdfPage page = pdf_1.Pages[0];
                        foreach (PdfTextData data in page.GetWords())
                        {
                            if (data.FontSize > 6 && data.Position.X < 600)
                            {
                                string text = data.Text;
                                text.TrimEnd();
                                Console.OutputEncoding = Encoding.GetEncoding(932);
                                Console.WriteLine(text);
                                //word_builder.Writeln(text);
                                word_doc_paragraph.AppendText(text);
                            }
                        }
                        foreach (PdfTextData data in page.GetWords())
                        {
                            if (data.FontSize > 6 && data.Position.X > 600)
                            {
                                string text = data.Text;
                                text.TrimEnd();
                                Console.OutputEncoding = Encoding.GetEncoding(932);
                                Console.WriteLine(text);
                                word_doc_paragraph.AppendText(text);
                            }
                        }
                    }
                    // the following lines reffers to the space between pages of the pdf text
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine();
                    // the followin reffers to the extra lines on word text


                    word_doc_paragraph.AppendText("                                        ");
                    word_doc_paragraph.AppendText("CURRENT PAGE: " + convi);
                    word_doc_paragraph = word_doc_section.AddParagraph();
                    word_doc.Sections[0].Paragraphs[i].AppendBreak(BreakType.PageBreak);
                }

                break;


            // case 2 reffers to the alignment of the pdf text that is centralized
            case "2":
                Console.WriteLine();
                for (int i = startpage; i <= endpage; i++)
                {
                    // the following refers to the int counter of pages being converted into string
                    string convi = i.ToString();
                    Console.OutputEncoding = Encoding.GetEncoding(932);
                    Console.WriteLine("今のページ: " + convi);
                    Console.WriteLine("Current Page: " + convi);

                    // the following refers to the bitmiracle api pdf to get the texts
                    using (BitMiracle.Docotic.Pdf.PdfDocument pdf_1 = new BitMiracle.Docotic.Pdf.PdfDocument(pdf_path + "/" + "temp" + "/" + convi + ".pdf"))
                    {
                        BitMiracle.Docotic.Pdf.PdfPage page = pdf_1.Pages[0];
                        foreach (PdfTextData data in page.GetWords())
                        {
                            if (data.FontSize > 6)
                            {
                                string text = data.Text;
                                text.TrimEnd();
                                Console.OutputEncoding = Encoding.GetEncoding(932);
                                Console.WriteLine(text);
                                word_doc_paragraph.AppendText(text);
                            }
                        }
                    }
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine();

                    word_doc_paragraph.AppendText("                                        ");
                    word_doc_paragraph.AppendText("CURRENT PAGE: " + convi);
                    word_doc_paragraph = word_doc_section.AddParagraph();
                    word_doc.Sections[0].Paragraphs[i].AppendBreak(BreakType.PageBreak);
                }
                break;

            default:
                Console.OutputEncoding = Encoding.GetEncoding(932);
                Console.WriteLine("error! (エラー)");
                Console.ReadKey();
                break;
            }

            // The following refers to creating a .docx file, opening up the file and deleting the temp folder
            word_doc.SaveToFile(pdf_path + "/" + pdf_file_name + ".docx", FileFormat.Docx);
            System.IO.Directory.Delete(pdf_path + "/" + "temp", true);
            try
            {
                System.Diagnostics.Process.Start(pdf_path + "/" + pdf_file_name + ".docx");
            }
            catch
            {
                Console.WriteLine("Error! ");
                Console.OutputEncoding = Encoding.GetEncoding(932);
                Console.WriteLine("エラー ! ");
            }
        }
Example #24
0
 /**
 * Add an imported page to our output
 * @param iPage an imported page
 * @throws IOException, BadPdfFormatException
 */
 public void AddPage(PdfImportedPage iPage) {
     int pageNum = SetFromIPage(iPage);
     
     PdfDictionary thePage = reader.GetPageN(pageNum);
     PRIndirectReference origRef = reader.GetPageOrigRef(pageNum);
     reader.ReleasePage(pageNum);
     RefKey key = new RefKey(origRef);
     PdfIndirectReference pageRef;
     IndirectReferences iRef;
     if (indirects.TryGetValue(key, out iRef) && !iRef.Copied)
     {
         pageReferences.Add(iRef.Ref);
         iRef.SetCopied();
     }
     pageRef = CurrentPage;
     if (iRef == null) {
         iRef = new IndirectReferences(pageRef);
         indirects[key] = iRef;
     }
     iRef.SetCopied();
     if (tagged)
         structTreeRootReference = (PRIndirectReference)reader.Catalog.Get(PdfName.STRUCTTREEROOT);
     PdfDictionary newPage = CopyDictionary(thePage);
     root.AddPage(newPage);
     iPage.SetCopied();
     ++currentPageNumber;
     structTreeRootReference = null;
 }
Example #25
0
 internal PdfImportedPage GetImportedPage(int pageNumber) {
     if (!reader.IsOpenedWithFullPermissions)
         throw new ArgumentException(MessageLocalization.GetComposedMessage("pdfreader.not.opened.with.owner.password"));
     if (pageNumber < 1 || pageNumber > reader.NumberOfPages)
         throw new ArgumentException(MessageLocalization.GetComposedMessage("invalid.page.number.1", pageNumber));
     PdfImportedPage pageT;
     if (!importedPages.TryGetValue(pageNumber, out pageT)) {
         pageT = new PdfImportedPage(this, writer, pageNumber);
         importedPages[pageNumber] = pageT;
     }
     return pageT;
 }
Example #26
0
 /**
 * Create a page stamp. New content and annotations, including new fields, are allowed.
 * The fields added cannot have parents in another pages. This method modifies the PdfReader instance.<p>
 * The general usage to stamp something in a page is:
 * <p>
 * <pre>
 * PdfImportedPage page = copy.getImportedPage(reader, 1);
 * PdfCopy.PageStamp ps = copy.createPageStamp(page);
 * ps.addAnnotation(PdfAnnotation.createText(copy, new Rectangle(50, 180, 70, 200), "Hello", "No Thanks", true, "Comment"));
 * PdfContentByte under = ps.getUnderContent();
 * under.addImage(img);
 * PdfContentByte over = ps.getOverContent();
 * over.beginText();
 * over.setFontAndSize(bf, 18);
 * over.setTextMatrix(30, 30);
 * over.showText("total page " + totalPage);
 * over.endText();
 * ps.alterContents();
 * copy.addPage(page);
 * </pre>
 * @param iPage an imported page
 * @return the <CODE>PageStamp</CODE>
 */
 public PageStamp CreatePageStamp(PdfImportedPage iPage)
 {
     int pageNum = iPage.PageNumber;
     PdfReader reader = iPage.PdfReaderInstance.Reader;
     PdfDictionary pageN = reader.GetPageN(pageNum);
     return new PageStamp(reader, pageN, this);
 }
 internal PdfImportedPage GetImportedPage(int pageNumber) {
     if (!reader.IsOpenedWithFullPermissions)
         throw new ArgumentException("PdfReader not opened with owner password");
     if (pageNumber < 1 || pageNumber > reader.NumberOfPages)
         throw new ArgumentException("Invalid page number: " + pageNumber);
     PdfImportedPage pageT = (PdfImportedPage)importedPages[pageNumber];
     if (pageT == null) {
         pageT = new PdfImportedPage(this, writer, pageNumber);
         importedPages[pageNumber] = pageT;
     }
     return pageT;
 }
Example #28
0
 /**
  * Initialize the imported page.
  * @param writer The PdfWriter
  */
 public void UseStationary(PdfWriter writer, byte[] stationary) {
   writer.PageEvent = new TemplateHelper(this);
   PdfReader reader = new PdfReader(stationary);
   page = writer.GetImportedPage(reader, 1);
 }
Example #29
0
 /**
 * Create a page stamp. New content and annotations, including new fields, are allowed.
 * The fields added cannot have parents in another pages. This method modifies the PdfReader instance.<p>
 * The general usage to stamp something in a page is:
 * <p>
 * <pre>
 * PdfImportedPage page = copy.GetImportedPage(reader, 1);
 * PdfCopy.PageStamp ps = copy.CreatePageStamp(page);
 * ps.AddAnnotation(PdfAnnotation.CreateText(copy, new Rectangle(50, 180, 70, 200), "Hello", "No Thanks", true, "Comment"));
 * PdfContentByte under = ps.GetUnderContent();
 * under.AddImage(img);
 * PdfContentByte over = ps.GetOverContent();
 * over.BeginText();
 * over.SetFontAndSize(bf, 18);
 * over.SetTextMatrix(30, 30);
 * over.ShowText("total page " + totalPage);
 * over.EndText();
 * ps.AlterContents();
 * copy.AddPage(page);
 * </pre>
 * @param iPage an imported page
 * @return the <CODE>PageStamp</CODE>
 */
 virtual public PageStamp CreatePageStamp(PdfImportedPage iPage) {
     int pageNum = iPage.PageNumber;
     PdfReader reader = iPage.PdfReaderInstance.Reader;
     if (IsTagged())
         throw new Exception(MessageLocalization.GetComposedMessage("creating.page.stamp.not.allowed.for.tagged.reader"));
     PdfDictionary pageN = reader.GetPageN(pageNum);
     return new PageStamp(reader, pageN, this);
 }
        private void addContentToPage(PdfReader reader, Rectangle size, PdfImportedPage page)
        {
            if (WriterCustomizer == null)
                return;

            var stamp = _writer.CreatePageStamp(page);
            WriterCustomizer(new ImportedPageInfo
            {
                FileNumber = _fileNumber,
                Reader = reader,
                Stamp = stamp,
                PageSize = size,
                ImportedPage = page,
                CurrentPageNumber = _overallPageNumber,
                PdfDocument = _document,
                TotalNumberOfPages = _totalNumberOfPages
            });
            stamp.AlterContents();
        }
Example #31
0
        /**
        * Add an imported page to our output
        * @param iPage an imported page
        * @throws IOException, BadPdfFormatException
        */
        public void AddPage(PdfImportedPage iPage)
        {
            int pageNum = SetFromIPage(iPage);

            PdfDictionary thePage = reader.GetPageN(pageNum);
            PRIndirectReference origRef = reader.GetPageOrigRef(pageNum);
            reader.ReleasePage(pageNum);
            RefKey key = new RefKey(origRef);
            PdfIndirectReference pageRef;
            IndirectReferences iRef = (IndirectReferences)indirects[key] ;
            iRef = null; // temporary hack to have multiple pages, may break is some cases
            // if we already have an iref for the page (we got here by another link)
            if (iRef != null) {
                pageRef = iRef.Ref;
            }
            else {
                pageRef = body.PdfIndirectReference;
                iRef = new IndirectReferences(pageRef);
                indirects[key] =  iRef;
            }
            pageReferences.Add(pageRef);
            ++currentPageNumber;
            if (! iRef.Copied) {
                iRef.SetCopied();
                PdfDictionary newPage = CopyDictionary(thePage);
                newPage.Put(PdfName.PARENT, topPageParent);
                AddToBody(newPage, pageRef);
            }
            root.AddPage(pageRef);
            pageNumbersToRefs.Add(pageRef);
        }
Example #32
0
 public override void AddPage(PdfImportedPage iPage) {
     CheckPdfAInfo(iPage.readerInstance.Reader);
     base.AddPage(iPage);
 }
Example #33
0
        /**
        * Add an imported page to our output
        * @param iPage an imported page
        * @throws IOException, BadPdfFormatException
        */
        public void AddPage(PdfImportedPage iPage)
        {
            int pageNum = SetFromIPage(iPage);

            PdfDictionary thePage = reader.GetPageN(pageNum);
            PRIndirectReference origRef = reader.GetPageOrigRef(pageNum);
            reader.ReleasePage(pageNum);
            RefKey key = new RefKey(origRef);
            PdfIndirectReference pageRef;
            IndirectReferences iRef;
            indirects.TryGetValue(key, out iRef);
            if (iRef != null && !iRef.Copied) {
                pageReferences.Add(iRef.Ref);
                iRef.SetCopied();
            }
            pageRef = CurrentPage;
            if (iRef == null) {
                iRef = new IndirectReferences(pageRef);
                indirects[key] = iRef;
            }
            iRef.SetCopied();
            PdfDictionary newPage = CopyDictionary(thePage);
            root.AddPage(newPage);
            iPage.SetCopied();
            ++currentPageNumber;
        }
Example #34
0
 /**
 * Add an imported page to our output
 * @param iPage an imported page
 * @throws IOException, BadPdfFormatException
 */
 public virtual void AddPage(PdfImportedPage iPage) {
     if (mergeFields && !mergeFieldsInternalCall) {
         throw new ArgumentException(MessageLocalization.GetComposedMessage("1.method.cannot.be.used.in.mergeFields.mode.please.use.addDocument", "addPage"));
     }
     int pageNum = SetFromIPage(iPage);
     
     PdfDictionary thePage = reader.GetPageN(pageNum);
     PRIndirectReference origRef = reader.GetPageOrigRef(pageNum);
     reader.ReleasePage(pageNum);
     RefKey key = new RefKey(origRef);
     PdfIndirectReference pageRef;
     IndirectReferences iRef;
     if (indirects.TryGetValue(key, out iRef) && !iRef.Copied)
     {
         pageReferences.Add(iRef.Ref);
         iRef.SetCopied();
     }
     pageRef = CurrentPage;
     if (iRef == null) {
         iRef = new IndirectReferences(pageRef);
         indirects[key] = iRef;
     }
     iRef.SetCopied();
     if (tagged)
         structTreeRootReference = (PRIndirectReference)reader.Catalog.Get(PdfName.STRUCTTREEROOT);
     PdfDictionary newPage = CopyDictionary(thePage);
     root.AddPage(newPage);
     iPage.SetCopied();
     ++currentPageNumber;
     structTreeRootReference = null;
 }
Example #35
0
 /**
 * convenience method. Given an importedpage, set our "globals"
 */
 protected int SetFromIPage(PdfImportedPage iPage)
 {
     int pageNum = iPage.PageNumber;
     PdfReaderInstance inst = currentPdfReaderInstance = iPage.PdfReaderInstance;
     reader = inst.Reader;
     SetFromReader(reader);
     return pageNum;
 }
Example #36
0
 internal PdfImportedPage GetImportedPage(int pageNumber)
 {
     if (pageNumber < 1 || pageNumber > reader.NumberOfPages)
         throw new ArgumentException("Invalid page number");
     PdfImportedPage pageT = (PdfImportedPage)importedPages[pageNumber];
     if (pageT == null) {
         pageT = new PdfImportedPage(this, writer, pageNumber);
         importedPages[pageNumber] = pageT;
     }
     return pageT;
 }
Example #37
0
 public override void AddPage(PdfImportedPage iPage)  {
     if (currentPdfReaderInstance.Reader != reader)
         serialized.Clear();
     base.AddPage(iPage);
 }
Example #38
0
        public Boolean MergePdfFiles(String[] pdfFiles, String outputPath)
        {
            //                                     Optional ByVal authorName As String = "", _
            //                                     Optional ByVal creatorName As String = "", _
            //                                     Optional ByVal subject As String = "", _
            //                                     Optional ByVal title As String = "", _
            //                                     Optional ByVal keywords As String = "")
            Boolean result   = false;
            int     pdfCount = 0;                        //'total input pdf file count
            int     f        = 0;                        //'pointer to current input pdf file
            string  fileName = String.Empty;             // 'current input pdf filename

            iTextSharp.text.pdf.PdfReader reader = null;
            int pageCount = 0;                                //'cureent input pdf page count

            iTextSharp.text.Document           pdfDoc = null; //   'the output pdf document
            iTextSharp.text.pdf.PdfWriter      writer = null;
            iTextSharp.text.pdf.PdfContentByte cb     = null;
            //    'Declare a variable to hold the imported pages
            iTextSharp.text.pdf.PdfImportedPage page = null;
            int  rotation         = 0;
            bool unethicalreading = false;

            //    'Declare a font to used for the bookmarks
            iTextSharp.text.Font bookmarkFont = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 12, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLUE);

            // Try
            pdfCount = pdfFiles.Length;
            if (pdfCount > 1)
            {
                //            'Open the 1st pad using PdfReader object
                fileName = pdfFiles[f];
                reader   = new iTextSharp.text.pdf.PdfReader(fileName);
                // reader.
                iTextSharp.text.pdf.PdfReader.unethicalreading = unethicalreading;
                //            'Get page count
                pageCount = reader.NumberOfPages;

                //            'Instantiate an new instance of pdf document and set its margins. This will be the output pdf.
                //            'NOTE: bookmarks will be added at the 1st page of very original pdf file using its filename. The location
                //            'of this bookmark will be placed at the upper left hand corner of the document. So you'll need to adjust
                //            'the margin left and margin top values such that the bookmark won't overlay on the merged pdf page. The
                //            'unit used is "points" (72 points = 1 inch), thus in this example, the bookmarks' location is at 1/4 inch from
                //            'left and 1/4 inch from top of the page.

                pdfDoc = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(1), 18, 18, 18, 18);
                //            'Instantiate a PdfWriter that listens to the pdf document
                writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, new System.IO.FileStream(outputPath, System.IO.FileMode.Create));    //added system
                //            'Set metadata and open the document
                // With pdfDoc
                pdfDoc.AddAuthor("");
                pdfDoc.AddCreationDate();
                pdfDoc.AddCreator("");
                pdfDoc.AddProducer();
                pdfDoc.AddSubject("");
                pdfDoc.AddTitle("");
                pdfDoc.AddKeywords("");
                pdfDoc.Open();
                //  End With
                //            'Instantiate a PdfContentByte object
                cb = writer.DirectContent;
                //            'Now loop thru the input pdfs
                while (f < pdfCount)
                {
                    //                'Declare a page counter variable
                    int i = 0;
                    //                'Loop thru the current input pdf's pages starting at page 1
                    while (i < pageCount)
                    {
                        i += 1;
                        //                    'Get the input page size
                        pdfDoc.SetPageSize(reader.GetPageSizeWithRotation(i));
                        //                    'Create a new page on the output document
                        pdfDoc.NewPage();

                        //                    'If it is the 1st page, we add bookmarks to the page
                        //                    'If i = 1 Then
                        //                    '    'First create a paragraph using the filename as the heading
                        //                    '    Dim para As New iTextSharp.text.Paragraph(IO.Path.GetFileName(fileName).ToUpper(), bookmarkFont)
                        //                    '    'Then create a chapter from the above paragraph
                        //                    '    Dim chpter As New iTextSharp.text.Chapter(para, f + 1)
                        //                    '    'Finally add the chapter to the document
                        //                    '    pdfDoc.Add(chpter)
                        //                    'End If

                        //                    'Now we get the imported page


                        page = writer.GetImportedPage(reader, i);
                        //                    'Read the imported page's rotation
                        rotation = reader.GetPageRotation(i);
                        //                    'Then add the imported page to the PdfContentByte object as a template based on the page's rotation
                        if (rotation == 90)
                        {
                            cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(i).Height);
                        }
                        else
                        if (rotation == 270)
                        {
                            cb.AddTemplate(page, 0, 1.0F, -1.0F, 0, reader.GetPageSizeWithRotation(i).Width + 60, -30);
                        }
                        else
                        {
                            cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0);
                        }
                    } //End While 2

                    //                'Increment f and read the next input pdf file
                    f += 1;
                    if (f < pdfCount)
                    {
                        fileName  = pdfFiles[f];
                        reader    = new iTextSharp.text.pdf.PdfReader(fileName);
                        pageCount = reader.NumberOfPages;
                    } //   End If
                }        //end while 1
                //            'When all done, we close the document so that the pdfwriter object can write it to the output file
                pdfDoc.Close();
                result = true;
            }//        End If Principal
             //    Catch ex As Exception
             //        Throw New Exception(ex.Message)
             //    End Try

            return(result);
        }