react-native-print icon indicating copy to clipboard operation
react-native-print copied to clipboard

Is there any way to set paper size as IS0 5 default

Open Venkat1P opened this issue 3 years ago • 6 comments

Any support for setting a default paper size before print.

Venkat1P avatar Feb 05 '22 20:02 Venkat1P

Hi @christopherdro do you have any suggestions for passing paper size as option. Please suggest this is getting critical for my project..

Venkat1P avatar Feb 14 '22 08:02 Venkat1P

i research it for long, but still don't find solution. I want to print for label size.(IOS)

Chhinvanchhai avatar Mar 12 '22 02:03 Chhinvanchhai

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'
});

reendev avatar Jun 01 '22 08:06 reendev

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.

hotaryuzaki avatar Sep 01 '22 07:09 hotaryuzaki

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.

stale[bot] avatar Dec 30 '22 22:12 stale[bot]

This issue shouldn't be closed

iskandarzhilmi avatar Feb 16 '24 07:02 iskandarzhilmi