Creating a downloadable PDF from a wordpress webpage

Viewed 84

I'm currently working on a configurator page on a clients wordpress website.

https://gof.co.uk/test-configurator/

They want to ability to select options on the product and then download a pdf with the image and selections listed. So it will look something like this - PDF concept image

Is there any way to do this? I'm at a bit of a loss.

Thanks,

Jack

2 Answers

Easiest way is to add a button prompting the browsers print window, from there you can save as PDF based on your print media CSS. As far as I know there's no way to directly trigger the save as PDF.

The other solution is to use a library such as jsPDF (javascript) or MPDF (PHP). But then you need to "remake" the page using their syntaxes. You can read more about both libraries here: jsPDF https://parall.ax/products/jspdf MPDF https://mpdf.github.io/

You could use CSS to format for printing give instructions to save to PDF.

You can link a stylesheet like this.

<link rel="stylesheet"
   src="print.css"
   type="text/css"
   media="print" />

An alternative to the previous approach is media queries. Anything you add inside this block will apply to printed documents.

@media print {

}

Margins can be set like this.

@page {
  margin-top: 2cm;
  margin-bottom: 2cm;
  margin-left: 2cm;
  margin-right: 2cm;
}
Related