Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add print orientation in print options #29

Merged
merged 4 commits into from
Mar 24, 2018
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ const styles = StyleSheet.create({
| `html` | `string` | HTML string to print
| `fileName` | `string` | Custom Filename excluding .pdf extension or remote file url NOTE: iOS only supports https protocols
| `printerURL` | `string` | **iOS Only:** URL returned from `selectPrinterMethod()`
| `isLandscape` | `bool` | Landscape print; defalut value is false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: default



## selectPrinter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void print(final ReadableMap options, final Promise promise) {

final String html = options.hasKey("html") ? options.getString("html") : null;
final String filePath = options.hasKey("filePath") ? options.getString("filePath") : null;
final boolean isLandscape = options.hasKey("isLandscape")?options.getBoolean("isLandscape"):false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space between operators.


if ((html == null && filePath == null) || (html != null && filePath != null)) {
promise.reject(getName(), "Must provide either `html` or `filePath`. Both are either missing or passed together");
Expand Down Expand Up @@ -169,7 +170,10 @@ public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttribute
}
};

printManager.print(jobName, pda, null);
PrintAttributes printAttributes = new PrintAttributes.Builder()
.setMediaSize(isLandscape?PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE:PrintAttributes.MediaSize.UNKNOWN_PORTRAIT)
.build();
printManager.print(jobName, pda, printAttributes);
promise.resolve(jobName);

} catch (Exception e) {
Expand Down
1 change: 1 addition & 0 deletions ios/RNPrint/RNPrint.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
@property NSString *filePath;
@property NSString *htmlString;
@property NSURL *printerURL;
@property (nonatomic, assign) BOOL isLandscape;
@end
5 changes: 5 additions & 0 deletions ios/RNPrint/RNPrint.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ - (dispatch_queue_t)methodQueue
_pickedPrinter = [UIPrinter printerWithURL:_printerURL];
}

if(options[@"isLandscape"]) {
_isLandscape = [[RCTConvert NSNumber:options[@"isLandscape"]] boolValue];
}

if ((_filePath && _htmlString) || (_filePath == nil && _htmlString == nil)) {
reject(RCTErrorUnspecified, nil, RCTErrorWithMessage(@"Must provide either `html` or `filePath`. Both are either missing or passed together"));
}
Expand All @@ -57,6 +61,7 @@ - (dispatch_queue_t)methodQueue
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [_filePath lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
printInfo.orientation = _isLandscape? UIPrintInfoOrientationLandscape: UIPrintInfoOrientationPortrait;

printInteractionController.printInfo = printInfo;
printInteractionController.showsPageRange = YES;
Expand Down