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

505
Visualizações
How can I convert a .docx file from a server with mammoth?

I have just installed mammoth.browser.min (v. 1.2.0) and, using an HTML tag as shown in the docs, tested it successfully on .docx files to be displayed in the browser.

Then I tried to implement parseWordDocxFile through a different interface: after loading files onto a server using $.post, I display them as a list. From this list, any line can be double-clicked like so:

let myFile = {"reference": reference, "type": type};
openDocument (myFile);

" reference " and "type" are retrieved from a $.get request: "reference" is the full path to the intended file; "type" is the file type.

The signature of the callee is openDocument (theFile). This function includes a switch:

switch (theFile.type)
{
       case 'pdf': case 'PDF': case 'PNG': case 'png': case 'JPEG': case 'jpg': case 'JPG':
         window.open ( file.reference ); // browser handles it directly
      break;               
      case 'docx': parseWordDocxFile(file.reference);  break; // full path to the file, checked
}

For file types .pdf, .png, .jpg, is works smoothly.

Now, as to .docx files, it avails to nothing. Upon entering parseWordDocxFile, Debugger says:

TypeError: FileReader.readAsArrayBuffer: Argument 1 is not an object

BUT if I copy back the file from the server onto my local disk and try and open it with the HTML interface (ditto), it works. In other words there is nothing wrong with the file stored on the server.

I surmise that I might pass parseWordDocxFile(theFile) an file object like so:

var objFile = new File ( [data], // type:= []
                            "Sample.docx", // full path correct
                            {
                                type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", // type displayed on debugging
                                lastModified: 1650875824000
                            }

but I have no clue as to what data would be.

What is it I am doing wrong? What is the right way to get it working?

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