Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
convertapi-js
Advanced tools
The ConvertAPI helps converting various file formats. Creating PDF and Images from various sources like Word, Excel, Powerpoint, images, web pages. Merge, Encrypt, Split, Repair and Decrypt PDF files. And many others files manipulations. In just few minutes you can integrate it into your application and use it easily.
The ConvertAPI-JS library makes it easier to use the Convert API from your web projects without having to build your own API calls. You can get your free API secret at https://www.convertapi.com/a
Run this line from console:
npm i convertapi-js
You can get your secret at https://www.convertapi.com/a
let convertApi = ConvertApi.auth({secret: '<YOUR_SECRET>'})
Example to convert DOCX file to PDF. All supported formats and options can be found here.
let params = convertApi.createParams()
params.add('file', elFileInput.files[0])
let result = await convertApi.convert('docx', 'pdf', params)
// Get result file URL
let url = result.files[0].Url
let params = convertApi.createParams()
params.add('file', new URL('https://cdn.convertapi.com/test-files/presentation.pptx'))
let result = await convertApi.convert('pptx', 'pdf', params)
// Get result file URL
let url = result.files[0].Url
ConvertAPI accepts extra conversion parameters depending on converted formats. All conversion parameters and explanations can be found here.
// Converting PDF to JPG file
let params = convertApi.createParams()
params.add('file', e.currentTarget.files[0])
params.add('ScaleImage', 'true')
params.add('ScaleProportions', 'true')
params.add('ImageHeight', '300')
params.add('ImageWidth', '300')
let result = await convertApi.convert('pdf', 'jpg', params)
// Get result file URL
let url = result.files[0].Url
You can find more advanced examples in the examples folder.
ConvertAPI is designed to make converting file super easy, the following snippet shows how easy it is to get started. Let's convert WORD DOCX file to PDF:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Conversion Example</title>
<script src="https://unpkg.com/convertapi-js/lib/convertapi.js"></script>
</head>
<body>
<h1>ConvertAPI JavaScript library example</h1>
<h2>Conversion Example</h2>
<p>
<label for="fileInput">Select DOCX file to convert it to PDF</label>
<input id="fileInput" type="file" accept="application/vnd.openxmlformats-officedocument.wordprocessingml.document">
</p>
<p id="result">
Result file:
<a id="resultLink" href=""></a>
</p>
<script src="index.js"></script>
</body>
</html>
let convertApi = ConvertApi.auth({secret: '<YOUR_SECRET>'})
let elResult = document.getElementById('result')
let elResultLink = document.getElementById('resultLink')
elResult.style.display = 'none'
// On file input change, start conversion
document.getElementById('fileInput').addEventListener('change', async e => {
elResult.style.display = 'none'
document.documentElement.style.cursor = 'wait'
try {
// Converting DOCX to PDF file
let params = convertApi.createParams()
params.add('file', e.currentTarget.files[0])
let result = await convertApi.convert('docx', 'pdf', params)
// Showing link with the result file
elResultLink.setAttribute('href', result.files[0].Url)
elResultLink.innerText = result.files[0].Url
elResult.style.display = 'block'
} finally {
document.documentElement.style.cursor = 'default'
}
})
This is the bare-minimum to convert a file using the ConvertAPI client, but you can do a great deal more with the ConvertAPI JS library.
Take special note that you should replace <YOUR_SECRET>
with the secret you obtained in item two of the pre-requisites.
Please leave all comments, bugs, requests, and issues on the Issues page. We'll respond to your request ASAP!
The ConvertAPI JS Library is licensed under the MIT license. Refere to the LICENSE file for more information.
FAQs
ConvertApi JavaScript and TypeScript library
The npm package convertapi-js receives a total of 866 weekly downloads. As such, convertapi-js popularity was classified as not popular.
We found that convertapi-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.