Skip to content

Commit 7028f6e

Browse files
SimonErmchristopherdro
authored andcommitted
add optional baseURL (#77)
1 parent 05f0227 commit 7028f6e

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

android/src/main/java/android/print/PdfConverter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class PdfConverter implements Runnable {
4141
private boolean mShouldEncode;
4242
private WritableMap mResultMap;
4343
private Promise mPromise;
44+
private String mBaseURL;
4445

4546
private PdfConverter() {
4647
}
@@ -85,7 +86,7 @@ public void onWriteFinished(PageRange[] pages) {
8586
}
8687
}
8788
});
88-
mWebView.loadData(mHtmlString, "text/HTML", "UTF-8");
89+
mWebView.loadDataWithBaseURL(mBaseURL, mHtmlString, "text/HTML", "UTF-8", null);
8990
}
9091

9192
public PrintAttributes getPdfPrintAttrs() {
@@ -96,7 +97,8 @@ public void setPdfPrintAttrs(PrintAttributes printAttrs) {
9697
this.mPdfPrintAttrs = printAttrs;
9798
}
9899

99-
public void convert(Context context, String htmlString, File file, boolean shouldEncode, WritableMap resultMap, Promise promise) {
100+
public void convert(Context context, String htmlString, File file, boolean shouldEncode, WritableMap resultMap,
101+
Promise promise, String baseURL) {
100102
if (context == null)
101103
throw new IllegalArgumentException("context can't be null");
102104
if (htmlString == null)
@@ -114,6 +116,7 @@ public void convert(Context context, String htmlString, File file, boolean shoul
114116
mShouldEncode = shouldEncode;
115117
mResultMap = resultMap;
116118
mPromise = promise;
119+
mBaseURL = baseURL;
117120
runOnUiThread(this);
118121
}
119122

android/src/main/java/com/christopherdro/htmltopdf/RNHTMLtoPDFModule.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,21 @@ public void convert(final ReadableMap options, final Promise promise) {
5454
destinationFile = getTempFile(fileName);
5555
}
5656

57-
convertToPDF(
58-
htmlString,
59-
destinationFile,
60-
options.hasKey("base64") && options.getBoolean("base64") == true,
61-
Arguments.createMap(),
62-
promise
63-
);
57+
convertToPDF(htmlString,
58+
destinationFile,
59+
options.hasKey("base64") && options.getBoolean("base64") == true,
60+
Arguments.createMap(),
61+
promise,
62+
options.hasKey("baseURL") ? options.getString("baseURL") : null);
6463
} catch (Exception e) {
6564
promise.reject(e.getMessage());
6665
}
6766
}
6867

69-
private void convertToPDF(String htmlString, File file, boolean shouldEncode, WritableMap resultMap, Promise promise) throws Exception {
68+
private void convertToPDF(String htmlString, File file, boolean shouldEncode, WritableMap resultMap, Promise promise,
69+
String baseURL) throws Exception {
7070
try {
71-
PdfConverter.getInstance()
72-
.convert(
73-
mReactContext,
74-
htmlString,
75-
file,
76-
shouldEncode,
77-
resultMap,
78-
promise
79-
);
71+
PdfConverter.getInstance().convert(mReactContext, htmlString, file, shouldEncode, resultMap, promise, baseURL);
8072
} catch (Exception e) {
8173
throw new Exception(e);
8274
}

0 commit comments

Comments
 (0)