The PDF file is NOT Created - Wrong filePath
See original GitHub issueRecently, RNHTMLtoPDF.convert()
stopped doing anything! No error is provided, and the file is not created. However, I noticed that the filePath
, which it uses does NOT actually exist (to the best of my knowledge.) This occurs on Android. I have not, yet, tried it on iOS.
build.grade:
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "21.4.7075529"
googlePlayServicesAuthVersion = "19.2.0"
kotlinVersion = "1.6.0"
My code:
if (Platform.OS === "android") {
directoryPath = "Download";
}
else {
directoryPath = "Documents";
}
const _createPDF = async () => {
try {
let file = await RNHTMLtoPDF.convert({
html: htmlContents,
fileName: "myFileName",
directory: directoryPath,
});
console.log("PDF - file.filePath:", file.filePath, ); // results in the following path:
// /storage/emulated/0/Android/data/<myAppName>/files/Download/myFileName.pdf"
// it should be: /storage/emulated/0/Download/myFileName.pdf
}
catch (err) {
console.log("PDF - inside _createPDF - catch - err:", err, );
}
};
try {
await _createPDF();
console.log("PDF - after calling _createPDF successfully"); // <<<<<<<<< The code reaches this point with no errors
}
catch (err) {
console.log("PDF - after calling _createPDF - catch - err:", err, );
}
Versions:
"react-native": "0.66.4",
"react-native-html-to-pdf": "^0.12.0",
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7
Top Results From Across the Web
Solved: "There was an error while opening this document.
The path does not exist' when you try to open the PDF from the windows context menu or by double click. Is this...
Read more >PDF file path is incorrect [duplicate] - java
I want to open a PDF file in my application but something goes wrong everytime. Yeah , I watched many topics about it,...
Read more >Specified path does not exist
I get the message "The specified path does not exist". All other existing files types are accessible. Only PDF paths seem to be...
Read more >Error: PDF File not found after compiling
I created my .tex file. I compiled it and the editor tells me that the .log file is created and the PDF file...
Read more >Excel Macro to Save Sheets As PDF
Export the Active Sheet as PDF File. How the Macro Works. Macro 2 - No Prompt. Macro 3 - File Check. Error -...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you guys still have an issue concerning the file path and the pdf not getting created in the appropriate folder. I have found a work around.
Go directly to the source code in your node module react-native-html-pdf -> android -> com -> christopherdro -> htmltopdf -> RNHTMLtoPDFModule.java In the convert() function change this code block
with
File path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), options.getString(DIRECTORY));
And that should change the file path to the appropriate location inside your emulator/device.
Facing the same problem. Path is showing - /storage/emulated/0/Android/data/com.reactnative/files/Documents/test.pdf But no file is being generated.