[ad_1]
Hey all,
I’m working on a plugin that I’m using to generate a resume pdf from a WordPress page. It could be used for more than resumes but that is my current use. So, why? Well, I want a nicely formatted PDF of the exact look and feel of how I formatted it in WP. That way I’m only maintaining the wp page and the end user can download a completely up-to-date version of the resume on-demand.

How are you thinking of implementing it? mPDF? 🙂
Github repo can be found here: https://github.com/openartist/clean-pdf-generator/tree/main
In my limited experience, it’s a LOT of work to accomplish this. It just never looks exactly the same and won’t have the same deliverability that exporting from Google doc, etc can do. I think you really just need to account for any possible layout you offer and specify the functionality in mPDF / Dompdf. Lots of trial and error.
i use [https://ekoopmans.github.io/html2pdf.js/](https://ekoopmans.github.io/html2pdf.js/)
I then use this function, added through my theme functions extensions.
I then tweak the media settings etc. It comes out quite similar. You might find making the document length infinite is easier than the page breaks to make it work. This works, but is far from perfect.
note: since the rendering is in the browser, i find it does a better job of accuracy than e.g. dompdf.
I make a button w/ the generate-pdf class on the page to trigger it. The ‘ag_require’ is a lazy-load (since its a fair chunk of javascript to load and almost never used), that function is also below but you don’t need it if you don’t mind loading all the time.
function generatePDF() {
let pdf = null;
const pdfs = document.getElementsByClassName(“generate-pdf”);
if (pdfs) {
pdf = pdfs[0];
}
if (pdf) {
pdf.addEventListener(‘click’, (event) => {
ag_require(“/html2pdf.bundle.min.js”, function () {
var opt = {
filename: `${document.title}.pdf`,
margin: 10,
image: { type: ‘jpeg’, quality: 0.98 },
jsPDF: { format: ‘letter’ },
html2canvas: { scale: 2 },
pagebreak: { mode: [‘css’] },
};
event.target.style.display = “none”;
const element = document.getElementsByTagName(“main”)[0];
let width = element.style.width;
element.style.width = ‘1280px’;
const status = html2pdf().set(opt).from(element).save().then( console.log(“Saved pdf”) );
event.target.style.display = “block”;
element.style.width = width;
});
});
}
}
function ag_require(file, callback) {
// create script element
var script = document.createElement(“script”);
script.src = file;
if (callback) {
script.onreadystatechange = function () {
if (script.readyState === “loaded” || script.readyState === “complete”) {
script.onreadystatechange = null;
callback();
}
};
script.onload = function () {
callback();
};
}
document.documentElement.firstChild.appendChild(script);
}