Getting Started
Using Pdf4me is as simple as it gets when it comes to working with Pdfs. Pdf4me provides Pdf functionalities in different ways that can cater to different developer needs yet keeping it simple. Providing wide range of controls over Pdf generation, modification, protection and archiving Pdf4me services are fast light & highly secure. The services are provided in the latest and most commonly used languages.
To the date, Pdf4me services can be explored in the following languages:
- PHP
- Ruby
- C# (.NET Framework or .NET Core)
- Java
- Javascript
- Python
Also Pdf4me services can be accessed using Curl – Command Line Tool – as well.
Pdf4me also extends its services via –
- Office 365: Using the Microsoft-Flow
- Pdf4meApp (upcoming)
Moreover Pdf4me lets you automate a lot of Pdf related tasks through various strong integrations. Furthermore you can use a variety of cloud storages and integrate them with Pdf4me to enable automatic storage to those locations once you perform an action on a document using Pdf4me functions.
Pdf4me services can be accessed using a basic authorization Key from the User/Developer portal. You can get the Key the following way.
- Login to Pdf4me Developer portal. In the Subscription tab, user can either create a new application or use the ‘Default’ application for accessing the Key (access token) for working with Pdf4me services.
- Copy the Key (access token) and use it in applications or functions using Pdf4me services.
Sample
A short example of how Pdf4me handles Optimization of Pdfs is below:
- curl
- C#
- Java
- JavaScript
- PHP
- Python
- Ruby
curl https://api.pdf4me.com/Optimize/OptimizeByProfile ^
-H "Authorization: Basic DEV-KEY" ^
-F profile=max ^
-F "file=@./PDF_to_Optimise.pdf" ^
-o ./Optimized.pdf
using Pdf4meClient;
// You can provide a generated token to initialise authorization.
Pdf4meClient.Pdf4me.Instance.Init(token);
// optimization for maximal memory size reduction (profile: max)
byte[] optimizedPdf = await Pdf4meClient.Pdf4me.Instance.
OptimizeClient.OptimizeByProfileAsync(
OptimizeActionProfile.Max,
File.ReadAllBytes("PDF_to_Optimise.pdf"));
// and writing the optimized PDF to disk
File.WriteAllBytes("Optimized.pdf", optimizedPdf);
/*
Either you store them in the config.properties file with key token
Do not use any quotes:
Correct: token=sample-not-working-key-aaaaaaa
Incorrect: token="sample-not-working-key-aaaaaaa"
*/
import com.pdf4me.client.Pdf4meClient;
import com.pdf4me.client.OptimizeClient;
Pdf4meClient pdf4meClient = new Pdf4meClient("resources/config.properties");// setup the optimizeClient
OptimizeClient optimizeClient = new OptimizeClient(pdf4meClient);
// optimization for maximal memory size reduction (profile: max) and writing the optimized PDF to disk
byte[] optimizedPdf = optimizeClient.optimizeByProfile(ProfileEnum.MAX, new File("PDF_to_Optimise.pdf"));
FileUtils.writeByteArrayToFile(new File("Optimized.pdf"), optimizedPdf);
const fs = require('fs')
const pdf4me = require('pdf4me')
// replace 'YOUR API KEY' with your token
const pdf4meClient = pdf4me.createClient('YOUR API KEY')
const optimizedPdf = await pdf4meClient.optimizeByProfile('max', fs.createReadStream('PDF_to_Optimise.pdf'))
// writing it to disk
fs.writeFileSync('Optimized.pdf', optimizedPdf)
// load Composer
require 'vendor/autoload.php';
use Pdf4me\API\HttpClient as pdf4meAPI;
$token = "6fg******jdS"; // replace this with your token
$client = new pdf4meAPI($token);
// The pdf4meClient object delivers the necessary authentication when instantiating the different pdf4meClients such as for instance Merge
$optimized = $client->pdf4me()->optimizeByProfile(
[
"profile"=> "max",
"file" => __DIR__.'/PDF_to_Optimise.pdf'
]
);
//writing it to file
file_put_contents('Optimized.pdf', $optimized);
"""
Either you store them in the config.properties file with key token
Do not use any quotes:
Correct: token=sample-not-working-key-aaaaaaa
Incorrect: token="sample-not-working-key-aaaaaaa"
In case the location of your config.properties differs from the default location ('../config.properties'), provide the optional argument path_to_config_file.
"""
pdf4me_client = Pdf4meClient(path_to_config_file='path_to_my_config.properties')
""" or you pass them as arguments when constructing the Pdf4meClient object """
pdf4me_client = Pdf4meClient(token=token)
# The pdf4meClient object delivers the necessary authentication when instantiating the different pdf4meClients such as for instance Optimize
optimize_client = OptimizeClient(pdf4me_client)
# optimization
optimized_pdf = optimize_client.optimize_by_profile(
profile='max',
file=FileReader().get_file_handler(path='PDF_to_Optimise.pdf')
)
# writing the generated PDF to disk
with open('Optimized.pdf', 'wb') as f:
f.write(optimized_pdf)
# Pdf4me works with any Rack application or plain old ruby script. In any regular script the configuration of Pdf4me looks like
# - Require pdf4me
# - Configure pdf4me with API endpoints and credentials
# - Call appropriate methods
# - Require pdf4me
require 'pdf4me'
# - Configure pdf4me with API endpoints and credentials
Pdf4me.configure do |config|
# config.debugging = true
config.token = 'your-app-token'
end
# - Call appropriate methods, for instance merge 2 documents.
a = Pdf4me::OptimizeByProfile.new(
file: '/PDF_to_Optimise.pdf',
profile: 'max',
save_path: 'Optimized.pdf'
)
a.run # safe returns true|false