Example #1
0
        public void SplitByPageRanges(string pageRanges)
        {
            int num;
            int num1;
            int num2;
            int num3;

            if (this.CheckOutput())
            {
                PDFHelper.DisplayTrialPopupIfNecessary();
                try
                {
                    string[] strArrays  = pageRanges.Split(new char[] { ',' });
                    List     list       = IteratorUtils.toList(this.pdfDocument.PDFBoxDocument.getPages().iterator());
                    int      num4       = list.size();
                    string[] strArrays1 = strArrays;
                    for (int i = 0; i < (int)strArrays1.Length; i++)
                    {
                        string str = strArrays1[i];
                        if (this.ConfigureRange(str, num4, out num, out num1, out num2, out num3))
                        {
                            List       list1      = list.subList(num, num1);
                            PDDocument pDDocument = new PDDocument();
                            for (int j = num2; j < list1.size(); j = j + num3)
                            {
                                PDPage pDPage = (PDPage)list1.@get(j);
                                pDPage.getResources();
                                pDDocument.addPage(pDPage);
                            }
                            pDDocument = PDFHelper.AddTrialStampIfNecessary(pDDocument);
                            string str1 = string.Format("{0} [{1}].pdf", this.OutputFileName, str);
                            pDDocument.save(Path.Combine(this.OutputFilePath, str1));
                        }
                        else
                        {
                            Console.WriteLine("Invalid range: {0}", str);
                        }
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    throw new PDFToolkitException(exception.Message, exception.InnerException);
                }
            }
        }
Example #2
0
        private void SplitByRepeatingPageRanges(string pageRange, int repeatEvery, PDPageTree allPages, int pageCount, string suffix)
        {
            int num;
            int num1;
            int num2;
            int num3;

            if (this.ConfigureRange(pageRange, pageCount, out num, out num1, out num2, out num3))
            {
                List       list       = IteratorUtils.toList(allPages.iterator());
                List       list1      = list.subList(num, num1);
                PDDocument pDDocument = new PDDocument();
                for (int i = num2; i < list1.size(); i = i + num3)
                {
                    pDDocument.addPage((PDPage)list1.@get(i));
                }
                pDDocument = PDFHelper.AddTrialStampIfNecessary(pDDocument);
                string str = string.Format("{0} [{1}].pdf", this.OutputFileName, this.splitCounter);
                pDDocument.save(Path.Combine(this.OutputFilePath, str));
                if (repeatEvery > 0)
                {
                    num  = num + repeatEvery + 1;
                    num1 = num1 + repeatEvery;
                    if (num <= pageCount)
                    {
                        if (num1 > pageCount)
                        {
                            num1 = pageCount;
                        }
                        this.splitCounter = this.splitCounter + 1;
                        string str1 = string.Format("{0}-{1}{2}", num, num1, suffix);
                        this.SplitByRepeatingPageRanges(str1, repeatEvery, allPages, pageCount, suffix);
                    }
                }
            }
            else
            {
                Console.WriteLine("Invalid page range.");
            }
        }
Example #3
0
 private void Split(int start, int end, int repeatEvery)
 {
     if (this.CheckOutput())
     {
         PDFHelper.DisplayTrialPopupIfNecessary();
         try
         {
             Splitter splitter = new Splitter();
             splitter.setStartPage(start);
             splitter.setEndPage(end);
             splitter.setSplitAtPage(repeatEvery);
             List list = splitter.split(this.pdfDocument.PDFBoxDocument);
             for (int i = 0; i < list.size(); i++)
             {
                 PDDocument pDDocument = PDFHelper.AddTrialStampIfNecessary((PDDocument)list.@get(i));
                 string     str        = string.Format("{0} [{1}].pdf", this.OutputFileName, i);
                 pDDocument.save(Path.Combine(this.OutputFilePath, str));
             }
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             throw new PDFToolkitException(exception.Message, exception.InnerException);
         }
     }
 }