Generate PDF from code

I am trying to generate a PDF from code. If I click on the generate PDF button of a Printpage it works as expected, if I try to do it via code it generates a PDF but without markup or images.

I just call the generatePdf() method of a Printpage. Is this the right way?

Thank you in advance,

After a long search I found what was causing this anomaly:
The array passed to the generatePdf() method needs 3 elements:

  • id (document id)
  • hostName (here I made the mistake of writing “hostname” without capital N)
  • protocol (http or https)