[]
SerializableUse this class to generate PageInfo objects for a workbook or worksheet, adjust pagination results, and save the resulting pages to PDF. It is the entry point for custom pagination workflows such as controlling page breaks, keeping content together, and combining content from one or more workbooks into a single PDF output.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", 200},
{"C", 300}
});
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(worksheet);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
printManager.savePageInfosToPDF(stream, pages);
final voidappendPage(org.apache.pdfbox.pdmodel.PDDocument doc,
PageInfo pageInfo) final voidappendPage(org.apache.pdfbox.pdmodel.PDDocument doc,
PageInfo pageInfo,
PdfSaveOptions options) final voiddraw(org.apache.pdfbox.pdmodel.PDDocument doc,
org.apache.pdfbox.pdmodel.PDPage page,
Point location,
IRange range) final voiddraw(org.apache.pdfbox.pdmodel.PDDocument doc,
org.apache.pdfbox.pdmodel.PDPage page,
Point location,
IRange range,
PdfSaveOptions options) final voiddraw(org.apache.pdfbox.pdmodel.PDDocument doc,
org.apache.pdfbox.pdmodel.PDPage page,
Rectangle rect,
IRange range) final voiddraw(org.apache.pdfbox.pdmodel.PDDocument doc,
org.apache.pdfbox.pdmodel.PDPage page,
Rectangle rect,
IRange range,
PdfSaveOptions options) final voiddraw(org.apache.pdfbox.pdmodel.PDDocument doc,
org.apache.pdfbox.pdmodel.PDPage page,
Rectangle rect,
PageContentInfo pageContent) final voiddraw(org.apache.pdfbox.pdmodel.PDDocument doc,
org.apache.pdfbox.pdmodel.PDPage page,
Rectangle rect,
PageContentInfo pageContent,
PdfSaveOptions options) final voiddraw(org.apache.pdfbox.pdmodel.PDDocument doc,
org.apache.pdfbox.pdmodel.PDPage page,
Rectangle rect,
PageInfo pageInfo) final voiddraw(org.apache.pdfbox.pdmodel.PDDocument doc,
org.apache.pdfbox.pdmodel.PDPage page,
Rectangle rect,
PageInfo pageInfo,
PdfSaveOptions options) final voiddraw(org.apache.pdfbox.pdmodel.PDDocument doc,
org.apache.pdfbox.pdmodel.PDPage page,
List<PageInfo> pages,
int rows,
int columns) final voiddraw(org.apache.pdfbox.pdmodel.PDDocument doc,
org.apache.pdfbox.pdmodel.PDPage page,
List<PageInfo> pages,
int rows,
int columns,
Order order) final voiddraw(org.apache.pdfbox.pdmodel.PDDocument doc,
org.apache.pdfbox.pdmodel.PDPage page,
List<PageInfo> pages,
int rows,
int columns,
Order order,
PdfSaveOptions options) protected voidfinalize()final PageContentInfogeneratePageContentInfo(IRange printArea,
Size availableSize,
int rowStart,
int columnStart,
boolean rowHeaderVisible,
boolean columnHeaderVisible) PageContentInfo object for the specified print area and page size.GetPaginationInfo(IWorksheet worksheet,
PaginationOrientation orientation) GetPaginationInfo(IWorksheet worksheet,
PaginationOrientation orientation,
List<IRange> keepTogetherRanges,
List<RepeatSetting> repeatSettings) getPrintAreas(IWorksheet worksheet) final Sizefinal SizegetSize(PageContentInfo contentInfo) final booleanhasPrintContent(IRange range) paginate(IWorksheet worksheet) paginate(IWorksheet worksheet,
List<IRange> keepTogetherRanges,
List<RepeatSetting> repeatSettings) final voidsavePageInfosToPDF(OutputStream stream,
List<PageInfo> pages) final voidsavePageInfosToPDF(OutputStream stream,
List<PageInfo> pages,
PdfSaveOptions options) final voidsavePageInfosToPDF(String fileName,
List<PageInfo> pages) final voidsavePageInfosToPDF(String fileName,
List<PageInfo> pages,
PdfSaveOptions options) final voidsaveWorkbooksToPDF(OutputStream stream,
List<IWorkbook> workbooks) final voidsaveWorkbooksToPDF(OutputStream stream,
List<IWorkbook> workbooks,
PdfSaveOptions options) final voidsaveWorkbooksToPDF(String fileName,
List<IWorkbook> workbooks) final voidsaveWorkbooksToPDF(String fileName,
List<IWorkbook> workbooks,
PdfSaveOptions options) final voidfinal voidupdatePageNumberAndPageSettings(List<PageInfo> pages,
int firstPageNumber,
int pageCount) This implementation clears each cached font collection in the internal collection and then calls super.finalize().
This method is invoked by the JVM finalization mechanism and should not be called directly from user code.
This method paginates the workbooks in list order by calling paginate(List) and then writes the generated pages to the specified output stream by calling savePageInfosToPDF(OutputStream,List).
worksheet.getPageSetup().setPrintArea("B2:D6");
worksheet.getRange("B2:D6").setValue("Test");
IWorkbook secondWorkbook = workbook.clone();
secondWorkbook.getWorksheets().get(0).getRange("B2").setValue("Summary");
List<IWorkbook> workbooks = new ArrayList<IWorkbook>();
workbooks.add(workbook);
workbooks.add(secondWorkbook);
PrintManager printManager = new PrintManager();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
printManager.saveWorkbooksToPDF(stream, workbooks);
stream - The output stream that receives the generated PDF data.workbooks - The workbooks to paginate and export. The workbooks are processed in the order they appear in the list.The workbooks are paginated in list order, and the generated pages are written to the supplied stream by calling savePageInfosToPDF(OutputStream,List,PdfSaveOptions).
worksheet.getPageSetup().setPrintArea("B2:D6");
worksheet.getRange("B2:D6").setValue("Test");
PrintManager printManager = new PrintManager();
List<IWorkbook> workbooks = new ArrayList<IWorkbook>();
workbooks.add(workbook);
IWorkbook secondWorkbook = workbook.clone();
secondWorkbook.getWorksheets().get(0).getRange("A1").setValue("Second workbook");
workbooks.add(secondWorkbook);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
printManager.saveWorkbooksToPDF(stream, workbooks, new PdfSaveOptions());
stream - The output stream to write the PDF data to. Must not be null.workbooks - The workbooks to paginate and export. The workbooks are processed in the order they appear in the list.options - The PDF save options. May be null.Each workbook in the collection is paginated, and all generated pages are written to the PDF. This overload passes null for PdfSaveOptions to the three-argument overload.
worksheet.getRange("A1").setValue("First workbook");
IWorkbook secondWorkbook = workbook.clone();
secondWorkbook.getWorksheets().get(0).getRange("A1").setValue("Second workbook");
PrintManager printManager = new PrintManager();
List<IWorkbook> workbooks = Arrays.asList(workbook, secondWorkbook);
printManager.saveWorkbooksToPDF("path/to/workbooks.pdf", workbooks);
fileName - The path and name of the PDF file to create. Must be a valid file path; null or an invalid path causes an IllegalArgumentException.workbooks - The collection of Workbook objects to save. This value is passed to the underlying save operation without additional validation by this overload.IllegalArgumentException - if fileName is not a valid path.RuntimeException - if an I/O error occurs while creating or writing the PDF file.
worksheet.getRange("A1").setValue("First workbook");
IWorkbook secondWorkbook = workbook.clone();
secondWorkbook.getWorksheets().get(0).getRange("A1").setValue("Second workbook");
PrintManager printManager = new PrintManager();
List<IWorkbook> workbooks = Arrays.asList(workbook, secondWorkbook);
PdfSaveOptions options = new PdfSaveOptions();
printManager.saveWorkbooksToPDF("path/to/workbooks.pdf", workbooks, options);
fileName - The specified pdf file.workbooks - The workbook collection.options - Options for saving pdf file.
worksheet.getPageSetup().setPrintArea("A1:B4");
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", 200},
{"C", 300}
});
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(worksheet);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
printManager.savePageInfosToPDF(stream, pages);
stream - The specified pdf file.pages - The page information collection.The pages collection should be generated by paginate(IWorksheet). Passing a null or empty collection causes an IllegalStateException.
worksheet.getPageSetup().setPrintArea("A1:B4");
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", 200},
{"C", 300}
});
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(worksheet);
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
printManager.savePageInfosToPDF(stream, pages, new PdfSaveOptions());
} catch (Exception e) {
}
stream - The output stream to write the PDF data to. Must not be null.pages - The page information collection to export. Must contain at least one page; null or an empty list causes an IllegalStateException.options - The PDF save options. Can be null.IllegalStateException - if pages is null or empty.This overload forwards null for the PdfSaveOptions argument to savePageInfosToPDF(String,List,PdfSaveOptions).
worksheet.getPageSetup().setPrintArea("B2:D6");
worksheet.getRange("B2:D6").setValue("Test");
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(workbook);
printManager.savePageInfosToPDF("path/to/pages.pdf", pages);
fileName - The path of the PDF file to create. Must be a valid file path.pages - The page information collection to save.IllegalArgumentException - if fileName is not a valid path.This method writes the supplied PageInfo objects to the PDF file identified by fileName. The options argument is passed to savePageInfosToPDF(OutputStream,List,PdfSaveOptions).
worksheet.getPageSetup().setPrintArea("B2:D6");
worksheet.getRange("B2:D6").setValue("Test");
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(workbook);
PdfSaveOptions options = new PdfSaveOptions();
printManager.savePageInfosToPDF("path/to/pages.pdf", pages, options);
fileName - The path of the PDF file to create. Must be a valid file path.pages - The page information collection to save.options - The options to use when saving the PDF file. May be null.IllegalArgumentException - if fileName is not a valid path.RuntimeException - if an I/O error occurs while creating or writing the PDF file.This method paginates each workbook in the specified list by calling paginate(IWorkbook), combines the resulting PageInfo objects into a single list, and then updates the page number and page settings for the combined pages.
worksheet.getPageSetup().setPrintArea("B2:D6");
worksheet.getRange("B2:D6").setValue("Test");
List<IWorkbook> workbooks = new ArrayList<IWorkbook>();
workbooks.add(workbook);
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(workbooks);
workbooks - The workbooks to paginate. The workbooks are processed in the order they appear in the list.PageInfo objects generated from all workbooks. Returns an empty list if the specified list is empty.This method paginates each worksheet whose visibility is Visibility.Visible, combines the resulting PageInfo objects into a single list, and updates the page number, page count, and page settings for the generated pages.
worksheet.getPageSetup().setPrintArea("B2:D6");
worksheet.getRange("B2:D6").setValue("Test");
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(workbook);
workbook - The workbook whose visible worksheets are paginated. Must not be null.PageInfo objects for all visible worksheets in the workbook. Returns an empty list if no pages are generated.The pagination result is calculated from the worksheet's current print areas and page setup. Each returned PageInfo describes one generated page in page order.
worksheet.getPageSetup().setPrintArea("B2:N40");
worksheet.getRange("B2:N40").setValue(10);
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(worksheet);
worksheet - The worksheet whose pages are generated. Must not be null.PageInfo objects that describe the generated pages in page order. Returns an empty list if no printable pages are generated.The pagination result is calculated from the worksheet's current page setup and print areas. Use keepTogetherRanges to keep specific ranges on the same page, and use repeatSettings to repeat title or tail rows or columns for a range during pagination.
worksheet.getPageSetup().setPrintArea("A1:D80");
worksheet.getRange("A1:D80").setValue(100);
List<IRange> keepTogetherRanges = new ArrayList<>();
keepTogetherRanges.add(worksheet.getRange("$20:$25"));
RepeatSetting repeatSetting = new RepeatSetting();
repeatSetting.setRange(worksheet.getRange("A1:D80"));
repeatSetting.setTitleRowStart(0);
repeatSetting.setTitleRowEnd(0);
List<RepeatSetting> repeatSettings = new ArrayList<>();
repeatSettings.add(repeatSetting);
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(worksheet, keepTogetherRanges, repeatSettings);
worksheet - The worksheet whose pages are generated. Must not be null.keepTogetherRanges - The ranges that should remain on the same page. Can be null or empty if no keep-together ranges are needed.repeatSettings - The repeat settings applied during pagination. Can be null or empty if no repeating rows or columns are needed.PageInfo objects that describe the generated pages in page order. Returns an empty list if no printable pages are generated.IllegalStateException - if a keep-together range or repeat setting cannot fit within the printable page area.PageContentInfo object for the specified print area and page size.The result is calculated from the supplied start row, start column, available size, and row and column header visibility settings.
worksheet.getRange("A1:C5").setValue(new Object[][] {
{"Name", "Value", "Status"},
{"Test", 100, "Ready"}
});
PrintManager printManager = new PrintManager();
PageContentInfo info = printManager.generatePageContentInfo(
worksheet.getRange("A1:C5"), new Size(400, 300), 0, 0, true, false);
printArea - The print area to evaluate. Must not be null.availableSize - The page content size excluding margins. Must not be null.rowStart - The zero-based start row index used to calculate the ending row.columnStart - The zero-based start column index used to calculate the ending column.rowHeaderVisible - Whether the row header is printed with this page.columnHeaderVisible - Whether the column header is printed with this page.PageContentInfo object that describes the calculated page content.Call this method after the page collection changes, such as when pages are added, deleted, or moved. It refreshes the supplied PageInfo list so pagination metadata stays consistent before further processing or export.
worksheet.getPageSetup().setPrintArea("B2:N40");
worksheet.getRange("B2:N40").setValue(10);
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(worksheet);
PageInfo page = pages.remove(0);
pages.add(page);
printManager.updatePageNumberAndPageSettings(pages);
pages - The page collection to update. Typically this is a list returned by paginate(IWorksheet) after the collection has been changed.Call this method after the page collection changes, such as when pages are added, deleted, or moved. This overload updates the specified pages by using the provided first page number and total page count.
worksheet.getPageSetup().setPrintArea("B2:N40");
worksheet.getRange("B2:N40").setValue(10);
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(worksheet);
printManager.updatePageNumberAndPageSettings(pages, 5, 12);
pages - The page collection to update.firstPageNumber - The page number to assign to the first page in pages.pageCount - The total number of pages to apply to the page information.This method adds a new page to doc using the paper size from pageInfo, and then draws the page content onto the appended PDF page.
This overload forwards null to appendPage(PDDocument,PageInfo,PdfSaveOptions).
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", 200},
{"C", 300}
});
PrintManager printManager = new PrintManager();
PageInfo page = printManager.paginate(worksheet).get(0);
try (PDDocument doc = new PDDocument()) {
printManager.appendPage(doc, page);
} catch (IOException e) {
}
doc - The PDF document that receives the appended page. Must not be null.pageInfo - The printed page information to append. Must not be null.This method creates a new PDF page in doc by using the paper size defined by pageInfo, and then draws the page content onto the appended page. Use paginate(IWorksheet) to generate the PageInfo instance before calling this method.
The options argument controls PDF rendering behavior. Pass null if no PdfSaveOptions are needed.
worksheet.getRange("A1:B3").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", 200}
});
PrintManager printManager = new PrintManager();
PageInfo pageInfo = printManager.paginate(worksheet).get(0);
PdfSaveOptions options = new PdfSaveOptions();
try (PDDocument doc = new PDDocument()) {
printManager.appendPage(doc, pageInfo, options);
} catch (IOException e) {
}
doc - The PDF document that receives the appended page. Must not be null.pageInfo - The printed page information to append. Must not be null.options - The PDF save options applied when drawing the page content; may be null.This method divides the target PDF page into a grid defined by rows and columns, then draws the specified PageInfo objects into that layout. This overload forwards to draw(PDDocument,PDPage,List,int,int,Order) with Order.OverThenDown.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", 200},
{"C", 300}
});
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(worksheet);
try (PDDocument doc = new PDDocument()) {
PDPage page = new PDPage();
doc.addPage(page);
printManager.draw(doc, page, pages, 1, 1);
} catch (IOException e) {
}
doc - The PDF document that receives the drawn content. Must not be null.page - The target PDF page. Must not be null.pages - The page collection to draw. Must not be null.rows - The number of rows used to divide the target page layout. Must be greater than 0.columns - The number of columns used to divide the target page layout. Must be greater than 0.This overload forwards to draw(PDDocument,PDPage,List,int,int,Order,PdfSaveOptions) with null options.
worksheet.getRange("A1:B3").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", 200}
});
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(worksheet);
try (PDDocument doc = new PDDocument()) {
PDPage page = new PDPage();
doc.addPage(page);
printManager.draw(doc, page, pages, 1, 1, Order.OverThenDown);
} catch (Exception e) {
}
doc - The PDF document that receives the drawn content. Must not be null.page - The target PDF page. Must not be null.pages - The page collection to draw. Must not be null.rows - The number of rows used to divide the page layout. Must be greater than 0.columns - The number of columns used to divide the page layout. Must be greater than 0.order - The direction used to arrange the pages. Must not be null.This method divides the target PDF page into a grid defined by rows and columns, then draws each PageInfo into one grid cell. The order parameter controls whether the pages are arranged across columns first or down rows first.
worksheet.getRange("A1:C6").setValue(new Object[][] {
{"Name", "Q1", "Q2"},
{"North", 100, 120},
{"South", 90, 110}
});
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(worksheet);
PdfSaveOptions options = new PdfSaveOptions();
try (PDDocument doc = new PDDocument()) {
PDPage page = new PDPage();
doc.addPage(page);
printManager.draw(doc, page, pages, 1, 1, Order.OverThenDown, options);
} catch (Exception e) {
}
doc - The PDF document that receives the drawn content. Must not be null.page - The target PDF page. Must not be null.pages - The page collection to draw. Must not be null.rows - The number of rows used to divide the target page layout.columns - The number of columns used to divide the target page layout.order - The direction used to arrange the pages in the grid. Must not be null.options - The PDF save options applied when drawing the page content; can be null.
worksheet.getPageSetup().setPrintArea("B2:D6");
worksheet.getRange("B2:D6").setValue("Test");
PrintManager printManager = new PrintManager();
boolean hasContent = printManager.hasPrintContent(worksheet.getRange("B2:D6"));
range - The printed range of a page. Must not be null.true if the specified range contains printable content; otherwise, false.NullPointerException - if range is null.
worksheet.getPageSetup().setPrintArea("A1:B4");
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", 200},
{"C", 300}
});
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(worksheet);
PageContentInfo contentInfo = pages.get(0).getPageContent();
Size contentSize = printManager.getSize(contentInfo);
contentInfo - The PageContentInfo object.
worksheet.getRange("B2:D6").setValue("Test");
IRange printArea = worksheet.getRange("B2:D6");
PrintManager printManager = new PrintManager();
Size rangeSize = printManager.getSize(printArea);
range - The range object.The pagination result is calculated for the provided printArea by using the worksheet's current page setup. Each returned PageInfo represents one generated page in page order, and its page number, page count, and page settings are updated before the list is returned.
IRange printArea = worksheet.getRange("B2:D20");
printArea.setValue("Test");
PrintManager printManager = new PrintManager();
List<PageInfo> pages = printManager.paginate(printArea);
printArea - The range to paginate. Must not be null.PageInfo objects that describe the generated pages for the specified range in page order. Returns an empty list if no printable pages are generated.This method measures the rendered size of range by calling getSize(IRange) and then forwards to draw(PDDocument,PDPage,Rectangle,IRange) with a Rectangle whose origin is location and whose width and height match the measured range size.
worksheet.getRange("A1:B2").setValue(new Object[][] {
{"Name", "Value"},
{"Test", 100}
});
IRange range = worksheet.getRange("A1:B2");
PrintManager printManager = new PrintManager();
try (PDDocument doc = new PDDocument()) {
PDPage page = new PDPage();
doc.addPage(page);
printManager.draw(doc, page, new Point(36, 72), range);
} catch (Exception e) {
}
doc - The PDF document that receives the rendered range.page - The PDF page on which to draw the range.location - The upper-left location, in page coordinates, where the range is drawn.range - The worksheet range to render.This overload measures range, creates a rectangle whose origin is location and whose size matches the range, and then forwards to draw(PDDocument,PDPage,Rectangle,IRange,PdfSaveOptions).
worksheet.getRange("A1:B2").setValue(new Object[][] {
{"Name", "Value"},
{"Test", 100}
});
IRange range = worksheet.getRange("A1:B2");
PrintManager printManager = new PrintManager();
PdfSaveOptions options = new PdfSaveOptions();
try (PDDocument doc = new PDDocument()) {
PDPage page = new PDPage();
doc.addPage(page);
printManager.draw(doc, page, new Point(36, 72), range, options);
} catch (Exception e) {
}
doc - The PDF document that receives the rendered range.page - The PDF page on which to draw the range.location - The top-left location, in page coordinates, where the range is drawn.range - The worksheet range to render.options - The PDF rendering options. May be null.This method renders the cells in range on page within rect. It forwards to draw(PDDocument,PDPage,Rectangle,IRange,PdfSaveOptions) with null for options.
worksheet.getRange("A1:B2").setValue(new Object[][] {
{"Name", "Value"},
{"Test", 100}
});
IRange range = worksheet.getRange("A1:B2");
PrintManager printManager = new PrintManager();
try (PDDocument doc = new PDDocument()) {
PDPage page = new PDPage();
doc.addPage(page);
printManager.draw(doc, page, new Rectangle(36, 72, 220, 90), range);
} catch (Exception e) {
}
doc - The PDF document that receives the rendered range.page - The PDF page on which to draw the range.rect - The target rectangle, in page coordinates, that defines where the range is drawn.range - The worksheet range to render.This method renders the cells in range by using the worksheet's page settings and writes the output to page within rect. If options is not null, its PDF document properties and security settings are also applied to doc before the range is drawn.
worksheet.getRange("A1:B2").setValue(new Object[][] {
{"Name", "Value"},
{"Test", 100}
});
IRange range = worksheet.getRange("A1:B2");
PrintManager printManager = new PrintManager();
PdfSaveOptions options = new PdfSaveOptions();
try (PDDocument doc = new PDDocument()) {
PDPage page = new PDPage();
doc.addPage(page);
Rectangle rect = new Rectangle(36, 72, 220, 90);
printManager.draw(doc, page, rect, range, options);
} catch (Exception e) {
}
doc - The PDF document that receives the rendered range. If options contains document properties or security settings, they are applied to this document.page - The PDF page on which to draw the range.rect - The target rectangle, in page coordinates, that defines where the range is drawn.range - The worksheet range to render.options - The PDF rendering options. May be null.Use this method to render a PageContentInfo object, such as one obtained from paginate(IWorksheet), into the target area defined by rect on page. This overload forwards null for options to draw(PDDocument,PDPage,Rectangle,PageContentInfo,PdfSaveOptions).
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", 200},
{"C", 300}
});
PrintManager printManager = new PrintManager();
PageContentInfo pageContent = printManager.paginate(worksheet).get(0).getPageContent();
try (PDDocument doc = new PDDocument()) {
PDPage page = new PDPage(new PDRectangle(400, 600));
doc.addPage(page);
printManager.draw(doc, page, new Rectangle(36, 36, 328, 528), pageContent);
} catch (IOException e) {
}
doc - The PDF document that contains page. Must not be null.page - The PDF page on which the printed content is drawn. Must not be null.rect - The target location and size, in PDF page coordinates, used to draw the printed content. Must not be null.pageContent - The printed page content information to render. Must not be null and must contain a range.This method creates a PageInfo from pageContent, uses the worksheet's odd-page settings, sets the paper size to the size of pageContent, clears all page margins, and then draws the result into rect on page.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", 200},
{"C", 300}
});
PrintManager printManager = new PrintManager();
PageContentInfo pageContent = printManager.paginate(worksheet).get(0).getPageContent();
try (PDDocument doc = new PDDocument()) {
PDPage page = new PDPage(new PDRectangle(400, 600));
doc.addPage(page);
printManager.draw(doc, page, new Rectangle(36, 36, 328, 528), pageContent, new PdfSaveOptions());
} catch (IOException e) {
}
doc - The PDF document that contains page. Must not be null.page - The PDF page on which the printed content is drawn. Must not be null.rect - The target location and size, in PDF page coordinates, used to draw the printed content. Must not be null.pageContent - The printed page content information to render. Must not be null and must contain a range.options - The PDF save options applied during drawing. Can be null.This overload forwards to draw(PDDocument,PDPage,Rectangle,PageInfo,PdfSaveOptions) with null for options.
worksheet.getPageSetup().setPrintArea("A1:B4");
worksheet.getRange("A1:B4").setValue(new Object[][] {{"Name", "Value"}, {"Test", 100}, {"Hello", 200}, {"Total", 300}});
PrintManager printManager = new PrintManager();
PageInfo pageInfo = printManager.paginate(worksheet).get(0);
Rectangle rect = new Rectangle(36, 36, 400, 300);
try (PDDocument doc = new PDDocument()) {
PDPage page = new PDPage();
doc.addPage(page);
printManager.draw(doc, page, rect, pageInfo);
} catch (IOException e) {
}
doc - The PDF document that contains the target page.page - The page in the PDF document.rect - The location and size of the area where the page information is drawn.pageInfo - The printed page information to draw.This method renders the content represented by pageInfo into rect on page. The page content stream is opened in append mode, so the drawn output is added to the existing PDF page content. The pageInfo object is typically obtained from paginate(IWorksheet).
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Name", "Value"},
{"A", 100},
{"B", 200},
{"C", 300}
});
PrintManager printManager = new PrintManager();
PageInfo pageInfo = printManager.paginate(worksheet).get(0);
try (PDDocument doc = new PDDocument()) {
PDPage page = new PDPage(new PDRectangle(400, 600));
doc.addPage(page);
printManager.draw(doc, page, new Rectangle(36, 36, 328, 528), pageInfo, new PdfSaveOptions());
} catch (IOException e) {
}
doc - The PDF document that contains page. Must not be null.page - The PDF page on which the printed content is drawn. Must not be null.rect - The target location and size, in PDF page coordinates, used to draw the printed content. Must not be null.pageInfo - The printed page information to render. Must not be null.options - The PDF save options applied during drawing. Can be null.
worksheet.getPageSetup().setPrintArea("B2:D6");
worksheet.getRange("B2:D6").setValue("Test");
PrintManager printManager = new PrintManager();
List<IRange> printAreas = printManager.getPrintAreas(worksheet);
String address = printAreas.get(0).getAddress();
worksheet - The worksheet object.The pagination is based on the current IPageSetup settings of the worksheet. Call this method separately for horizontal and vertical pagination. If no print area is defined, pagination is determined from cell A1 to the last cell that contains data.
worksheet.getPageSetup().setPrintArea("B2:N40");
worksheet.getRange("B2:N40").setValue(10);
PrintManager printManager = new PrintManager();
List<Integer> columnPageBoundaries =
printManager.GetPaginationInfo(worksheet, PaginationOrientation.Horizontal);
worksheet - The worksheet whose pagination information is retrieved. Must not be null.orientation - The pagination direction that determines whether row or column boundary indexes are returned.The pagination result is calculated from the current page setup of the worksheet and the specified orientation. Use keepTogetherRanges to prevent specific ranges from being split across pages, and use repeatSettings to repeat title or tail rows or columns for a range during pagination.
If the worksheet has no print area, this method returns null.
worksheet.getPageSetup().setPrintArea("A1:D80");
worksheet.getRange("A1:D80").setValue(100);
List<IRange> keepTogetherRanges = new ArrayList<>();
keepTogetherRanges.add(worksheet.getRange("A20:D25"));
RepeatSetting repeatSetting = new RepeatSetting();
repeatSetting.setRange(worksheet.getRange("A1:D80"));
repeatSetting.setTitleRowStart(0);
repeatSetting.setTitleRowEnd(0);
List<RepeatSetting> repeatSettings = new ArrayList<>();
repeatSettings.add(repeatSetting);
PrintManager printManager = new PrintManager();
List<Integer> pageBoundaries = printManager.GetPaginationInfo(
worksheet, PaginationOrientation.Vertical, keepTogetherRanges, repeatSettings);
worksheet - The worksheet whose pagination information is retrieved. Must not be null.orientation - The pagination direction that determines whether row or column boundary indexes are returned.keepTogetherRanges - The ranges that should remain on the same page. Can be null or empty if no keep-together ranges are needed.repeatSettings - The repeat settings applied during pagination. Can be null or empty if no repeating rows or columns are needed.null if the worksheet has no print area.IllegalStateException - if the keep-together or repeat settings cannot fit within the printable page area.