pdf Inputs

The DynamicPDF API's pdf
endpoint uses a JSON document that provides processing instructions for manipulating PDFs. The instructions document has six input types.
endpoint | description |
---|---|
dlex | Specifies a DLEX document used with JSON layoutdata to create a rich PDF document/report. |
image | Specifies an image that is converted into a PDF. |
html | Specifies an HTML document or fragment that is converted into a PDF. |
word | Specifies a Word document that is converted into a PDF. |
excel | Specifies an Excel document that is converted into a PDF. |
page | Specifies one or more inputs to create a new single-page PDF. |
pdf | Specifies a pre-existing PDF to be be combined with one or the other input types to create a new PDF. Optionally allows applying templates to an existing PDF to overlay elements such as text, shapes, and images. |
Refer to documentation on the instructions schema for more general information on how to use the pdf
endpoint.
Use the six input types in any combination to combine into a merged PDF document.
For all inputs, input the relative path to the resource as a string if using a resource such as a DLEX file, image, or layout data that resides in your DynamicPDF API's cloud storage. Otherwise, you will use one of the input's associated resource classes if the resource is on your local system.
The resources for all the examples in this documentation are available from samples/users-guide-resources
in cloud storage. See environment-manager-sample-resources for more information.
DlexInput
The DlexInput
class adds a DLEX file to an instructions document for processing by the pdf
endpoint. This input type is used in combination with DynamicPDF Designer to create rich reports/documents.
See the Designer documentation for more information on using Designer.
- C# (.NET)
- Java
- Node.js
- PHP
- Go
- Python
- Ruby
The .NET C# client library DlexInput
class has the following constructors.
Constructors
public DlexInput(DlexResource dlexResource, LayoutDataResource layoutData);
public DlexInput(DlexResource dlexResource, string layoutData);
public DlexInput(string cloudResourcePath, LayoutDataResource layoutData);
public DlexInput(string cloudResourcePath, string layoutData);
- The
DlexResource
class obtains the DLEX for processing. - The
LayoutDataResource
class obtains the JSON data processed by the DLEX to create the resultant PDF report. - The
cloudResourcePath
string passes the relative path to a DLEX file in your cloud storage. - The
layoutData
string that passes the path in your local storage to the JSON layout data.
You do not create a DlexInput
instance directly. Instead, you pass the DlexResource
and LayoutDataResource
to the Pdf
class's AddDlex
method.
Properties
The DlexInput
class has one property, which you set via the Pdf
AddDlex
method rather than through a DlexInput
instance.
public string LayoutDataResourceName { get; set; }
LayoutDataResource
The LayoutDataResource
class accepts a serializable object containing JSON data or a string. If an object, then the JSON-compatible object is serialized into JSON using the Newsoft.Json.Serialization
class. If a string, then the string is assumed to be a path to a JSON document.
Constructors
public LayoutDataResource(object layoutData, string layoutDataResourceName = null);
public LayoutDataResource(string layoutData, string layoutDataResourceName = null);
Properties
public string LayoutDataResourceName { get; set; }
DlexResource
The DlexResource
class accepts a string, byte array, or a Stream
. If a string, the constructor assumes a path to a DLEX file. Otherwise, it expects the data as either a byte array or Stream
.
Constructors
public DlexResource(string dlexPath, string resourceName = null) : base(dlexPath, resourceName)
public DlexResource(byte[] value, string resourceName = null)
public DlexResource(Stream data, string resourceName = null) : base(data, resourceName)
Examples
The following example illustrates using a DLEX file and JSON file that reside on a local filesystem.
Pdf pdf = new Pdf();
DlexResource dlex = new DlexResource("c:/temp/dlex-resource/SimpleReportWithCoverPage.dlex");
LayoutDataResource layout = new LayoutDataResource("c:/temp/dlex-resource/SimpleReportWithCoverPage.json");
pdf.AddDlex(dlex, layout);
return pdf;
The DlexResource
and LayoutDataResource
classes have constructors that allow a byte array or a stream. The data could come from any number of sources, including a database. The following example illustrates.
If you use a DLEX file that resides locally on your system, remember any embedded resources must also reside in a path reachable by the DLEX.
Pdf pdf = new Pdf();
//get the DLEX from local filesystem
DlexResource dlexResource = new DlexResource("c:/temp/users-guide-resources/SimpleReportWithCoverPage.dlex");
LayoutDataResource layout = new LayoutDataResource("c:/temp/users-guide-resources/SimpleReportWithCoverPage.json");
pdf.AddDlex(dlexResource, layout);
//get the image embedded in the dlex from local filesystem
pdf.AddAdditionalResource("c:/temp/users-guide-resources/NorthwindLogo.gif");
//get layout data as a string
string stringLayoutData = File.ReadAllText("c:/temp/users-guide-resources/SimpleReportWithCoverPage.json");
LayoutDataResource layoutTwo = new LayoutDataResource(stringLayoutData);
//get dlex from cloud storage
pdf.AddDlex("samples/users-guide-resources/SimpleReportWithCoverPage.dlex", layoutTwo);
return pdf;
Refer to DlexLayoutObjectExample
in the dotnet-client-examples
(hhttps://github.com/dynamicpdf-api/dotnet-client-examples/blob/main/DynamicPdfClientLibraryExamples/Examples/InstructionsExample.cs) for an example using serializable objects as layout data.
The Nodejs client library's DlexInput
class has the following constructor.
Constructors
The constructor initializes a new instance of the DlexInput
class by:
- posting the DLEX file and the JSON data file or,
- the DLEX file path that is present in the cloud environment and the JSON data file or,
- the DLEX file path and DLEX data file path that is present in the cloud environment from the client to the API to create the PDF report.
export class PdfInput extends Input {
/**Gets or sets the merge options `MergeOptions` */
mergeOptions;
/**Gets or sets the start page. */
startPage;
/** Gets or sets the page count.*/
pageCount;
/**
* Initializes a new instance of the `PdfInput` class.
* @param { PdfResource | string } resource The resource of type `PdfResource`. | The resource path in cloud resource manager.
* @param {MergeOptions} mergeOptions The merge options for the pdf.
*/
constructor(resource, mergeOptions = null) {
super(resource);
if (mergeOptions != null)
this.mergeOptions = mergeOptions;
this._Type = inputType.pdf;
}
You do not create a DlexInput
instance directly. Instead, you pass the DlexResource
and LayoutDataResource
to the Pdf
class's addDlex
method.
LayoutDataResource
The LayoutDataResource
has one constructor that takes either the JSON data as a Buffer
or as a file path to the JSON data. It also includes an optional resource name.
Constructors
export class LayoutDataResource extends Resource {
#fileExtension = ".json";
/** Gets or sets name of the layout data resource. */
layoutDataResourceName;
/**
* Initializes a new instance of the `LayoutDataResource` class
* using the layout data object and a resource name.
* @param {Buffer | string } layoutData Serializable object data (utf-8 Buffer) to create PDF report or the layout data JSON file path (string).
* @param {string} [layoutDataResourceName=null] The name for layout data resource.
*/
constructor(layoutData, layoutDataResourceName = null) {
DlexResource
The DlexResource
class has one constructor which takes either a string path to the resource file or the data as a Buffer
. It also allows an optional resource name.
Constructors
export class DlexResource extends Resource {
#FileExtension = ".dlex";
/** Gets or sets name for layout data resource. */
layoutDataResourceName;
/**
* Initializes a new instance of the `DlexResource` class
* with DLEX file path and resource name or
* byte data of the DLEX file and resource name as parameters.
* @param {string | Buffer[]} dlex The dlex file path. | The Buffer array of the dlex file.
* @param {string} resource The name of the resource.
*/
constructor(dlex, resource = null) {
Examples
The following two examples illustrate using a local DLEX file with local layout data to create a PDF using the pdf
endpoint. The first example uses a string to obtain the DLEX file. The second reads the DLEX file into an object and then loads the binary into a DlexResource
.
If you use a DLEX file that resides locally on your system, remember any embedded resources must also reside in a path reachable by the DLEX.
var pdf = new Pdf();
var dlex = new DlexResource("c:/temp/dlex-resource/SimpleReportWithCoverPage.dlex");
var layout = new LayoutDataResource("c:/temp/dlex-resource/SimpleReportWithCoverPage.json");
pdf.addDlex(dlex, layout);
var pdf = new Pdf();
var dlexStream = fs.readFileSync("c:/temp/dlex-resource/SimpleReportWithCoverPage.dlex", "utf8");
var dlex = new DlexResource(dlexStream);
var layout = new LayoutDataResource("c:/temp/dlex-resource/SimpleReportWithCoverPage.json");
pdf.addDlex(dlex, layout);
The Java client library DlexInput
class has the following constructors.
Constructors
public DlexInput(DlexResource dlexResource, LayoutDataResource layoutData)
public DlexInput(DlexResource dlexResource, String layoutData)
public DlexInput(String cloudResourcePath, LayoutDataResource layoutData)
public DlexInput(String cloudResourcePath, String layoutData)
- The
DlexResource
class obtains the DLEX for processing - The
LayoutDataResource
class obtains the JSON data that is processed by the DLEX to create the resultant PDF report. - The
cloudResourcePath
is a string that passes the relative path to a DLEX file in your cloud storage. - The
layoutData
is a string that passes the path in your local storage to the JSON layout data.
You do not create a DlexInput
instance directly. Instead, you pass the DlexResource
and LayoutDataResource
to the Pdf
class's AddDlex
method.
Properties
The DlexInput
class has one property, which you set via the Pdf
addDlex
method rather than through a DlexInput
instance.
private String layoutDataResourceName
LayoutDataResource
The LayoutDataResource
class accepts a serializable object containing JSON data or a string. If an object, then the JSON compatible object is serialized into JSON. If a string, then the string is assumed to be a path to a JSON document.
Constructors
public LayoutDataResource(Object layoutData, String layoutDataResourceName)
public LayoutDataResource(Object layoutData)
public LayoutDataResource(String layoutData, String layoutDataResourceName)
public LayoutDataResource(String layoutData)
Properties
private ResourceType type = ResourceType.LAYOUTDATA;
private String layoutDataResourceName;
DlexResource
The DlexResource
class accepts a string, byte array, or a InputStream
. If a string, the constructor assumes a path to a DLEX file. Otherwise, it expects the data as either a byte array or an InputStream
.
Constructors
public DlexResource(String dlexPath, String resourceName)
public DlexResource(String dlexPath)
public DlexResource(byte[] value, String resourceName)
public DlexResource(byte[] value)
public DlexResource(InputStream data, String resourceName)
public DlexResource(InputStream data)
If you use a DLEX file that resides locally on your system, remember any embedded resources must also reside in a path reachable by the DLEX.
Example
The following example illustrates creating a PDF where the DLEX file and the layout data JSON file resides on your local file system and then creating a PDF where the DLEX resides in cloud storage and the JSON is binary string data.
// combine two pdf reports into single report (merge)
Pdf pdf = new Pdf();
//create pdf using local dlex and embedded image
LayoutDataResource layoutDataResource = new LayoutDataResource(basePath + "SimpleReportWithCoverPage.json");
DlexResource dlexResource = new DlexResource(basePath + "SimpleReportWithCoverPage.dlex");
pdf.addDlex(dlexResource, layoutDataResource);
pdf.addAdditionalResource("c:/temp/users-guide-resources/NorthwindLogo.gif");
// create pdf using cloud storage dlex and binary JSON data
String jsonData = null;
try {
jsonData = Files.readString(Paths.get(basePath + "SimpleReportWithCoverPage.json"));
} catch (IOException e1) {
e1.printStackTrace();
}
LayoutDataResource layoutData2 = new LayoutDataResource(jsonData);
pdf.addDlex("samples/users-guide-resources/SimpleReportWithCoverPage.dlex", layoutData2);
return pdf;
The following example illustrates using a serialized object as JSON data.
DynamicPDF API uses the Jackson ObjectMapper
class to serialize Java objects into JSON and deserialize JSON string into Java objects.
String jsonText = null;
SimpleReport simpleReport = null;
Pdf pdf = new Pdf();
try {
jsonText = Files.readString(Paths.get(basePath + "/SimpleReportWithCoverPage.json"));
// ObjectMapper instantiation
ObjectMapper objectMapper = new ObjectMapper();
// Deserialization into the `SimpleReport` class
simpleReport = objectMapper.readValue(jsonText, SimpleReport.class);
com.fasterxml.jackson.databind.ObjectMapper basicMapper = new ObjectMapper();
jsonText = basicMapper.writeValueAsString(simpleReport);
try {
jsonText = Files.readString(Paths.get(basePath + "SimpleReportWithCoverPage.json"));
} catch (IOException e1) {
e1.printStackTrace();
}
LayoutDataResource layoutData = new LayoutDataResource(jsonText);
pdf.addDlex("samples/users-guide-resources/SimpleReportWithCoverPage.dlex", layoutData);
} catch (Exception e1) {
e1.printStackTrace();
}
return pdf;
The DlexInput
class allows you to use a DLEX combined with the DLEX file's layout data to create a PDF.
Constructors
The DlexInput
class has the following constructor and initializes a new instance by posting the DLEX file and the JSON data file from the client to the API to create the PDF report. The $dlex
parameter is the DLEX file path present in the resource manager or the DlexResource
file created as per the desired PDF report layout design. The $layout
parameter is the JSON data file path present in the resource manager used to create the PDF report or the LayoutDataResource
file used to create the PDF report.
class DlexInput extends Input
{
/**
*
* Initializes a new instance of the DlexInput class by posting the DLEX file and the JSON data file from
* the client to the API to create the PDF report.
*
* @param string|DlexResource $dlex The DLEX file path present in the resource manager or the DlexResource file created as per the desired PDF report layout design.
* @param string|LayoutDataResource $layout The JSON data file path present in the resource manager used to create the PDF report or the LayoutDataResource file used to create the PDF report.
*/
public function __construct($dlex, $layout)
You do not call the DlexInput
class directly, but rather through the Pdf
class's AddDlex
method. See the example below.
LayoutDataResource
The LayoutDataResource
class initializes a new instance using the layout data object and a resource. The $layout
parameter is a serializable object data to create PDF report or the layout data JSON file path. The $layoutDataResourceName
is the name for layout data resource.
Constructors
class LayoutDataResource extends Resource
{
/**
*
* Initializes a new instance of the LayoutDataResource class using the layout data object and a resource
* name.
*
* @param array|string $layout Data to create PDF report as an array of JSON content or as a string of JSON file path.
* @param string $layoutDataResourceName The name for layout data resource.
*/
public function __construct($layout = null, string $layoutDataResourceName = null)
DlexResource
The DlexResource
class initializes a new instance with the DLEX file path and resource name as parameters. The $dlex
parameter is the DLEX file path, the byte array of the DLEX file, or a stream containing the DLEX file. The optional $resourceName
is the name of the resource.
Constructors
class DlexResource extends Resource
{
/**
*
* Initializes a new instance of the DlexResource class with DLEX file path and resource name as parameters.
*
* @param string|array|stream $dlex The dlex file path or the byte array of the dlex file or the stream of the dlex file.
* @param string $resourceName The name of the resource.
*/
public function __construct($dlex, string $resourceName = null)
Examples
The following examples illustrates first creating a PDF from a DLEX and its layout data and then creating a PDF from a stream.
//get layoutdata from local filesystem
$layoutData = new LayoutDataResource(CreatingPdfDlexLayout::$BasePath . "creating-pdf-dlex-layout.json");
//load dlex from cloud and layoutdata from file
$dlexEndpoint = new DlexLayout("samples/creating-pdf-dlex-layout-endpoint/creating-pdf-dlex-layout.dlex", $layoutData);
$dlexEndpoint->ApiKey = "DP.xxx-api-key-xxx";
$response = $dlexEndpoint->Process();
$file_content = file(CreatingPdfDlexString::$BasePath . "SimpleReportWithCoverPage.json");
$layoutData = new LayoutDataResource($file_content);
$pdf = new Pdf();
$pdf->ApiKey ="DP.xxx-api-key-xxx";
//load dlex from cloud and layoutdata from object
$pdf->AddDlex("samples/dlex-layout/SimpleReportWithCoverPage.dlex", $layoutData);
$response = $pdf->Process();
The following methods initializes a new instance of a DlexInput
( Dlex.go). Note that the DlexInput
is a struct where you only call the methods. It has methods to load a DLEX file as a local resource or from the cloud. Call one of these methods to create the resultant PDF.
The dlexResource
is either a path to the DLEX file in DynamicPDF CloudAPI cloud storage or the resource on your local system. The layoutData
is the layout data (The JSON data) in DynamicPDF CloudAPI cloud storage or on your local system.
func NewDlexWithDlexNLayoutResources(dlexResource resource.DlexResource, layoutData resource.LayoutDataResource) *Dlex
func NewDlexWithDlexResourceNLayoutDataPath(dlexResource resource.DlexResource, layoutData string) *Dlex
func NewDlexWithCloudResourceNLayoutData(cloudResourcePath string, layoutData resource.LayoutDataResource) *Dlex
func NewDlexWithCloudResourceNLayoutDataPath(cloudResourcePath string, layoutData string) *Dlex
Example
In the following example the PDF is created using a local path to the DLEX file and a local path to the layout data's JSON document.
pdfD := endpoint.NewPdf()
pdfD.AddDlexWithDlexResourceNLayoutDataPath("C:/temp/dynamicpdf-api-samples/getting-started.dlex", "C:/temp/dynamicpdf-api-samples/getting-started.json")
pdfD.Endpoint.BaseUrl = baseUrl
pdfD.Endpoint.ApiKey = key
return pdfD
The DlexInput
class allows you to use a DLEX combined with the DLEX file's layout data to create a PDF.
Constructors
The DlexInput
class has the following constructor and initializes a new instance by posting the DLEX file and the JSON data file from the client to the API to create the PDF report. The resource
parameter is the DLEX file path present in the resource manager or the DlexResource
file created as per the desired PDF report layout design. The layout
parameter is the JSON data file path present in the resource manager used to create the PDF report or the LayoutDataResource
file used to create the PDF report.
class DlexInput(Input):
'''
Represents a Dlex input
'''
def __init__(self, resource, layout_data):
You do not call the DlexInput
class directly, but rather through the Pdf
class's add_dlex
method. See the example below.
LayoutDataResource
The LayoutDataResource
class initializes a new instance using the layout data object and a resource. The $layout
parameter is a serializable object data to create PDF report or the layout data JSON file path. The $layoutDataResourceName
is the name for layout data resource.
Constructors
class LayoutDataResource(Resource):
'''
Represents the Layout data resource used to create PDF reports
'''
def __init__(self, layout_data, layout_data_resource_name = None):
DlexResource
The DlexResource
class initializes a new instance with the DLEX file path and resource name as parameters. The $dlex
parameter is the DLEX file path, the byte array of the DLEX file, or a stream containing the DLEX file. The optional $resourceName
is the name of the resource.
Constructors
class DlexResource(Resource):
'''
Represents a Dlex resource object that is created using the DLEX file and a name.
'''
def __init__(self, dlex, resource = None):
Examples
The following example illustrates creating a PDF from a DLEX and its layout data as a file path.
def ug_dlex_pdf_example(documentPath):
pdf = Pdf()
layout = LayoutDataResource(documentPath + "SimpleReportWithCoverPage.json")
pdf.add_dlex("samples/users-guide-resources/SimpleReportWithCoverPage.dlex", layout)
return pdf
This next example illustrates creating a PDF from a DLEX and its layout data as an object. Although the example uses a JSON file, it loads the file into a string and then converts the JSON string into an object hierarchy.
def ug_dlex_string_pdf_string_example(documentPath):
pdf = Pdf()
with open(documentPath + "SimpleReportWithCoverPage.json","r") as f:
fileData = f.read()
f.close()
python_obj = json.loads(fileData)
layout = LayoutDataResource(python_obj)
pdf.add_dlex("samples/users-guide-resources/SimpleReportWithCoverPage.dlex", layout)
return pdf
The complete example is available from the InstructionsExample.py
file on GitHub (https://github.com/dynamicpdf-api/python-client-examples).
See DlexLayoutObjectExample.py
for an example of creating a Python object hierarchy as layout data
The DlexInput
class allows you to use a DLEX combined with the DLEX file's layout data to create a PDF.
Constructors
The DlexInput
class has the following constructor and initializes a new instance by posting the DLEX file and the JSON data file from the client to the API to create the PDF report. The resource
parameter is the DLEX file path present in the resource manager or the DlexResource
file created as per the desired PDF report layout design. The layout
parameter is the JSON data file path present in the resource manager used to create the PDF report or the LayoutDataResource
file used to create the PDF report.
class DlexInput < Input
#
# Initializes a new instance of the DlexInput class by posting the DLEX file and the JSON data file from
# the client to the API to create the PDF report.
#
#@param dlex [String]|[DlexResource] The DLEX file path present in the resource manager or the DlexResource file created as per the desired PDF report layout design.
#@param layout [String]|[LayoutDataResource] The JSON data file path present in the resource manager used to create the PDF report or the LayoutDataResource file used to create the PDF report.
#
def initialize(dlex, layout)
super()
@_resources = []
@_type = InputType::DLEX
You do not call the DlexInput
class directly, but rather through the Pdf
class's add_dlex
method. See the example below.
LayoutDataResource
The LayoutDataResource
class initializes a new instance using the layout data object and a resource. The $layout
parameter is a serializable object data to create PDF report or the layout data JSON file path. The $layoutDataResourceName
is the name for layout data resource.
Constructors
#
# Initializes a new instance of the LayoutDataResource class using the layout data object and a resource
# name.
#
# @param layout [Object]|[String] Serializable object data to create PDF report or the layout data JSON file path.
# @param layout_data_resource_name [String] The name for layout data resource.
#
def initialize(layout = nil, layout_data_resource_name = nil)
DlexResource
The DlexResource
class initializes a new instance with the DLEX file path and resource name as parameters. The $dlex
parameter is the DLEX file path, the byte array of the DLEX file, or a stream containing the DLEX file. The optional $resourceName
is the name of the resource.
Constructors
#
# Initializes a new instance of the DlexResource class with DLEX file path and resource name as parameters.
#
# @param dlex [String]|[Array]|[Stream] The dlex file path or the byte array of the dlex file or the stream of the dlex file.
# @param resource_name [String] The name of the resource.
#
def initialize(dlex, resource_name = nil)
@layout_data_resource_name = nil
@_type = ResourceType::DLEX
@_mime_type = 'application/xml'
super(dlex, resource_name)
end
Examples
The following example illustrates creating a PDF from a DLEX and its layout data as a file path.
def self.run_cloud(apikey, path, output_path)
layout_data = LayoutDataResource.new("#{path}creating-pdf-dlex-layout.json")
dlex_endpoint = DlexLayout.new("samples/creating-pdf-dlex-layout-endpoint/creating-pdf-dlex-layout.dlex", layout_data)
dlex_endpoint.api_key = apikey
response = dlex_endpoint.process
if response.is_successful
File.open("#{output_path}dlex-layout-cloud-example-output.pdf", 'wb') { |file| file.write(response.content) }
else
puts response.error_json
end
ImageInput
Use an ImageInput
to process and add an image to a PDF that is returned from the pdf
endpoint. The DynamicPDF API supports the following nine common image types.
File Type | Description |
---|---|
JPEG | JPEGs are handled natively through a highly efficient pass through process. |
PNG | PNGs are handled natively. If the PNG does not have an alpha channel (transparency), it uses a highly efficient pass through process. If the PNG does have an alpha channel it is parsed and reformatted for inclusion in a PDF document. |
BMP | BMPs are converted to a bitmap for inclusion in a PDF document. |
EMF | EMFs are converted to a bitmap for inclusion in a PDF document. |
WMF | WMFs are converted to a bitmap for inclusion in a PDF document. |
EXIF | EXIFs are handled natively through a highly efficient pass through process. |
JPEG 2000 | JPEG 2000s are handled natively through a highly efficient pass through process. |
GIF | GIFs are handled natively, but are parsed and reformatted for inclusion in a PDF document. |
TIFF | TIFFs are handled natively and most types of TIFFs (LZW being the exception) use a highly efficient pass through process. Multi-page Tiffs are supported, allowing access to any page in a TIFF document. |
- C# (.NET)
- Java
- Node.js
- PHP
- Go
- Python
- Ruby
The ImageInput
class has the following two constructors. Note that when using the constructor that takes a string, it expects the relative path in your DynamicPDF Cloud Storage and not a local path. Use the ImageResource
class for local images.
Constructors
public ImageInput(ImageResource resource);
public ImageInput(string cloudResourcePath);
Properties
The ImageInput
class provides the following properties for customizing the outputted PDF.
public float? ScaleX { get; set; }
public float? ScaleY { get; set; }
public float? TopMargin { get; set; }
public float? LeftMargin { get; set; }
public float? BottomMargin { get; set; }
public float? RightMargin { get; set; }
public float? PageWidth { get; set; }
public float? PageHeight { get; set; }
public bool? ExpandToFit { get; set; }
public bool? ShrinkToFit { get; set; }
public Align Align { get; set; }
public VAlign VAlign { get; set; }
public int? StartPage { get; set; }
public int? PageCount { get; set; }
ImageResource
Use the ImageResource
class when working with local resources. This class has constructors that accept a file path, a byte array, or a Stream
.
public ImageResource(string filePath, string resourceName = null);
public ImageResource(byte[] value, string resourceName = null);
public ImageResource(Stream data, string resourceName = null);
Example
The following example illustrates using the image
input type to get an image as a file, as binary, and then from DynamicPDF Cloud Storage.
Pdf pdf = new Pdf();
//get image from local system
ImageResource ir = new ImageResource("C:/temp/users-guide-resources/A.png");
pdf.AddImage(ir);
//get Image as binary from local system
ImageResource ir2 = new ImageResource(File.ReadAllBytes("C:/temp/users-guide-resources/B.png"));
pdf.AddImage(ir2);
//get image from cloud storage
pdf.AddImage("samples/users-guide-resources/C.png");
return pdf;
The ImageInput
class has one constructor. The resource parameter is either an ImageResource
instance or a path present in cloud resource manager.
Constructors
export class ImageInput extends Input {
/**
* Initializes a new instance of the `ImageInput` class.
* @param {ImageResource | string} resource object to create ImageInput. | The image file path present in cloud resource manager.
*/
constructor(resource) {
Properties
The ImageInput
converts an image into a PDF and provides the following properties for customizing its output.
scaleX;
scaleY;
expandToFit;
shrinkToFit;
align = align.center;
vAlign = vAlign.center;
startPage;
pageCount;
ImageResource
The ImageResource
class initializes a new instance from the image's file path or a byte array of the image file. It also has an optional string to specify the resource name.
Constructors
export class ImageResource extends Resource {
/**
* Initializes a new instance of the `ImageResource` class.
* @param {string | Buffer[]} filePath The image file path. | The byte array of the image file.
* @param {string} resourceName The name of the resource.
*/
constructor(image, resourceName) {
The ImageInput
class converts an image into a PDF. The class has the following two constructors. Use the constructor that takes a string as the cloudResourcePath
for images in your DynamicPDF Cloud Storage. Use the ImageResource
class for images on your local system.
Constructors
public ImageInput(ImageResource resource)
public ImageInput(String cloudResourcePath)
Properties
The ImageInput
converts an image into a PDF and provides the following properties for customizing its output.
private float scaleX;
private float scaleY;
private float topMargin;
private float leftMargin;
private float bottomMargin;
private float rightMargin;
private float pageWidth;
private float pageHeight;
private boolean expandToFit;
private boolean shrinkToFit;
private Align align = Align.CENTER;
private VAlign vAlign = VAlign.CENTER;
private int startPage;
private int pageCount;
ImageResource
Use the ImageResource
class when working with local resources. This class has a constructors that accept a file path, a byte array, or a InputStream
.
Constructors
public ImageResource(String filePath, String resourceName)
public ImageResource(String filePath)
public ImageResource(byte[] value, String resourceName)
public ImageResource(byte[] value)
public ImageResource(InputStream data, String resourceName)
public ImageResource(InputStream data)
Properties
ResourceType resourceType = ResourceType.IMAGE;
String mimeType;
Example
The following example illustrates creating a PDF from three images where one image is a local file, another image is binary, and an image is from cloud storage.
Pdf pdf = new Pdf();
//get image from local system
ImageResource ir = new ImageResource(basePath + "A.png");
pdf.addImage(ir);
//get Image as binary from local system
ImageResource ir2 = null;
try {
ir2 = new ImageResource(Files.readAllBytes(Paths.get(basePath + "B.png")));
} catch (IOException e) {
e.printStackTrace();
}
pdf.addImage(ir2);
//get image from cloud storage
pdf.addImage("samples/users-guide-resources/C.png");
return pdf;
The ImageInput
class initializes a new instance where the $resource
property is either the image file relative path relative in cloud storage or an ImageResource
object.
Constructors
class ImageInput extends Input
{
/**
*
* Initializes a new instance of the ImageInput class.
*
* @param string|ImageResource $resource The image file path present in cloud resource manager or the ImageResource object to create ImageInput.
*/
public function __construct($resource)
Properties
The ImageInput
class has the following properties for customizing the PDF created from the image.
public $ScaleX;
public $ScaleY;
public $TopMargin;
public $LeftMargin;
public $BottomMargin;
public $RightMargin;
public $PageWidth;
public $PageHeight;
public $ExpandToFit;
public $ShrinkToFit;
public $Align = Align::Center;
public $VAlign = VAlign::Center;
public $StartPage;
public $PageCount;
ImageResource
Use the ImageResource
class to create a new class instance where the $file
parameter is either the image file path, the byte array of the image file, or the stream of the image file. The $resourceName
is an optional resource name.
Constructors
class ImageResource extends Resource
{
/**
*
* Initializes a new instance of the ImageResource class.
*
* @param string|array|stream $filePath The image file path or the byte array of the image file or the stream of the image file.
* @param string $resourceName The name of the resource.
*/
public function __construct($file, string $resourceName = null)
The following methods implement an ImageInput
instance (image.go
). The NewImageWithResourcePath
uses the image file path present in your DynamicPDF Cloud Storage. The NewImageWithImageResource
method uses the resource to create an instance of the Image
class.
func NewImageWithResourcePath(value string) *Image
func NewImagewithImageResource(value resource.ImageResource) *Image
Properties
The Image
structure has the following properties available to format the image converted to PDF.
ScaleX int
ScaleY int `json:"scaleY"`
ExpandToFit float32 `json:"expandToFit"`
ShrinkToFit float32 `json:"shrinkToFit"`
Align position.Align `json:"align"`
VAlign position.VAlign `json:"vAlign"`
Example
In the following example the endpoint fetches an image from your local system and another image from cloud storage. It then merges these two images to create a two page PDF document.
prImage := endpoint.NewPdf()
imageResource := resource.NewImageResourceWithResourcePath("C:/temp/getting-started.png", "getting-started.png")
prImage.AddImage(imageResource)
prImage.AddImageCloudPath("samples/image-info/getting-started.png")
prImage.Endpoint.ApiKey = key
prImage.Endpoint.BaseUrl = baseUrl
return prImage
The ImageInput
class initializes a new instance where the resource
property is either the image file relative path relative in cloud storage or an ImageResource
object.
Constructors
class ImageInput(Input):
'''
Represents an image input
'''
def __init__(self, resource):
Properties
The ImageInput
class has the following properties for customizing the PDF created from the image.
# Gets or sets the scaleX of the image.
self.scale_x = None
# Gets or sets the scaleY of the image.
self.scale_y = None
# Gets or sets the top margin.
self.top_margin = None
# Gets or sets the left margin.
self.left_margin = None
# Gets or sets the bottom margin.
self.bottom_margin = None
# Gets or sets the right margin.
self.right_margin = None
# Gets or sets the page width.
self.page_width = None
# Gets or sets the page height.
self.page_height = None
# Gets or sets a boolean indicating whether to expand the image.
self.expand_to_fit = None
# Gets or sets a boolean indicating whether to shrink the image.
self.shrink_to_fit = None
# Gets or sets the horizontal alignment of the image.
self.align = Align.Center
# Gets or sets the vertical alignment of the image.
self.v_align = VAlign.Center
# Gets or sets the start page.
self.start_page = None
# Gets or sets the page count.
self.page_count = None
ImageResource
Use the ImageResource
class to create a new class instance where the image
parameter is either the image file path or the byte array of the image file. The resourceName
is an optional resource name.
Constructors
class ImageResource(Resource):
'''
Represents an image resource used to create an ImageInput
object to create PDF from images
'''
def __init__(self, image, resource_name = None):
Example
The following example illustrates three different ways to process an image. The code first reads an image as an io.BytesIO
stream. Then it uses the file directly from cloud storage. Finally, it gets the file from the local file system.
def ug_image_example(documentPath):
pdf = Pdf()
#read image as binary stream
with io.open(documentPath + "A.png", 'rb') as f:
imageBinary = f.read()
imageStream = io.BytesIO(imageBinary)
f.close()
imageResource = ImageResource(imageStream)
pdf.add_image(imageResource)
#get image from cloud storage
pdf.add_image("samples/users-guide-resources/B.png")
#get image from local file
imageFile = documentPath + "C.png"
imageResource2 = ImageResource(imageFile)
pdf.add_image(imageResource2)
return pdf
The ImageInput
class has the following two constructors. Note that when using the constructor that takes a string, it expects the relative path in your DynamicPDF Cloud Storage and not a local path. Use the ImageResource
class for local images.
Constructors
#
# Represents an image input.
#
class ImageInput < Input
#
# Initializes a new instance of the ImageInput class.
#
# @param resource [String]|[ImageResource] The image file path present in cloud resource manager or the ImageResource object to create ImageInput.
#
def initialize(resource)
@_type = InputType::IMAGE
@scale_x = nil
@scale_y = nil
@top_margin = nil
@left_margin = nil
@bottom_margin = nil
@right_margin = nil
@page_width = nil
@page_height = nil
@expand_to_fit = nil
@shrink_to_fit = nil
@align = Align::CENTER
@v_align = VAlign::CENTER
@start_page = nil
@page_count = nil
super(resource)
end
Properties
The ImageInput
class provides the following properties for customizing the outputted PDF.
#
# Gets or sets the scaleX of the image.
#
attr_accessor :scale_x
#
# Gets or sets the scaleY of the image.
#
attr_accessor :scale_y
#
# Gets or sets the top margin.
#
attr_accessor :top_margin
#
# Gets or sets the left margin.
#
attr_accessor :left_margin
#
# Gets or sets the bottom margin.
#
attr_accessor :bottom_margin
#
# Gets or sets the right margin.
#
attr_accessor :right_margin
#
# Gets or sets the page width.
#
attr_accessor :page_width
#
# Gets or sets the page height.
#
attr_accessor :page_height
#
# Gets or sets a boolean indicating whether to expand the image.
#
attr_accessor :expand_to_fit
#
# Gets or sets a boolean indicating whether to shrink the image.
#
attr_accessor :shrink_to_fit
#
# Gets or sets the horizontal alignment of the image.
#
attr_accessor :align
#
# Gets or sets the vertical alignment of the image.
#
attr_accessor :v_align
#
# Gets or sets the start page.
#
attr_accessor :start_page
#
# Gets or sets the page count.
#
attr_accessor :page_count
ImageResource
Use the ImageResource
class when working with local resources. This class has constructors that accept a file path, a byte array, or a Stream
.
#
# Represents an image resource used to create an ImageInput object to create PDF from images.
#
class ImageResource < Resource
#
# Initializes a new instance of the ImageResource class.
#
# @param file [String]|[Stream] The image file path or the byte of the image file or the stream of the image file.
# @param resource_name [String] The name of the resource.
#
def initialize(file, resource_name = nil)
@_type = ResourceType::IMAGE
@_mime_type = nil
super(file, resource_name)
end
Example
The following example illustrates using the image
input type to get an image as a file, as binary, and then from DynamicPDF Cloud Storage.
TBD
HtmlInput
Use an HtmlInput
class to process and add HTML to a PDF that is returned from the pdf
endpoint.
DynamicPDF API fully supports HTML 5 and CSS but does not support JavaScript.
An embedded base path must be a resource publicly accessible via HTTP.
- C# (.NET)
- Java
- Node.js
- PHP
- Go
- Python
- Ruby
The HtmlInput
class has one constructor that takes an HtmlResource
, a basepath
(if it exists), PageSize
, PageOrientation
, and margins
as a float.
Constructor
public HtmlInput(HtmlResource resource, string basepath = null, PageSize size = PageSize.Letter, PageOrientation orientation = PageOrientation.Portrait, float? margins = null);
The HtmlInput
class only accepts local resources and only accepts raw HTML strings.
Properties
The HtmlInput
class has the following properties for customizing the format of the created PDF.
public string BasePath { get; set; }
public float? TopMargin { get; set; }
public float? LeftMargin { get; set; }
public float? BottomMargin { get; set; }
public float? RightMargin { get; set; }
public float PageWidth { get; set; }
public float PageHeight { get; set; }
public PageSize PageSize { get; set; }
public PageOrientation PageOrientation { get; set; }
HtmlResource
The HtmlResource
class constructor only accepts raw HTML strings
Constructors
public HtmlResource(string html, string resourceName = null)