pdf-info
Use the pdf-info endpoint to upload a PDF document and return JSON describing the PDF.The pdf-info endpoint takes a PDF document and returns the following data as JSON:
- the metadata (title, author, keywords etc)
- any custom properties in the PDF,
- an array of pages with the size of each page,
- and an array of form fields and their name, value and available values (for select boxes).
Refer to the following Users Guide page for more information illustrating how to call the endpoint directly as a REST call.
- Calling the
pdf-infoendpoint using REST (pdf-info REST API).
API
- C# (.NET)
- Java
- Node.js
- PHP
- Go
- Python
- Ruby
The PdfInfo class encapsulates the pdf-info endpoint. A PdfInfo instance takes a PdfResource instance. A PdfResource is constructed from a PDF coming from a file, a byte array, or Stream.
public PdfInfo(PdfResource resource);
public class PdfResource : Resource
{
public PdfResource(string filePath, string resourceName = null);
public PdfResource(byte[] value, string resourceName = null);
public PdfResource(Stream data, string resourceName = null);
}
The PdfInfo class encapsulates the pdf-info endpoint. A PdfInfo instance takes a PdfResource instance. A PdfResource is constructed from a PDF coming from a file, a byte array, or Inputstream.
public PdfInfo(PdfResource resource);
public class PdfResource extends Resource
{
public PdfResource(String filePath, String resourceName);
public PdfResource(String filePath);
public PdfResource(byte[] value, String resourceName);
public PdfResource(byte[] value);
public PdfResource(InputStream data, String resourceName);
public PdfResource(InputStream data);
}
The PdfInfo class encapsulates the pdf-info endpoint. A PdfInfo instance takes a PdfResource instance. A PdfResource is constructed from a PDF coming from a file or a byte array.
export class PdfInfo extends Endpoint {
constructor(resource);
}
export class PdfResource extends Resource {
/**
* Initializes a new instance of the `PdfResource` class.
* @param {string | Buffer[]} input The pdf file path. | The byte array of the pdf file.
* @param {string} resourceName The name of the resource.
*/
constructor(pdf, resourceName);
The PdfInfo class encapsulates the pdf-info endpoint. A PdfInfo instance takes a PdfResource instance. A PdfResource is constructed from a PDF coming from a file or a byte array.
class PdfInfo extends Endpoint
{
public function __construct(PdfResource $resource)
}
class PdfResource extends Resource
{
/**
*
* Initializes a new instance of the PdfResource class.
*
* @param string|array|stream $filePath The pdf file path or the byte
* array of the pdf file or the stream of the pdf file.
* @param ?string $resourceName The name of the resource.
*/
public function __construct($file, ?string $resourceName = null)
The PdfInfo class encapsulates the pdf-info endpoint. A PdfInfo instance takes a PdfResource instance. A PdfResource is constructed from a PDF coming from a file or a byte array.
func NewPdfInfoResource(resource resource.PdfResource) *PdfInfo
func NewPdfResourceWithResourcePath(resource string, resourceName string) PdfResource
func NewPdfResourceWithByteValue(resource string, resourceName string) PdfResource
The PdfInfo class encapsulates the pdf-info endpoint and extends the Endpoint class. A PdfInfo instance takes a PdfResource instance. A PdfResource extends the Resource class and is constructed from a PDF coming from a file, a byte array, or io.BytesIO stream.
class PdfInfo(Endpoint):
def __init__(self,resource):
super().__init__()
self.resource=resource
self.EndpointName = "pdf-info"
class PdfResource(Resource):
'''
Represents a pdf resource
'''
def __init__(self, input, resource_name = None):
'''
Initializes a new instance of the PdfResource class.
Args:
input (string | Buffer[]): The pdf file path. | The byte array of the pdf file.
resourceName (string): The name of the resource.
'''
super().__init__(input, resource_name)
self._type = ResourceType.Pdf
self._file_extension = ".pdf"
self._mime_type = "application/pdf"
The PdfInfo class encapsulates the pdf-info endpoint and extends the Endpoint class. A PdfInfo instance takes a PdfResource instance. A PdfResource extends the Resource class and is constructed from a PDF coming from a file, a byte array, or io.BytesIO stream.
def initialize(resource)
super()
@resource = resource
@_endpoint_name = 'pdf-info'
end
Example
A complete example is available via one of the following GitHub projects depending upon the language you wish to use.
| Language | GitHub Users Guide Project | Class | Location/Package/Namespace |
|---|---|---|---|
| C# | https://github.com/dynamicpdf-api/dotnet-client-examples | Program.cs | namespace PdfInfoExample |
| Go | https://github.com/dynamicpdf-api/go-client-examples | pdf-info-example.go | go-client-examples |
| Java | https://github.com/dynamicpdf-api/java-client-examples | PdfInfoExample.java | com.dynamicpdf.client.api.examples |
| Node.js | https://github.com/dynamicpdf-api/nodejs-client-examples | PdfInfoExample.js | nodejs-users-guide |
| PHP | https://github.com/dynamicpdf-api/php-client-examples | PdfInfoExample.php | php-client-examples |
| Python | https://github.com/dynamicpdf-api/python-client-examples | PdfInfoExample.py | python-client-examples |
| Ruby | https://github.com/dynamicpdf-api/ruby-client-examples | PdfInfoExample.rb | ruby-client-examples |
The processing steps and syntax for all seven languages are similar.
- Create a
PdfInfoinstance and pass aPdfResourceinstance to thePdfInfoinstance. - Call the
PdfInfoinstance'sProcessmethod to return the PDF's metadata as JSON.
- C# (.NET)
- Java
- Node.js
- PHP
- Go
- Python
- Ruby
using DynamicPDF.Api;
using System;
namespace PdfInfoExample
{
class Program
{
static void Main(string[] args)
{
Run("DP.xxx-api-key-xxx", "C:/temp/dynamicpdf-api-usersguide-examples/");
}
public static void Run(string key, string basePath)
{
PdfResource resource = new PdfResource(basePath + "/DocumentA.pdf");
PdfInfo pdfInfo = new PdfInfo(resource);
pdfInfo.ApiKey = key;
PdfInfoResponse response = pdfInfo.Process();
Console.WriteLine(PrettyPrintUtil.JsonPrettify(response.JsonContent));
}
}
}
import {
PdfResource,
PdfInfo
} from "@dynamicpdf/api"
export class PdfInfoExample {
static async Run() {
var basePath = "C:/temp/dynamicpdf-api-usersguide-examples/";
var apiKey = "DP.xxx-api-key-xxx";
var resource = new PdfResource(basePath + "DocumentA.pdf");
var pdfInfo = new PdfInfo(resource);
pdfInfo.apiKey = apiKey;
var res = await pdfInfo.process();
if (res.isSuccessful) {
console.log(JSON.parse(res.content));
}
}
}
PdfInfoExample.Run();
package com.dynamicpdf.api.examples;
import com.dynamicpdf.api.PdfInfo;
import com.dynamicpdf.api.PdfInfoResponse;
import com.dynamicpdf.api.PdfResource;
import com.dynamicpdf.api.util.PrettyPrintUtility;
public class PdfInfoExample {
public static void Run(String key, String basePath) {
PdfResource resource = new PdfResource(basePath + "DocumentA.pdf");
PdfInfo pdfInfo = new PdfInfo(resource);
pdfInfo.setApiKey(key);
PdfInfoResponse response = pdfInfo.process();
System.out.println(PrettyPrintUtility.prettyPrintJSON(response.getJsonContent()));
}
public static void main(String[] args) {
PdfInfoExample.Run("DP.xxx-api-key-xxx",
"C:/temp/dynamicpdf-api-usersguide-examples/");
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
use DynamicPDF\Api\PdfResource;
use DynamicPDF\Api\PdfInfo;
class PdfInfoExample
{
private static string $BasePath = "C:/temp/dynamicpdf-api-usersguide-examples/";
private static string $ApiKey = "DP.xxx-api-key-xxx";
public static function Run()
{
$resource = new PdfResource(PdfInfoExample::$BasePath . "DocumentA.pdf");
$pdfInfo = new PdfInfo($resource);
$pdfInfo->ApiKey = PdfInfoExample::$ApiKey;
$response = $pdfInfo->Process();
echo (json_encode($response));
}
}
PdfInfoExample::Run();
func main() {
resource := resource.NewPdfResourceWithResourcePath("C:/temp/dynamicpdf-api-samples/pdf-info/fw4.pdf", "fw4.pdf")
text := endpoint.NewPdfInfoResource(resource)
text.Endpoint.BaseUrl = "https://api.dpdf.io/"
text.Endpoint.ApiKey = "DP.xxx-api-key-xxx"
resp := text.Process()
res := <-resp
if res.IsSuccessful() == true {
fmt.Print(string(res.Content().Bytes()))
}
}
from dynamicpdf_api.pdf_info import PdfInfo
from dynamicpdf_api.pdf_resource import PdfResource
import pprint
import json
from Shared import *
def pdf_info_example(api_key, full_path):
resource = PdfResource(full_path + "fw4.pdf")
pdf_info = PdfInfo(resource)
pdf_info.api_key = api_key
response = pdf_info.process()
print(pprint.pformat(json.loads(response.json_content)))
if __name__ == "__main__":
pdf_info_example(api_key, base_path + "/pdf-info/")
def self.run(api_key, path)
resource = PdfResource.new("#{path}fw4.pdf")
pdf_info = PdfInfo.new(resource)
pdf_info.api_key = api_key
response = pdf_info.process
if response.is_successful
puts JSON.pretty_generate(JSON.parse(response.json_content))
else
puts response.error_json
end
end