react-native-print
react-native-print copied to clipboard
Is there any way to set paper size as IS0 5 default
Any support for setting a default paper size before print.
Hi @christopherdro do you have any suggestions for passing paper size as option. Please suggest this is getting critical for my project..
i research it for long, but still don't find solution. I want to print for label size.(IOS)
Modify android/src/java/com/christopherdro/RNPrint/PNPrintModule.java
@ReactMethod
public void print(final ReadableMap options, final Promise promise) {
...
final String paperSize = options.hasKey("paperSize") ? options.getString("paperSize") : null;
...
@Override
public void onPageFinished(WebView view, String url) {
....
// Pass in the ViewView's document adapter.
PrintAttributes.MediaSize mediaSize;
if (paperSize != null) {
switch(paperSize) {
case "receipt": mediaSize = PrintAttributes.MediaSize.ISO_A7;break;
default: mediaSize = isLandscape?PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE:
PrintAttributes.MediaSize.UNKNOWN_PORTRAIT;
}
}
else {
mediaSize = isLandscape?PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE:
PrintAttributes.MediaSize.UNKNOWN_PORTRAIT;
}
PrintAttributes printAttributes = new PrintAttributes.Builder()
.setMediaSize(mediaSize)
.build();
printManager.print(jobName, adapter, printAttributes);
...
}
}
Usage in react native
RNPrint.print({
html:html,
paperSize:'receipt'
});
Modify android/src/java/com/christopherdro/RNPrint/PNPrintModule.java
@ReactMethod public void print(final ReadableMap options, final Promise promise) { ... final String paperSize = options.hasKey("paperSize") ? options.getString("paperSize") : null; ... @Override public void onPageFinished(WebView view, String url) { .... // Pass in the ViewView's document adapter. PrintAttributes.MediaSize mediaSize; if (paperSize != null) { switch(paperSize) { case "receipt": mediaSize = PrintAttributes.MediaSize.ISO_A7;break; default: mediaSize = isLandscape?PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE: PrintAttributes.MediaSize.UNKNOWN_PORTRAIT; } } else { mediaSize = isLandscape?PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE: PrintAttributes.MediaSize.UNKNOWN_PORTRAIT; } PrintAttributes printAttributes = new PrintAttributes.Builder() .setMediaSize(mediaSize) .build(); printManager.print(jobName, adapter, printAttributes); ... } }
Usage in react native
RNPrint.print({ html:html, paperSize:'receipt' });
i think you should make a pull request, so everyone can use this. it is an important feature.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue shouldn't be closed