Api2Pdf 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Api2Pdf --version 1.0.1                
NuGet\Install-Package Api2Pdf -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Api2Pdf" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Api2Pdf --version 1.0.1                
#r "nuget: Api2Pdf, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Api2Pdf as a Cake Addin
#addin nuget:?package=Api2Pdf&version=1.0.1

// Install Api2Pdf as a Cake Tool
#tool nuget:?package=Api2Pdf&version=1.0.1                

api2pdf.dotnet

.NET bindings for Api2Pdf REST API

Api2Pdf.com is a REST API for instantly generating PDF documents from HTML, URLs, Microsoft Office Documents (Word, Excel, PPT), and images. The API also supports merge / concatenation of two or more PDFs. Api2Pdf is a wrapper for popular libraries such as wkhtmltopdf, Headless Chrome, and LibreOffice.

  • Installation
  • Resources
  • Authorization
  • Usage

Add a dependency

nuget

Run the nuget command for installing the client Install-Package Api2Pdf

Resources

Resources this API supports:

  • wkhtmltopdf
  • Headless Chrome
  • LibreOffice
  • Merge / Concatenate PDFs
  • Helper Methods

Authorization

Acquire API Key

Create an account at portal.api2pdf.com to get an API key.

Usage

Initialize the Client

All usage starts by initializing the client by passing your API key as a parameter to the constructor.

var a2pClient = Api2Pdf("YOUR-API-KEY");

Once you initialize the client, you can make calls like so:

var apiResponse = a2pClient.HeadlessChrome.FromHtml("<p>Hello, World</p>");
Console.WriteLine(apiResponse.Pdf);
Console.ReadLine();

Result Object

An Api2PdfResponse object is returned from every API call. If a call is unsuccessful then success will show False and the error will provide the reason for failure. Additional attributes include the total data usage in, out, and the cost for the API call, typically very small fractions of a penny.

{
    'pdf': 'https://link-to-pdf-only-available-for-24-hours',
    'mbIn': 0.08421039581298828,
    'mbOut': 0.08830547332763672,
    'cost': 0.00017251586914062501,
    'success': True,
    'error': None,
    'responseId': '6e46637a-650d-46d5-af0b-3d7831baccbb'
}

wkhtmltopdf

Convert HTML to PDF

var apiResponse = a2pClient.WkHtmlToPdf.FromHtml("<p>Hello, World</p>");

Convert HTML to PDF (load PDF in browser window and specify a file name)

var apiResponse = a2pClient.WkHtmlToPdf.FromHtml("<p>Hello, World</p>", inline: true, outputFileName: "test.pdf");

Convert HTML to PDF (use dictionary for advanced wkhtmltopdf settings) View full list of wkhtmltopdf options available.

var options = new Dictionary<string, string>();
options.Add("orientation", "landscape");
options.Add("pageSize", "Letter");
var apiResponse = a2pClient.WkHtmlToPdf.FromHtml("<p>Hello, World</p>", options: options);

Convert URL to PDF

var apiResponse = a2pClient.WkHtmlToPdf.FromUrl("http://www.api2pdf.com");

Convert URL to PDF (load PDF in browser window and specify a file name)

var apiResponse = a2pClient.WkHtmlToPdf.FromUrl("http://www.api2pdf.com", inline: true, outputFileName: "test.pdf");

Convert URL to PDF (use dictionary for advanced wkhtmltopdf settings) View full list of wkhtmltopdf options available.

var options = new Dictionary<string, string>();
options.Add("orientation", "landscape");
options.Add("pageSize", "Letter");
var apiResponse = a2pClient.WkHtmlToPdf.FromUrl("http://www.api2pdf.com", options: options);

Headless Chrome

Convert HTML to PDF

var apiResponse = a2pClient.HeadlessChrome.FromHtml("<p>Hello, World</p>");

Convert HTML to PDF (load PDF in browser window and specify a file name)

var apiResponse = a2pClient.HeadlessChrome.FromHtml("<p>Hello, World</p>", inline: true, outputFileName: "test.pdf");

Convert HTML to PDF (use dictionary for advanced Headless Chrome settings) View full list of Headless Chrome options available.

var options = new Dictionary<string, string>();
options.Add("landscape", "true");
var apiResponse = a2pClient.HeadlessChrome.FromHtml("<p>Hello, World</p>", options: options);

Convert URL to PDF

var apiResponse = a2pClient.HeadlessChrome.FromUrl("http://www.api2pdf.com");

Convert URL to PDF (load PDF in browser window and specify a file name)

var apiResponse = a2pClient.HeadlessChrome.FromUrl("http://www.api2pdf.com", inline: true, outputFileName: "test.pdf");

Convert URL to PDF (use dictionary for advanced Headless Chrome settings) View full list of Headless Chrome options available.

var options = new Dictionary<string, string>();
options.Add("landscape", "true");
var apiResponse = a2pClient.HeadlessChrome.FromUrl("http://www.api2pdf.com", options: options);

LibreOffice

LibreOffice supports the conversion to PDF from the following file formats:

  • doc, docx, xls, xlsx, ppt, pptx, gif, jpg, png, bmp, rtf, txt, html

You must provide a url to the file. Our engine will consume the file at that URL and convert it to the PDF.

Convert Microsoft Office Document or Image to PDF

var apiResponse = a2pClient.LibreOffice.Convert("https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx");

Convert Microsoft Office Document or Image to PDF (load PDF in browser window and specify a file name)

var apiResponse = a2pClient.LibreOffice.Convert("https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx", inline: true, outputFileName: "test.pdf");

Merge / Concatenate Two or More PDFs

To use the merge endpoint, supply a list of urls to existing PDFs. The engine will consume all of the PDFs and merge them into a single PDF, in the order in which they were provided in the list.

Merge PDFs from list of URLs to existing PDFs

var links_to_pdfs = new List<string>() {"https://LINK-TO-PDF", "https://LINK-TO-PDF"};
var apiResponse = a2pClient.Merge(links_to_pdfs);

Merge PDFs from list of URLs to existing PDFs (load PDF in browser window and specify a file name)

var links_to_pdfs = new List<string>() {"https://LINK-TO-PDF", "https://LINK-TO-PDF"};
var apiResponse = a2pClient.Merge(links_to_pdfs, inline: true, outputFileName: "test.pdf");

Helper Methods

void Api2PdfResponse.SavePdf(string localPath)

On any Api2PdfResponse that succesfully generated a pdf, you can use the handy SavePdf(string localPdf) method to download the pdf to a local cache.

var a2pClient = Api2Pdf("YOUR-API-KEY");
var links_to_pdfs = new List<string>() {"https://LINK-TO-PDF", "https://LINK-TO-PDF"};
var apiResponse = a2pClient.Merge(links_to_pdfs, inline: true, outputFileName: "test.pdf");
apiResponse.SavePdf("path-to-local-folder");

byte[] Api2PdfResponse.GetPdfBytes()

You can use GetPdfBytes() method to download the pdf to a byte array.

var a2pClient = Api2Pdf("YOUR-API-KEY");
var links_to_pdfs = new List<string>() {"https://LINK-TO-PDF", "https://LINK-TO-PDF"};
var apiResponse = a2pClient.Merge(links_to_pdfs, inline: true, outputFileName: "test.pdf");
apiResponse.GetPdfBytes();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Api2Pdf:

Package Downloads
Olivitec.Framework.Converter.Pdf

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.1 105,246 2/2/2023
2.1.0 80,886 3/13/2022
2.0.1 22,385 10/10/2021
2.0.0 13,035 7/10/2021
2.0.0-rc 308 6/12/2021
1.1.0 132,518 1/27/2019
1.0.1 8,165 6/22/2018
1.0.0 1,141 6/20/2018