Comments (3)
Im trying:
await RNPrint.print({
html: `<img src=${imageUrl} style="width:400px;height:600px;">`
});
i already tried diferents width/height but image always have big margins
from react-native-print.
I did this in RNPrintModule.java and it seems that works with image urls:
package com.christopherdro.RNPrint;
import android.content.Context;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.ParcelFileDescriptor;
import android.print.PageRange;
import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter;
import android.print.PrintDocumentInfo;
import android.print.PrintManager;
import android.webkit.URLUtil;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.UiThreadUtil;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import android.support.v4.print.PrintHelper;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import java.net.HttpURLConnection;
/**
* NativeModule that allows JS to open emails sending apps chooser.
*/
public class RNPrintModule extends ReactContextBaseJavaModule {
ReactApplicationContext reactContext;
final String jobName = "Document";
public RNPrintModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}
@Override
public String getName() {
return "RNPrint";
}
WebView mWebView;
@ReactMethod
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;
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");
return;
}
try {
PrintHelper photoPrinter = new PrintHelper(getCurrentActivity());
photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT);
Bitmap bitmap = getBitmapFromURL(filePath);
photoPrinter.printBitmap("samsung note 9", bitmap);
promise.resolve(jobName);
} catch (Exception e) {
promise.reject(getName(), e);
}
}
private static Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
// Log exception
return null;
}
}
}
from react-native-print.
For print local images only need update Bitmap with path like this:
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.droids);
https://developer.android.com/training/printing/photos
from react-native-print.
Related Issues (20)
- App crash when silent print on iOS 16 HOT 4
- How to print Local Pdf, doc file from Gallery HOT 2
- Print gets blurry when I am trying print receipt on bluetooth printer HOT 1
- Android packaging error HOT 5
- Silent print support in react-native-windows HOT 2
- build error for android HOT 2
- react-native-print working properly on debug build but getting error at ./gradlew assembleRelease and getting following error...this error is only with this package only..please help HOT 1
- Print webview screen HOT 1
- make silent printing optional for ios HOT 1
- Bluetooth and Wifi support for Brother Printer HOT 3
- Android pagination issue HOT 1
- working around rdar://FB11966380 (iOS 16 blank page issue with label printers) HOT 1
- Type improvements HOT 1
- Windows HTML Print HOT 1
- Print gets printer name blurry when I am trying print on USB printer HOT 3
- Pdf not fit properly in Print preview, make blank space either right and bottom. HOT 2
- Customize print screen
- Automatically click the print button
- PDF print attempt causes crash on iOS17+ HOT 2
- Showing black background into receipt
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-print.