pdf-generator
pdf-generator copied to clipboard
Styles do not apply for iOS
I followed along with the example in the documentation and I can't seem to get the styles to show up in the Print Preview for iOS.
-Since it's iOS, I set cssFile to www/styles.bundle.css -Content is just the innerHTML of the page I'm trying to make a pdf of.
I'm not sure if cssFile is set to the correct path because the pdf looks completely unformatted except for a couple colors from inline styles. Any help would be appreciated!
createPDF(cssFile, content) {
const opts = {
documentSize: "A4",
landscape: "portrait",
type: "share",
fileName: 'my-pdf.pdf'
};
const payload = _.template('<head><link rel="stylesheet" href="<%=css_file%>"></style></head><body><%=content%></body>');
cordova.plugins.pdf.fromData(payload({ css_file: cssFile, content: content }),
opts)
.then()
.catch();
}
Assuming that file is in the FileSystem then, in iOS you'll need to use the cordova-plugin-file, example:
if (cordova.platformId === 'ios') {
// this function is from the cordova-plugin-file...
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory,
function(url) {
//url represents the asset folder www/
// generate your template
let tmpl = payload({ css_file: url + '/' +cssFile, content: content })
// generate PDF
pdf.fromData(payload, opts).then(/.../)
},
function(err) {
console.log('error', err, ' args ->', arguments)
}
);