react-native-pdf-lib
react-native-pdf-lib copied to clipboard
PDFLib.getDocumentsDirectory() of undefined after Linking
Hello, I keep getting an PDFLib.getDocumentsDirectory() of undefined error even though I followed all the steps on the installation. I would really appreciate it if someone could help enlighten me with this error.
I'm using Cocoapods and I even tried to link the dependencies and also tried doing those steps alone but no luck.
Please help.
React Native Version: 0.61.2 react-native-pdf-lib: 0.2.0 and 0.2.1 (Tried both but are not working for me)
Could you supply an example project so I can reproduce and get to the bottom of it?
Thanks for the response @thekevinbrown, here's the reproduction
https://github.com/danielezra/IssueReproduction
Steps taken
- Fresh react native project
- Install react-native-pdf-lib
- Linked through cocoa pods and react-native-link
Tried doing react-native-link alone and pod install alone but still getting the error.

Any finding on this @thekevinbrown?
For what its worth, I have run into this same issue. I'm going to try to dig a little further and will update if I figure something out.
For what its worth, I have run into this same issue. I'm going to try to dig a little further and will update if I figure something out.
I don't know much about pods yet but got it working. The problem is that the pdflib library does not get compiled because the source is not there, and secondly the static inlcuded libraries don't get linked. I got around it this way:
- Install latest version from github: npm install --save https://github.com/Hopding/react-native-pdf-lib
- Edit RNReactNativePdfLib.podspec in node_modules/react-native-pdf-lib/ios/: 2.1. Include the source files that end in .mm in stead of .m: s.source_files = "*.{h,mm}" 2.2. Add the static libraries that are included: s.ios.vendored_libraries =["lib/universal/libFreeType.a", "lib/universal/libLibJpeg.a", "lib/universal/libLibTiff.a", "lib/universal/libPDFWriter.a", "lib/universal/libZlib.a"].
- in ios/ run pod install
- Copy the header files. From node_modules/react-native-pdf-lib/ios/lib/include/ to ios/Pods/Headers/Private/RnReactNativePdfLib/. Also copy the header files from subdirs freetype/ and freetype/config/
- Now RnReactNativePdfLib library in pods project should compile and the libs link succesffully in your project.
One of the things I'm hoping to do in the future is move away from PDFLib and to just using the built in CG PDF rendering methods on iOS, so that should help this as well.
@zilicon any chance you could make a PR for this so I can roll it into the library?
@zilicon I created a fork using your fix, and I added/change to do the import automatically too https://github.com/jdaoliveira/react-native-pdf-lib
I tested as best as I could, but as I am in work I can't fully test.
@jdaoliveira, could you make a PR for these changes?
@thekevinbrown Done, to make this work i had to remove the folder, probably not the best way, but i couldn't find a way to do it with folders.
Based on the fix found by @zilicon, I made a modification to the podspec which resolve the issue.
TL,DR: add this to the podspec
s.header_mappings_dir = "lib/include"
Explication:
The resulting podspec is now :
require 'json'
package = JSON.parse(File.read(File.join(__dir__, '../package.json')))
Pod::Spec.new do |s|
s.name = "RNReactNativePdfLib"
s.version = package['version']
s.summary = package['description']
s.description = package['description']
s.homepage = package['homepage']
s.license = package['license']
s.author = package['author']
s.source = { :git => 'https://github.com/Hopding/react-native-pdf-lib.git', :tag => 'v'+s.version.to_s }
s.platform = :ios, '9.0'
s.ios.deployment_target = '8.0'
s.dependency 'React'
s.source_files = "**/*.{h,mm}"
s.header_mappings_dir = "lib/include"
s.ios.vendored_libraries =["lib/universal/libFreeType.a", "lib/universal/libLibJpeg.a", "lib/universal/libLibTiff.a", "lib/universal/libPDFWriter.a", "lib/universal/libZlib.a"]
end
After the modification given by @zilicon, the remaining issue is linked to unresolved header import. This is caused by cocoapods which flatten the headers directories. This line prevents this side-effect :
s.header_mappings_dir = "lib/include"
@jdaoliveira, I think you could adapt you're PR with this.
as this issue is still not fixed and there is a font issue now appearing on rn 0.63I forked the fix for that to add on @balzdur PR. If you can't wait you can for the merge to happen, replace whit this line in your package.json and you should be worry free on ios: "react-native-pdf-lib": "github:zilicon/react-native-pdf-lib#fix-fonts",