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

Add option to set the default filename in the base64 fallback scenario #311

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

imjosh
Copy link

@imjosh imjosh commented Jan 28, 2025

Resolves #301

Can set the filename explicitly or optionally get it from the data uri's metadata

const { jsPDF } = window.jspdf;

const jsPdfDoc = new jsPDF();
jsPdfDoc.text("Hello World!", 20, 20);

const pdfOutBase64 = jsPdfDoc.output("datauristring", {
  // jsPdf puts the filename in the data uri like: 'data:application/pdf;filename=HelloWorld1.pdf;base64,...'
  filename: "HelloWorld1.pdf"
});

// If present, PDFObject will use the filename from the data uri
PDFObject.embed(pdfOutBase64); // filename = "HelloWorld1.pdf"


// Setting the PDFObject option takes precedence
PDFObject.embed(pdfOutBase64, undefined, {
  fallbackFileNameForBase64: "HelloWorld2.pdf" // filename = "HelloWorld2.pdf"
});

// Default if the option isn't set and there's no filename in the data uri
// (Note: can't be tested with jsPDF because it defaults to putting "generated.pdf" in the uri)
PDFObject.embed(anotherPdfOutBase64); // filename = "file.pdf"

Can set the filename explicitly or optionally get it from the data uri's metadata
Resolves pipwerks#301
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

Successfully merging this pull request may close these issues.

change default download file name
1 participant