diff --git a/src/android/PrintAdapter.java b/src/android/PrintAdapter.java index 3e82e69..187f1ff 100644 --- a/src/android/PrintAdapter.java +++ b/src/android/PrintAdapter.java @@ -46,6 +46,9 @@ class PrintAdapter extends PrintDocumentAdapter { // The name of the print job private final @NonNull String jobName; + // Max page count + private final int pageCount; + // The input stream to render private final @NonNull InputStream input; @@ -55,16 +58,19 @@ class PrintAdapter extends PrintDocumentAdapter { /** * Constructor * - * @param jobName The name of the print job. - * @param input The input stream to render. - * @param callback The callback to inform once the job is done. + * @param jobName The name of the print job. + * @param pageCount The max page count. + * @param input The input stream to render. + * @param callback The callback to inform once the job is done. */ - PrintAdapter (@NonNull String jobName, @NonNull InputStream input, + PrintAdapter (@NonNull String jobName, int pageCount, + @NonNull InputStream input, @NonNull PrintHelper.OnPrintFinishCallback callback) { - this.jobName = jobName; - this.input = input; - this.callback = callback; + this.jobName = jobName; + this.pageCount = pageCount; + this.input = input; + this.callback = callback; } @Override @@ -81,6 +87,7 @@ class PrintAdapter extends PrintDocumentAdapter { pdi = new PrintDocumentInfo.Builder(jobName) .setContentType(CONTENT_TYPE_DOCUMENT) + .setPageCount(pageCount) .build(); boolean changed = !newAttributes.equals(oldAttributes); diff --git a/src/android/PrintManager.java b/src/android/PrintManager.java index 7416f53..4e090a2 100644 --- a/src/android/PrintManager.java +++ b/src/android/PrintManager.java @@ -245,7 +245,8 @@ class PrintManager { PrintOptions options = new PrintOptions(settings); String jobName = options.getJobName(); - PrintAdapter adapter = new PrintAdapter(jobName, stream, () -> callback.onFinish(isPrintJobCompleted(jobName))); + Integer pageCount = options.getPageCount(); + PrintAdapter adapter = new PrintAdapter(jobName, pageCount, stream, () -> callback.onFinish(isPrintJobCompleted(jobName))); printAdapter(adapter, options); } diff --git a/src/android/PrintOptions.java b/src/android/PrintOptions.java index fe759fb..e34b26f 100644 --- a/src/android/PrintOptions.java +++ b/src/android/PrintOptions.java @@ -34,6 +34,7 @@ import static android.print.PrintAttributes.DUPLEX_MODE_SHORT_EDGE; import static android.print.PrintAttributes.Margins.NO_MARGINS; import static android.print.PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE; import static android.print.PrintAttributes.MediaSize.UNKNOWN_PORTRAIT; +import static android.print.PrintDocumentInfo.PAGE_COUNT_UNKNOWN; import static android.support.v4.print.PrintHelper.ORIENTATION_LANDSCAPE; import static android.support.v4.print.PrintHelper.ORIENTATION_PORTRAIT; import static android.support.v4.print.PrintHelper.SCALE_MODE_FILL; @@ -72,6 +73,16 @@ class PrintOptions { return jobName; } + /** + * Returns the max page count. + */ + int getPageCount() + { + int count = spec.optInt("pageCount", PAGE_COUNT_UNKNOWN); + + return count <= 0 ? PAGE_COUNT_UNKNOWN : count; + } + /** * Converts the options into a PrintAttributes object. */ diff --git a/src/ios/APPPrinterRenderer.m b/src/ios/APPPrinterRenderer.m index 8310154..7a1b2ee 100644 --- a/src/ios/APPPrinterRenderer.m +++ b/src/ios/APPPrinterRenderer.m @@ -65,7 +65,7 @@ - (NSInteger) numberOfPages { NSInteger num = [super numberOfPages]; - id maxPages = _settings[@"maxPages"]; + id maxPages = _settings[@"pageCount"]; if (maxPages < 0) { diff --git a/www/printer.js b/www/printer.js index eff352e..92c4e8b 100755 --- a/www/printer.js +++ b/www/printer.js @@ -32,7 +32,7 @@ exports._defaults = { // monochrome: false, // copies: 1, - // maxPages: 10, + // pageCount: 1, // border: true, // maxHeight: '10cm',