Open bilalswiftsolutions opened 3 years ago
Works fine for me:
const options = {
documentSize: "A4",
fileName: "devis.pdf",
};
export const shareFromData = async (action: string, data: object) => {
PDFGenerator.fromData(createHTML(data), {
...options,
type: action,
})
.then(() => console.log("PDF généré!"))
.catch((err) => console.log(err));
};
Function createHTML
just returns some html code where I inject dynamic data via variable nesting using ${}
.
However, I'm unable to add image using img
tag and src
attribute.
I appended the component styles using the style tag in the string which we are passing as pdfContent , it worked for me
const options = {
documentSize: "A4",
type: "share",
fileName: "myFile.pdf"
};
console.log(this.$refs.order.$el.outerHTML);
PDFGenerator.fromData(`<style>.container{background:red}<style/>${this.$refs.order.$el.outerHTML}`, options)
.then(() => "ok")
.catch((err) => console.log(err));
and for the images you can use an public url
I am using this ionic package to generate pdf file
Pdf is generating but it seems like html tags and css is not applied on pdf it seem broken
I am generating pdf like that. I am getting outer html of vue component and then generating pdf from that but thats not happening correctly