Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Css and html tags are not implemented on pdf generated in vue ionic #137

Open
bilalswiftsolutions opened this issue Aug 26, 2021 · 2 comments

Comments

@bilalswiftsolutions
Copy link

I am using this ionic package to generate pdf file

https://github.com/cesarvr/pdf-generator

Pdf is generating but it seems like html tags and css is not applied on pdf it seem broken

enter image description here

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

 let options = {
        documentSize: "A4",
        type: "share",
        fileName: "myFile.pdf",
      };
 console.log(this.$refs.order.$el.outerHTML)
      PDFGenerator.fromData(`<html lang="en"><head></head><body><div id="app">${this.$refs.order.$el.outerHTML }</div></body></html>`, options)
        .then(() => "ok")
        .catch((err) => console.log(err));
@MadeInFck
Copy link

MadeInFck commented Mar 24, 2022

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 createHTMLjust returns some html code where I inject dynamic data via variable nesting using ${}.
However, I'm unable to add image using imgtag and srcattribute.

@VedantS20
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants