Documentation / Tutorials / Tutorials & How to’s

Creating PDF files in WordPress using Awesome Studio

/ Tutorials & How to’s / Creating PDF files in WordPress using Awesome Studio

Using aw2.pdf shortcode of Awesome Studio plugin you can easily create PDFs in WordPress. It allows you to create custom layouts with HTML.

Step 1. Create a module - generate-pdf

Go to Awesome Studio -> Global Modules -> Add New and create a module 'generate-pdf' to follow along with this tutorial.
Step 2. Setup PDF file
Before we can actually generate PDF file we need to specify some of the required properties of a PDF file, like the orientation of the page, a measurement unit for the library when creating PDF file and size of the page.

For this, we will be using aw2.pdf shortcode of Awesome Studio plugin. Its Setup part allows us to specify those properties easily. Put the code shown below within your module.

[aw2.pdf part=setup]
{
	"page_orientation":"P",
	"pdf_unit":"mm",
	"page_format":"A4",
	"show_footer":"yes",
	"show_header":"yes",
	"author":"aw2.dev",
	"title":"Awesome PDF Demo"
}
[/aw2.pdf]

For the demo PDF, we have set page orientation to Portrait, page unit to mm and page size to A4. We have also set the Author and Title meta of the PDF file. While show_header & show_footer properties allow us to decide if we want to hide or show header & footer in the PDF.

 

This is how the final code will look like, just put it any module either in an App or global module, and run it using the aw2.module shortcode.

[aw2.pdf part=setup]
{
	"page_orientation":"p",
	"pdf_unit":"mm",
	"page_format":"A4",
	"header_margin":"5",
	"footer_margin":"20",
	"author":"Amit"

}
[/aw2.pdf]

[aw2.pdf part=header]
 {
	"font_name":"freesans",
	"font_size":"15",
	"items":[
	  {
	     "item_type": "cell",
			 "SetY":"1",
			 "w":"10",
			 "h":"0",
			 "text":"Testing Header WPoets",
			 "border":"B",
			 "ln":"1",
			 "align":"R"
		},
	  {
		 "item_type": "text",
			"SetY":"2",
			 "x":"2",
			 "y":"2",
			 "text":"Testing Text Link header",
			 "link":"https://www.wpoets.com"
		},
		{
		 "item_type": "image",
			"SetY":"0.1",
			"file":"D:\\laragon\\www\\awesome\\wp-content\\uploads\\2017\\05\\random-4-100x100.png",
			 "x":"15",
			 "y":"2",
			 "w":"100"
		
		},
		{
		 "item_type": "cell",
			 "SetY":"4",
			 "w":"10",
			 "h":"0",
			 "text":"header cell",
			 "border":"B",
			 "ln":"1",
			 "align":"R"
		}
	]
 
 }
[/aw2.pdf]
[aw2.pdf part=footer]
 {
	"font_name":"freesans",
	"font_size":"15",
	"items":[
  	{
     "item_type": "cell",
	   "SetX":"6",
		 "w":"0",
		 "h":"0",
		 "text":"Generated By Magazinify.com | An Experiment By AmiWorks",
		 "border":"",
		 "ln":"0",
		 "align":"L"
  	}
  ]
 }
[/aw2.pdf]

[aw2.pdf part=content]
	<p style="color:red">the properly formated HTML content with attributes having double quotes.</p>
[/aw2.pdf]
[aw2.pdf part=save dir_path='D:/laragon/www/awesome/wp-content/uploads/2017' filename='abc.pdf'][/aw2.pdf]

 

Categories
Most Popular