public virtual void AddCustomAnd() { PageRange range = new PageRange(); PageRange.IPageRangePart odd = PageRange.PageRangePartOddEven.ODD; PageRange.IPageRangePart seq = new PageRange.PageRangePartSequence(2, 14); PageRange.IPageRangePart and = new PageRange.PageRangePartAnd(odd, seq); range.AddPageRangePart(and); NUnit.Framework.Assert.AreEqual(range.GetQualifyingPageNums(15), JavaUtil.ArraysAsList(3, 5, 7, 9, 11, 13) ); }
/// <summary>Splits a document into smaller documents with no more than @pageCount pages each.</summary> /// <param name="pageCount">the biggest possible number of pages in a split document.</param> /// <param name="documentReady"> /// the event listener which is called when another document is ready. /// You can close this document in this listener, for instance. /// </param> public virtual void SplitByPageCount(int pageCount, PdfSplitter.IDocumentReadyListener documentReady) { for (int startPage = 1; startPage <= pdfDocument.GetNumberOfPages(); startPage += pageCount) { int endPage = Math.Min(startPage + pageCount - 1, pdfDocument.GetNumberOfPages()); PageRange currentPageRange = new PageRange().AddPageSequence(startPage, endPage); PdfDocument currentDocument = CreatePdfDocument(currentPageRange); pdfDocument.CopyPagesTo(startPage, endPage, currentDocument); documentReady.DocumentReady(currentDocument, currentPageRange); } }
private PdfDocument CreatePdfDocument(PageRange currentPageRange) { PdfDocument newDocument = new PdfDocument(GetNextPdfWriter(currentPageRange)); if (pdfDocument.IsTagged() && preserveTagged) { newDocument.SetTagged(); } if (pdfDocument.HasOutlines() && preserveOutlines) { newDocument.InitializeOutlines(); } return(newDocument); }
/// <summary>Splits the document basing on the given size.</summary> /// <param name="size"><strog>Preferred</strog> size for splitting.</param> /// <returns> /// The documents which the source document was split into. /// Be warned that these documents are not closed. /// </returns> public virtual IList <PdfDocument> SplitBySize(long size) { IList <PageRange> splitRanges = new List <PageRange>(); int currentPage = 1; int numOfPages = pdfDocument.GetNumberOfPages(); while (currentPage <= numOfPages) { PageRange nextRange = GetNextRange(currentPage, numOfPages, size); splitRanges.Add(nextRange); IList <int> allPages = nextRange.GetAllPages(); currentPage = (int)allPages[allPages.Count - 1] + 1; } return(ExtractPageRanges(splitRanges)); }
private PdfDocument CreatePdfDocument(PageRange currentPageRange) { PdfDocument newDocument = new PdfDocument(GetNextPdfWriter(currentPageRange), new DocumentProperties().SetEventCountingMetaInfo (metaInfo)); if (pdfDocument.IsTagged() && preserveTagged) { newDocument.SetTagged(); } if (pdfDocument.HasOutlines() && preserveOutlines) { newDocument.InitializeOutlines(); } return(newDocument); }
/// <summary>Splits the document by page numbers.</summary> /// <param name="pageNumbers"> /// the numbers of pages from which another document is to be started. /// If the first element is not 1, then 1 is implied (i.e. the first split document will start from page 1 in any case). /// </param> /// <param name="documentReady"> /// the event listener which is called when another document is ready. /// You can close this document in this listener, for instance. /// </param> /// <exception cref="iText.Kernel.PdfException"/> public virtual void SplitByPageNumbers(IList <int> pageNumbers, PdfSplitter.IDocumentReadyListener documentReady ) { int currentPageNumber = 1; for (int ind = 0; ind <= pageNumbers.Count; ind++) { int nextPageNumber = ind == pageNumbers.Count ? pdfDocument.GetNumberOfPages() + 1 : (int)pageNumbers[ind]; if (ind == 0 && nextPageNumber == 1) { continue; } PageRange currentPageRange = new PageRange().AddPageSequence(currentPageNumber, nextPageNumber - 1); PdfDocument currentDocument = CreatePdfDocument(currentPageRange); pdfDocument.CopyPagesTo(currentPageNumber, nextPageNumber - 1, currentDocument); documentReady.DocumentReady(currentDocument, currentPageRange); currentPageNumber = nextPageNumber; } }
public virtual void SplitDocumentTest03() { String inputFileName = sourceFolder + "iphone_user_guide.pdf"; PdfDocument inputPdfDoc = new PdfDocument(new PdfReader(inputFileName)); PageRange pageRange1 = new PageRange().AddPageSequence(4, 15).AddSinglePage(18).AddPageSequence(1, 2); PageRange pageRange2 = new PageRange().AddSinglePage(99).AddSinglePage(98).AddPageSequence(70, 99); IList <PdfDocument> splitDocuments = new _PdfSplitter_155(inputPdfDoc).ExtractPageRanges(JavaUtil.ArraysAsList (pageRange1, pageRange2)); foreach (PdfDocument pdfDocument in splitDocuments) { pdfDocument.Close(); } for (int i = 1; i <= 2; i++) { NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "splitDocument3_" + i + ".pdf", sourceFolder + "cmp/" + "cmp_splitDocument3_" + i.ToString() + ".pdf", destinationFolder, "diff_" )); } }
/// <summary>This method is called when another split document is to be created.</summary> /// <remarks> /// This method is called when another split document is to be created. /// You can override this method and return your own /// <seealso>PdfWriter</seealso> /// depending on your needs. /// </remarks> /// <param name="documentPageRange">the page range of the original document to be included in the document being created now. /// </param> /// <returns>the PdfWriter instance for the document which is being created.</returns> protected internal virtual PdfWriter GetNextPdfWriter(PageRange documentPageRange) { return(new PdfWriter(new ByteArrayOutputStream())); }
/// <summary>Extracts the specified page ranges from a document.</summary> /// <param name="pageRange">the page range to be extracted from the document.</param> /// <returns> /// the resultant document containing the pages specified by the provided page range. /// Be warned that this document is not closed. /// </returns> /// <exception cref="iText.Kernel.PdfException"/> public virtual PdfDocument ExtractPageRange(PageRange pageRange) { return(ExtractPageRanges(JavaCollectionsUtil.SingletonList(pageRange))[0]); }
public void DocumentReady(PdfDocument pdfDocument, PageRange pageRange) { splitDocuments.Add(pdfDocument); }
public virtual void AddIncorrectConstructor() { PageRange range = new PageRange(""); NUnit.Framework.Assert.AreEqual(new List <Object>(), range.GetQualifyingPageNums(0)); }
public virtual void PageRangeEqualsNullTest() { PageRange range1 = new PageRange("3-8"); NUnit.Framework.Assert.IsFalse(range1.Equals(null)); }
public virtual void IsPageInRangeFalseTest() { PageRange range = new PageRange("3-8"); NUnit.Framework.Assert.IsFalse(range.IsPageInRange(2)); }
public virtual void IsPageInRangeTrueTest() { PageRange range = new PageRange("3-8"); NUnit.Framework.Assert.IsTrue(range.IsPageInRange(6)); }
public virtual void AddSinglesConstructor() { PageRange range = new PageRange("5, 1"); NUnit.Framework.Assert.AreEqual(range.GetQualifyingPageNums(10), JavaUtil.ArraysAsList(5, 1)); }
public virtual void AddCustomEvenConstructor() { PageRange range = new PageRange("even"); NUnit.Framework.Assert.AreEqual(range.GetQualifyingPageNums(5), JavaUtil.ArraysAsList(2, 4)); }
public virtual void AddCustomAfterConstructor() { PageRange range = new PageRange("3-"); NUnit.Framework.Assert.AreEqual(JavaUtil.ArraysAsList(3, 4, 5), range.GetQualifyingPageNums(5)); }