Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
save pdf edit to server using pdfannotate

I'm using the jsPDF plugin to create a pdf file. Currently, the method can generate a download file based on the click button. instead of that, I would like to save the file into the server when I click the button. a few research I use jquery.ajax to send the data to the file server.

Code

PDFAnnotate.prototype.savePdf = function() {
        var inst = this;

        var doc = new jspdf.jsPDF();

        inst.fabricObjects.forEach(function(fabricObj, index) {
            if (index != 0) {
                doc.addPage();
                doc.setPage(index + 1);
            }
            doc.addImage(
                fabricObj.toDataURL({
                    format: 'png'
                }),
                inst.pageImageCompression == "NONE" ? "PNG" : "JPEG",
                0,
                0,
                doc.internal.pageSize.getWidth(),
                doc.internal.pageSize.getHeight(),
                `page-${index + 1}`,
                ["FAST", "MEDIUM", "SLOW"].indexOf(inst.pageImageCompression) >= 0 ?
                inst.pageImageCompression :
                undefined
            );
            if (index === inst.fabricObjects.length - 1) {
                var blob = doc.output('blob');
                var formData = new FormData();
                formData.append('pdf', blob);

                var xhr = new XMLHttpRequest();

                xhr.open('POST', baseurl + "wo/replaceFile", true);
                xhr.send('pdf');

            }
        })
    }

Based on xhr.open I call method in controller Wo.php/replaceFile()

if(!empty($_FILES['pdf'])) {
$data = $_POST['pdf'];
$fname = "test.pdf"; // name the file
$file = fopen("testa/pdf/" .$fname, 'w');
fwrite($file, $data); //save data
fclose($file);

} else {
    throw new Exception("no data");
}
?>

But no action happened.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda