'use strict'
const gs = require("ghostscript-node");
const fs = require('fs');
const { PDFDocument, rgb, StandardFonts } = require('pdf-lib');
const pdf2json = require('pdf2json');
const pdf = require('pdfkit');
const http = require('https');
const FormData = require('form-data');
const base64 = require('base64topdf');
convertToPDFA2: async function () {
const pdf = fs.readFileSync("path input.pdf")
var username = '';
var password = '';
var auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
const formData = new FormData();
formData.append('file', pdf, {
filename: 'file.pdf',
contentType: 'application/pdf'
});
const options = {
port: 8243,
path: '/mustang-doc/v1.0.0/mustang/pdf?pdfAVersion=1',
method: 'POST',
headers: {
Authorization: auth,
'Content-Type': "multipart/form-data; boundary=" + formData.getBoundary(),
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
fs.writeFileSync("path output.pdf", data);
});
});
req.on('error', (e) => {
console.error(`Problem with request: ${e.message}`);
});
formData.pipe(req);
req.end();
}
}