View Source Api2pdf (Api2pdf v0.3.0)
Api2pdf
API client for PDF generator/converter service https://www.api2pdf.com.
At this point only features that are related to PDF generation and conversion that are supported as those are the ones that I'm currently using.
Contribution are welcomed to add/fix features or simply open a ticket for feature requests or bug report. If you're looking for API clients in other languages please check their official repository.
Below are lists of features that are supported and those that are not, grouped by their engine:
headless-chrome
Headless Chrome
- [x] html_to_image (
Api2pdf.Chrome.html_to_image/2
) - [x] html_to_pdf (
Api2pdf.Chrome.html_to_pdf/2
) - [x] url_to_image (
Api2pdf.Chrome.url_to_image/2
) - [x] url_to_pdf(
Api2pdf.Chrome.url_to_pdf/2
)
wkhtml
Wkhtml
- [x] html_to_pdf (
Api2pdf.Wkhtml.html_to_pdf/2
) - [x] url_to_pdf (
Api2pdf.Wkhtml.url_to_pdf/2
)
libre-office
Libre Office
- [x] any_to_pdf (
Api2pdf.LibreOffice.any_to_pdf/2
) - [x] any_to_image (
Api2pdf.LibreOffice.any_to_image/2
) - [x] pdf_to_html (
Api2pdf.LibreOffice.pdf_to_html/2
) - [x] html_to_docx (
Api2pdf.LibreOffice.html_to_docx/2
) - [x] html_to_xlsx (
Api2pdf.LibreOffice.html_to_xlsx/2
)
pdfsharp
PdfSharp
- [ ] merge_pdfs
- [ ] bookmark_pdf
- [ ] password_pdf
- [ ] extract_pdf
- [ ] compress_pdf
zxing-bar-codes-generator
ZXING (Bar codes generator)
- [ ] generate_barcode
utility-commands
Utility Commands
- [x] check_balance (
Api2pdf.balance/1
) - [x] delete_file (
Api2pdf.delete_file/2
) - [x] zip_files (
Api2pdf.zip_files/2
) - [x] api_status (
Api2pdf.status/1
)
installation
Installation
Add api2pdf
to your list of dependencies in mix.exs
:
def deps do
[
{:api2pdf, "~> 0.3"}
]
end
api-key
API Key
Api2pdf service requires API key to be able to access their endpoints which you can get by creating an account on their membership portal site.
Once you have API key, you can pass it to this Api2pdf
client in two ways.
via-application-config
Via application config
# file: config.exs
config :api2pdf,
api_key: "YOUR-API-KEY"
via-options
Via options
All functions accept optional Keyword
list where you can pass the api_key
and some other configuration.
Api2pdf.Chrome.url_to_pdf("https://example.com", api_key: "YOUR-API-KEY")
engines
Engines
Api2pdf service uses multiple engines to generate PDF and doing document conversions that you can choose from. Which one to use? It's up to your preference.
You can switch between those engines by using separate modules, they are:
Link to this section Summary
Functions
Utility command to check your balance on https://portal.api2pdf.com.
Delete a file on command instead of waiting 24 hours for self-delete.
HTTP response handling.
Returns HTTP client.
Api2pdf API health check.
Create a ZIP file from a list of files.
Link to this section Functions
Utility command to check your balance on https://portal.api2pdf.com.
https://app.swaggerhub.com/apis-docs/api2pdf/api2pdf/2.0.0#/Utility%20Commands/balanceCheck
examples
Examples
# api_key in config.exs
{:ok, 5.0} = Api2pdf.balance()
# OR, api_key as option
{:ok, 5.0} = Api2pdf.balance(api_key: "YOUR-API-KEY")
@spec delete_file( String.t(), keyword() ) :: {:ok, Api2pdf.Model.ApiSuccessResponse.t()} | {:error, any()}
Delete a file on command instead of waiting 24 hours for self-delete.
https://app.swaggerhub.com/apis-docs/api2pdf/api2pdf/2.0.0#/Utility%20Commands/fileDELETE
examples
Examples
response_id = "857af41a-b382-4c61-ace4-95be78dcd605"
# api_key in config.exs
{:ok, _} = Api2pdf.delete_file(response_id)
# OR, api_key as option
{:ok, _} = Api2pdf.delete_file(response_id, api_key: "YOUR-API-KEY")
HTTP response handling.
@spec http_client() :: any()
Returns HTTP client.
@spec status(keyword()) :: :ok | :error
Api2pdf API health check.
https://app.swaggerhub.com/apis-docs/api2pdf/api2pdf/2.0.0#/Utility%20Commands/statusCheck
examples
Examples
# api_key in config.exs
:ok = Api2pdf.status()
# OR, api_key as option
:ok = Api2pdf.status(api_key: "YOUR-API-KEY")
@spec zip_files( Api2pdf.Model.ZipFilesRequest.t(), keyword() ) :: {:error, any()} | {:ok, Api2pdf.Model.ApiSuccessResponse.t()}
Create a ZIP file from a list of files.
https://app.swaggerhub.com/apis-docs/api2pdf/api2pdf/2.0.0#/Utility%20Commands/filesZip
examples
Examples
alias Api2pdf.Model.ZipFilesRequest
files = ZipFilesRequest.new()
|> ZipFilesRequest.add("https://example.com/halo.png")
|> ZipFilesRequest.add("https://example.com/hola.png", "new-name.png")
# api_key in config.exs
{:ok, _} = Api2pdf.zip_files(files)
# OR, api_key as option
{:ok, _} = Api2pdf.zip_files(files, api_key: "YOUR-API-KEY")