Closed sahil6111 closed 5 years ago
Now, i have changed my function to print directly without connecting because the printer is already paired & connected to iPad.
export async function directPrint(prnt, imageUrl) {
console.log("started===================>");
try {
console.log("select printerprnt", prnt);
await print(
EmulationPrinter,
prnt.portName,
getCommands(imageUrl));
} catch (e) {
console.log(e);
}
}
After this change, a small stub of receipt will feed through the printer, as if to print something but nothing prints. I am trying to print image uri which is captured by 'react-native-view-shot'. @infoxicator @CHOMNANP Need help or any guidance that can help to print. Thanks!
You may wish to check the get status documentation which states:
Checking status of a printer while connected
to that printer can produce unexpected results.
With some basic code I can connect and print. Also note that I believe for both of your cases you will need to pair the printer with the iPad.
It appears that the iOS native module does not support parsing a URI with a file scheme which is why you're experiencing nothing being printed as the image data cannot be resolved.
NSURL *imageURL = [NSURL URLWithString:urlString]; NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; UIImage *image = [UIImage imageWithData:imageData];
https://github.com/infoxicator/react-native-star-prnt/blob/master/ios/RNStarPrnt.m#L537
I think fileURLWithPath will have to be used in order to parse a file based URL.
I've created a PR here attempting to fix this: https://github.com/infoxicator/react-native-star-prnt/pull/31
@sahil6111 , can you try running this on your device? https://gitlab.com/CHOMNANP/react-native-star-print-example/tree/print
I think can follow the example here if it work.
If I'm not wrong, we convert image to based64 and paste the base64 format for IOS.
I changed the logic, didn't use the imageUrl, instead i used the append text.
Printer is discovered using above getPrinters function. But when i try to connect and print it always show printer not connected. Any help is appreciated. Thanks.