@cincel.digital/doc-convert-request
@cincel.digital/doc-convert-request is a package designed to connect with @cincel.digital/doc-convert-plugin, a Hapi plugin that converts documents to PDF. This package provides HTTP-related functionality for document conversion.
Installation
yarn add @cincel.digital/doc-convert-request
# or
npm i @cincel.digital/doc-convert-request
Usage
To use this package, you need to import the function http
from
@cincel.digital/doc-convert-request.
Converting a File to PDF
The http
function allows you to convert a file to PDF by sending an HTTP
POST request to the specified URL. The function takes two parameters: the URL
and the file to be converted.
import { request } from "@cincel.digital/doc-convert-request"
const upload =
const filepicker = document.getElementById("filepicker") as HTMLInputElement
filepicker.addEventListener("change", (event) => {
const file = event.target.files?.[0]
if (!file) return
request("http://example.com/convert", file)
.then((pdfFile) => {
return pdfFile
})
.catch((err) => {
console.error(err)
})
})
Downloading a Raw URL
The downloadRawURL
function allows you to generate a download URL for a
PDF file. It takes a File object as input and returns a URL that can be used for
downloading the file.
import { request, downloadRawURL } from "@cincel.digital/doc-convert-request"
const filepicker = document.getElementById("filepicker") as HTMLInputElement
filepicker.addEventListener("change", (event) => {
const file = event.target.files?.[0]
if (!file) return
request("http://example.com/convert", file)
.then((pdfFile) => {
const downloadRawURL = downloadRawURL(pdfFile)
window.open(downloadRawURL, "_blank")
return pdfFile
})
.catch((err) => {
console.error(err)
})
})
Please note that the @cincel.digital/doc-convert-plugin plugin is required for the proper functioning of this package. Make sure to install and configure the plugin according to its documentation before using @cincel.digital/doc-convert-request.