Showing
2 changed files
with
11 additions
and
3 deletions
| @@ -28,11 +28,13 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler { | @@ -28,11 +28,13 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler { | ||
| 28 | switch (call.method) { | 28 | switch (call.method) { |
| 29 | case "printPdf": { | 29 | case "printPdf": { |
| 30 | final String name = call.argument("name"); | 30 | final String name = call.argument("name"); |
| 31 | + Double width = call.argument("width"); | ||
| 32 | + Double height = call.argument("height"); | ||
| 31 | 33 | ||
| 32 | final PrintingJob printJob = | 34 | final PrintingJob printJob = |
| 33 | new PrintingJob(activity, this, (int) call.argument("job")); | 35 | new PrintingJob(activity, this, (int) call.argument("job")); |
| 34 | assert name != null; | 36 | assert name != null; |
| 35 | - printJob.printPdf(name); | 37 | + printJob.printPdf(name, width, height); |
| 36 | 38 | ||
| 37 | result.success(1); | 39 | result.success(1); |
| 38 | break; | 40 | break; |
| @@ -190,9 +190,15 @@ public class PrintingJob extends PrintDocumentAdapter { | @@ -190,9 +190,15 @@ public class PrintingJob extends PrintDocumentAdapter { | ||
| 190 | thread.start(); | 190 | thread.start(); |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | - void printPdf(@NonNull String name) { | 193 | + void printPdf(@NonNull String name, @NonNull Double width, @NonNull Double height) { |
| 194 | jobName = name; | 194 | jobName = name; |
| 195 | - printJob = printManager.print(name, this, null); | 195 | + |
| 196 | + PrintAttributes.Builder attrBuilder = new PrintAttributes.Builder(); | ||
| 197 | + if (width > height) { | ||
| 198 | + attrBuilder.setMediaSize(PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE); | ||
| 199 | + } | ||
| 200 | + PrintAttributes attrib = attrBuilder.build(); | ||
| 201 | + printJob = printManager.print(name, this, attrib); | ||
| 196 | } | 202 | } |
| 197 | 203 | ||
| 198 | void cancelJob(String message) { | 204 | void cancelJob(String message) { |
-
Please register or login to post a comment