Documentation / Tutorials / Awesome Enterprise
How to create PDF using Awesome Enterprise
/ Awesome Enterprise / How to create PDF using Awesome Enterprise
pdf.generate is used to provide the ability to generate PDF from HTML content. It is based on tcpdf library, with pdf.generate you can save a pdf file or force it to download it.
setup| header | footer | content | download | saveVarious parts split the usage of pdf.generate into manageable chunks.
Part = Setup for pdf.generate
When you are starting to set up various properties of your PDF file like page orientation etc., you start by using part=setup. It takes following values as a JSON object, as shown in example below
P or Portrait | L or LandscapeIf not specified, Portrait is taken as default
pt | mm | cm | inA point equals 1/72 of an inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit
A0| A4 | LETTERA bigger list of supported page formats can be seen at https://tcpdf.org/docs/srcdoc/tcpdf/class-TCPDF_STATIC/#$page_formats. You can also provide an array of width and height for custom sizes.
TRUE | FalseTRUE means that the input text is Unicode (default = true)
Charset encoding (used only when converting back HTML entities); default is UTF-8.
TRUE | FalseIf TRUE set the document to PDF/A mode.
yes | noIf it is set to ‘no’ then the header is not set on pdf file, and part=header section is ignored. By default, it is yes.
Size of the header, it is specified in the page unit selected.
yes | noIf it is set to ‘no’ then the footer is not set on pdf file, and part=footer section is ignored. By default, it is yes.
Size of the footer is specified using footer_margin
If provided it will set as author of the PDF file
If provided it will be set as title of the PDF file
It allows you to set the left margin of the page
It allows you to set the top margin of the page
It allows you to set the right margin of the page
Set over all font to use for the PDF file
A working example
Part = Header for pdf.generate
If you want to set a header to the PDF you can use the part=header. It allows you to set the font, size for the full header. It gives you the flexibility to control the position of each item where you want. It supports following JSON parameters
You can specify the name of the font to use.
size of the font
Part = Footer for pdf.generate
Similar to part = header, it allows you to configure things for footer of you PDF page. Part = Footer has same JSON attributes as header.
Part = Content for pdf.generate
This is where actual HTML page content of you pdf file is written. It uses writeHTML function of tcpdf, so make sure the HTML you are writing here is well formed. You can use awesome studio shortcodes within the content. It will be parsed while generating PDF
Part = Download for pdf.generate
If you want to download the generated PDF you use part=download. Once this part is executed, PDF file is forced to download and the pdf objected is destroyed. It requires just one additional attribute
Name of the PDf that will be used while downloading the file.
Part = Save for pdf.generate
If instead of downloading you want to save the generated PDF file then you can use part=save. Similar to download part, it will destroy the PDF object when executed. It requires few additional parameters
The folder where you want to save the pdf files. This path must have write permission.
Name of the PDF that will be used while saving the file.
It returns the path of PDF file generated.