PDFGun

PDFGun

Sign up

PDFGun documentation

Version 1.2 Last updated 02/11/2024

Using parameters in URL

You can use URL parameter values in your PDF template. For example, if the URL parameter is param1 and value is John then the parameter of URL will be
?param1=John
In this case, the parameter param1 can be used in the PDF template.
My name is {param1}
This parameter param1 will be replaced to value John when the template is generated. The resulting value will be My name is John
Also you can set the image source as variable in URL.
?param1=John&mypicture=https://.../water1.jpg
The second parameter mypicture will be transformed into the image with base64 encoding.
My photo is [image.mypicture]

 
My photo is <img src="data:image/jpeg;base64..."> 

Also URL parameters could be used for backend API request URL.

Your Backend API Request

You could use API for getting data into PDF template and you could use all URL parameters for this operation. For example, if you need to make request
//anysite.com/api/v1/data1/data2?any=data3
and this parameters can always be changed than you could replace API URL in PDFGun like this
//anysite.com/api/v1/{param1}/{param2}?any={param3}
In this case, the request part your PDF URL will be transformed to:
?param1=data1&param2=data2&param3=data3
After this simple manipulation with backend API URL you can make unlimited requests inside PDFGun and get different JSON data for PDF generating. Your API requests always will be hidden inside the PDFGun service. PDFGun supports transferring different URL parameters into API header request. You could setup Authtorization, Content-Type and other custom header parameters in API header before running the API request.

Further if your API request had already done without errors you could use data from API for PDF transforming. First, PDFGun supports a single array in JSON.

[
  {
   "param": "my data number one"
  },
  {
   "param": "my data number two"
  }
]

Second, you could use multiple arrays in JSON data.

{ 
 "data1": [
  {
   "param": "my data number one"
  },
  {
   "param": "my data number two"
  }
], 
 "data2": [
  {
   "param": "my data number one"
  },
  {
   "param": "my data number two"
  }
]
}
Third, you could use complex JSON objects.
{
 "parent": {
   "child": "my data"
  }
}

Writing PDF template parameters

{any parameter}
This is any parameter from any source (URL or API). It must be placed in {} quotes. The parameter key {parameter} in JSON
{
 "parameter": "my data"
}
or in URL
?parameter=my%20data
will be replaced to my data before generating PDF document.
{parent.child}
For complex JSON data objects you could use parent.child annotation. In this example
{
 "parent": {
   "child": "my data"
  }
}
object {parent.child} will be transformed to my data in PDF

PDFGun patterns

[pagebreak]
Generating page break in your PDF
[begin]
Indicate the begining of the root array in JSON. Here is an example JSON data with the root array in [] quotes.
[
  {
   "param": "my data number one"
  },
  {
   "param": "my data number two"
  }
]
In this case, using [begin] [end] pattern in PDF template and writing parameter{param} inside [begin] [end] like this [begin] {param} [end]  will be transformed to my data number one, my data number two in PDF
[end]
Indicate the end of JSON array.
[beginTable.TableName]
Indicate begining of JSON TableName data array. In this example
{ "data": [
  {
   "param": "my data number one"
  },
  {
   "param": "my data number two"
  }
] }
inside [beginTable.data] [endTable.data] annotation you could use {param} pattern for replacing data. In this example, [beginTable.data] {param}, [endTable.data]  will be transformed to my data number one, my data number two
[endTable.TableName]
Indicate end of JSON TableName data array.
{countTable.TableName}
This is expression pattern for calculating length of array (number of rows) TableName data array.
[image.PictureName]
This is picture pattern forPictureName in JSON data array or URL. The picture will be downloaded from remote source and will be inserted into PDF. For example
{ "data": [
  {
   "param": "my data number one",
   "picture": "https://.../water1.jpg"
  },
  {
   "param": "my data number two",
   "picture": "https://.../water2.jpg"
  }
] }
Inside [beginTable.data] [endTable.data] annotation you could use [image.picture] structure for downloading water1.jpg and water2.jpg into PDF document. In this example, PDFGun pattern string
[beginTable.data] {param} is [image.picture], [endTable.data]
will be transformed to
 
my data number one is <img src="data:image/jpeg;base64...">, 
my data number two is <img src="data:image/jpeg;base64..."> 
[image=PictureURL]
This is picture pattern for remote resource with direct URL definition. In this case, the picture will be downloaded from remote resource and will be inserted into PDF. This example pattern[image=https://.../water2.jpg] will be transformed to
 
<img src="data:image/jpeg;base64..."> 
[hideRowIf.<Key>==<Value>]

For complex JSON object

[hideRowIf.<Key1>.<Key2>==<Value>]
This is expression pattern for disabling rows in tables. It can be used with as single as complex JSON objects. Disabling rows if parameter is Key == Value or Key1.Key2 == Value
Here is an example of data array:
{ "data": [
  {
   "id": 1,
   "picture": "https://.../water1.jpg"
  },
  {
   "id": 2,
   "picture": "https://.../water2.jpg"
  }
] }
If you want to dasable showing object with id == 2 you could use expression pattern [hideRowIf.id==2]
[hideKeyIf.<Key>==<Value>]
[endHideKey.<Key>]

For complex JSON object

[hideKeyIf.<Key1>.<Key2>==<Value>]
[endHideKey.<Key1>.<Key2>]
This is expression pattern for disabling parameter from PDF. It can be used with as single as complex JSON objects. If parameter is {Key} equals Key == Value
or for complex JSON objects:
parameter {Key1.Key2} equals Key1.Key2 == Value

For example, if you have array of objects
{ "data": [
  {
   "id": 1,
   "picture": "https://.../water1.jpg"
  },
  {
   "id": 2,
   "picture": "https://.../water2.jpg"
  }
] }
and you want to hide key with id == 2 you could use this pattern in PDF template
[hideKeyIf.id==2] {id} [endHideKeyIf.id]

See also

PDFGun FAQ