Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,19 @@ public TFinalClass useExternalResourceAccessControl(
return (TFinalClass) this;
}

/**
* Allows the setting of the initial page number to use with the
* <code>page</code> and <code>pages</code> CSS counters.
* Useful when appending to an existing document.
* Must be one or greater.
*
* @return this for method chaining.
*/
public TFinalClass useInitialPageNumber(int initialPageNumber) {
state._initialPageNumber = initialPageNumber;
return (TFinalClass) this;
}

public enum TextDirection {
RTL, LTR
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<html>
<head>
<style>
@page {
size: 300px 150px;
margin: 25px;

@top-center {
content: counter(page) " of " counter(pages);
}
@bottom-center {
content: element(ftr);
}
}
.footer::before {
content: "Footer on page " counter(page) " of " counter(pages);
}
body {
margin: 0;
}
</style>
</head>
<body>
<div class="footer" style="position: running(ftr);"></div>

<h2 style="margin-top: 0;">Page five</h2>
<h2 style="margin-top: 0; page-break-before: always;">Page six</h2>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,16 @@ public void testIssue649MultipleBgImagesPageBox() throws IOException {
assertTrue(vt.runTest("issue-649-multiple-bg-images-page-box"));
}

/**
* Tests setting an initial page number with CSS page and pages counters.
*/
@Test
public void testPr727InitialPageNumber() throws IOException {
assertTrue(vt.runTest("pr-727-initial-page-number", builder -> {
builder.useInitialPageNumber(5);
}));
}

// TODO:
// + Elements that appear just on generated overflow pages.
// + content property (page counters, etc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ public Java2DRendererBuilder useLayoutGraphics(Graphics2D g2d) {
return this;
}

/**
* Used to set an initial page number for use with page counters, etc.
*
* @param pageNumberInitial
* @return this for method chaining
*/
public Java2DRendererBuilder useInitialPageNumber(int pageNumberInitial) {
state._initialPageNumber = pageNumberInitial;
return this;
}

/**
* Whether to use fonts available in the environment. Enabling environment fonts may mean different text
* rendering behavior across different environments. The default is not to use environment fonts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ public class PdfBoxRenderer implements Closeable, PageSupplier {
private PageSupplier _pageSupplier;

private final Closeable diagnosticConsumer;


private final int _initialPageNumber;

/**
* This method is constantly changing as options are added to the builder.
*/
Expand Down Expand Up @@ -269,6 +271,8 @@ else if (doc.file != null) {
}

this._os = state._os;

this._initialPageNumber = state._initialPageNumber;
}

public Document getDocument() {
Expand Down Expand Up @@ -477,7 +481,7 @@ public void createPDF(OutputStream os, boolean finish) throws IOException {
@Deprecated
public void createPDF(OutputStream os, boolean finish, int initialPageNo) throws IOException {
if (_useFastMode) {
createPdfFast(finish);
createPdfFast(finish, initialPageNo);
return;
}

Expand All @@ -493,7 +497,7 @@ public void createPDF(OutputStream os, boolean finish, int initialPageNo) throws

RenderingContext c = newRenderingContext();
c.setInitialPageNo(initialPageNo);

PageBox firstPage = pages.get(0);
Rectangle2D firstPageSize = new Rectangle2D.Float(0, 0,
firstPage.getWidth(c) / _dotsPerPoint,
Expand Down Expand Up @@ -523,7 +527,7 @@ public void createPDF(OutputStream os, boolean finish, int initialPageNo) throws
/**
* Go fast!
*/
private void createPdfFast(boolean finish) throws IOException {
private void createPdfFast(boolean finish, int initialPageNo) throws IOException {
boolean success = false;

XRLog.log(Level.INFO, LogMessageId.LogMessageId0Param.GENERAL_PDF_USING_FAST_MODE);
Expand All @@ -537,7 +541,7 @@ private void createPdfFast(boolean finish) throws IOException {
List<PageBox> pages = _root.getLayer().getPages();

RenderingContext c = newRenderingContext();
c.setInitialPageNo(0);
c.setInitialPageNo(initialPageNo != 0 ? initialPageNo : _initialPageNumber);
c.setFastRenderer(true);

PageBox firstPage = pages.get(0);
Expand Down Expand Up @@ -596,6 +600,7 @@ private void writePDFFast(List<PageBox> pages, RenderingContext c, Rectangle2D f

int pageCount = _root.getLayer().getPages().size();
c.setPageCount(pageCount);

firePreWrite(pageCount); // opportunity to adjust meta data
setDidValues(doc); // set PDF header fields from meta data

Expand Down