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.

Attributes:

  • part:
    setup| header | footer | content | download | save

    Various 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

  • page_orientation:
    P or Portrait | L or Landscape

    If not specified, Portrait is taken as default
  • pdf_unit:
    pt | mm | cm | in

    A 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
  • page_format:
    A0| A4 | LETTER

    A 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.
  • unicode:
    TRUE | False

    TRUE means that the input text is Unicode (default = true)
  • encoding:
    Charset encoding (used only when converting back HTML entities); default is UTF-8.
  • pdfa:
    TRUE | False

    If TRUE set the document to PDF/A mode.
  • show_header:
    yes | no

    If 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.
  • header_margin:
    Size of the header, it is specified in the page unit selected.
  • show_footer:
    yes | no

    If 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.
  • footer_margin:
    Size of the footer is specified using footer_margin
  • author:
    If provided it will set as author of the PDF file
  • title:
    If provided it will be set as title of the PDF file
  • left_margin:
    It allows you to set the left margin of the page
  • top_margin:
    It allows you to set the top margin of the page
  • right_margin:
    It allows you to set the right margin of the page
  • font_name:
    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

  • font_name:
    You can specify the name of the font to use.
  • font_size:
    size of the font
  • items:
    item_type

    It is basically number of items you want to manage individually within a header. We support cell , text  and image ( item. Check the example to see the usage.

 

 

An example

 

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

  • filename:
    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

  • dir_path:
    The folder where you want to save the pdf files. This path must have write permission.
  • filename:
    Name of the PDF that will be used while saving the file.

It returns the path of PDF file generated.

Categories
Most Popular

Leave a Reply

Your email address will not be published. Required fields are marked *