Java Code Examples for com.itextpdf.text.pdf.PdfContentByte#newPath()
The following examples show how to use
com.itextpdf.text.pdf.PdfContentByte#newPath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Abstract2DPdfPageSplittingTool.java From testarea-itext5 with GNU Affero General Public License v3.0 | 7 votes |
void split(PdfReader reader, int page) throws IOException { PdfImportedPage importedPage = writer.getImportedPage(reader, page); Rectangle pageSizeToImport = reader.getPageSize(page); Iterable<Rectangle> rectangles = determineSplitRectangles(reader, page); for (Rectangle rectangle : rectangles) { newPage(rectangle); PdfContentByte directContent = writer.getDirectContent(); directContent.saveState(); directContent.rectangle(rectangle.getLeft(), rectangle.getBottom(), rectangle.getWidth(), rectangle.getHeight()); directContent.clip(); directContent.newPath(); writer.getDirectContent().addTemplate(importedPage, -pageSizeToImport.getLeft(), -pageSizeToImport.getBottom()); directContent.restoreState(); } }
Example 2
Source File: AbstractPdfPageSplittingTool.java From testarea-itext5 with GNU Affero General Public License v3.0 | 6 votes |
void split(PdfReader reader, int page) throws IOException { PdfImportedPage importedPage = writer.getImportedPage(reader, page); PdfContentByte directContent = writer.getDirectContent(); yPosition = pageSize.getTop(); Rectangle pageSizeToImport = reader.getPageSize(page); float[] borderPositions = determineSplitPositions(reader, page); if (borderPositions == null || borderPositions.length < 2) return; for (int borderIndex = 0; borderIndex + 1 < borderPositions.length; borderIndex++) { float height = borderPositions[borderIndex] - borderPositions[borderIndex + 1]; if (height <= 0) continue; directContent.saveState(); directContent.rectangle(0, yPosition - height, pageSizeToImport.getWidth(), height); directContent.clip(); directContent.newPath(); writer.getDirectContent().addTemplate(importedPage, 0, yPosition - (borderPositions[borderIndex] - pageSizeToImport.getBottom())); directContent.restoreState(); newPage(); } }
Example 3
Source File: PdfVeryDenseMergeTool.java From testarea-itext5 with GNU Affero General Public License v3.0 | 4 votes |
void merge(PdfReader reader, PdfReaderContentParser parser, int page) throws IOException { PdfImportedPage importedPage = writer.getImportedPage(reader, page); PdfContentByte directContent = writer.getDirectContent(); PageVerticalAnalyzer finder = parser.processContent(page, new PageVerticalAnalyzer()); if (finder.verticalFlips.size() < 2) return; Rectangle pageSizeToImport = reader.getPageSize(page); int startFlip = finder.verticalFlips.size() - 1; boolean first = true; while (startFlip > 0) { if (!first) newPage(); float freeSpace = yPosition - pageSize.getBottom(bottomMargin); int endFlip = startFlip + 1; while ((endFlip > 1) && (finder.verticalFlips.get(startFlip) - finder.verticalFlips.get(endFlip - 2) < freeSpace)) endFlip -=2; if (endFlip < startFlip) { float height = finder.verticalFlips.get(startFlip) - finder.verticalFlips.get(endFlip); directContent.saveState(); directContent.rectangle(0, yPosition - height, pageSizeToImport.getWidth(), height); directContent.clip(); directContent.newPath(); writer.getDirectContent().addTemplate(importedPage, 0, yPosition - (finder.verticalFlips.get(startFlip) - pageSizeToImport.getBottom())); directContent.restoreState(); yPosition -= height + gap; startFlip = endFlip - 1; } else if (!first) throw new IllegalArgumentException(String.format("Page %s content sections too large.", page)); first = false; } }