JSFiddle - React, Tailwind, and code Playground
by Jonas Jasas
HTML
<h1>JPG to PDF example</h1>
<p>
<label for="secret">Your secret:</label>
<input type="text" id="secret">
</p>
<p>
<label for="fileInput">Select JPG file:</label>
<input type="file" id="fileInput" accept=".jpg">
</p>
<a id="result"></a>
JavaScript
$('#fileInput').on('change', () => {
var fd = new FormData()
fd.append('file', $('#fileInput')[0].files[0])
$('#result').text('Converting...').attr('href', null)
$.ajax({
method: 'POST',
url: 'https://v2.convertapi.com/convert/jpg/to/pdf?storefile=true&secret=' + $('#secret').val(),
data: fd,
processData: false,
contentType: false,
})
.done((res) => {
$('#result').text('Download').attr('href', res.Files[0].Url)
})
.fail(() => $('#result').text('Error :('))
})