Skip to content

Commit deeee13

Browse files
committed
allows for PDF jobs to not use Pageable and instead continue until a
NO_SUCH_PAGE is delivered by printable.print(...)
1 parent c38ecc3 commit deeee13

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed
1.78 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/gnu/jpdf/PDFPrinterJob.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ public PageFormat pageDialog(PageFormat page) throws HeadlessException {
125125
* Prints a set of pages.
126126
*
127127
* @param pathname
128-
* the full path for the output PDF file.
128+
* the full path for the output PDF file.
129129
* @exception PrinterException
130-
* an error in the print system caused the job to be aborted.
130+
* an error in the print system caused the job to be aborted.
131131
* @see Book
132132
* @see Pageable
133133
* @see Printable
@@ -145,28 +145,32 @@ public void print(String pathname) throws PrinterException {
145145
}
146146

147147
System.out.println("GNU JPDF creating " + file);
148-
148+
149149
PDFGraphics pdfGraphics = null;
150150
printJob = new PDFJob(fileOutputStream);
151151

152152
if (info != null) {
153153
printJob.getPDFDocument().setPDFInfo(info);
154154
}
155155

156-
pageCount = (pageable == null ? 1 : pageable.getNumberOfPages());
157-
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
156+
// BH 2018 allows for unknown number of pages and a return of NO_SUCH_PAGE from the
157+
// project to stop sending pages.
158+
pageCount = (pageable == null ? Pageable.UNKNOWN_NUMBER_OF_PAGES : pageable.getNumberOfPages());
159+
160+
for (int pageIndex = 0; pageCount < 0 || pageIndex < pageCount; pageIndex++) {
158161
if (pageable != null)
159162
pageFormat = pageable.getPageFormat(pageIndex);
160163
if (pageFormat == null)
161164
pageFormat = defaultPage();
162165
pdfGraphics = (PDFGraphics) printJob.getGraphics(pageFormat);
163166
if (pageable != null)
164167
printable = pageable.getPrintable(pageIndex);
165-
printable.print(pdfGraphics, pageFormat, pageIndex);
168+
if (printable.print(pdfGraphics, pageFormat, pageIndex) == Printable.NO_SUCH_PAGE)
169+
pageCount = 0;
166170
pdfGraphics.dispose();
167171
}
168172
printJob.end();
169-
173+
170174
System.out.println("GNU JPDF created: " + file);
171175

172176
}

0 commit comments

Comments
 (0)