i created page to generate documents in word DOCX and I try to generate word document using this code:
function loadFile(url,callback){
PizZipUtils.getBinaryContent(url,callback);
}
function gen(id, dane) {
$.ajax({
url:"create.php",
method:"post",
data:{id},
success:function(data)
{
dane.numer = data;
generate(dane);
}
});
}
function generate(data) {
loadFile("/doc.docx",function(error,content){
if (error) { throw error };
function replaceErrors(key, value) {
if (value instanceof Error) {
return Object.getOwnPropertyNames(value).reduce(function(error, key) {
error[key] = value[key];
return error;
}, {});
}
return value;
}
function errorHandler(error) {
console.log(JSON.stringify({error: error}, replaceErrors));
if (error.properties && error.properties.errors instanceof Array) {
const errorMessages = error.properties.errors.map(function (error) {
return error.properties.explanation;
}).join("\n");
console.log('errorMessages', errorMessages);
}
throw error;
}
var zip = new PizZip(content);
var doc;
try {
doc=new window.docxtemplater(zip);
} catch(error) {
errorHandler(error);
}
doc.setData(data);
try {
doc.render();
}
catch (error) {
errorHandler(error);
}
var out=doc.getZip().generate({
type:"blob",
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
})
saveAs(out,"Prot "+ data.name +".docx")
})
}
Does anyone know how to convert this word document DOCX to a PDF file on this page? Does anyone know how to convert this word document DOCX to a PDF file on this page?