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

224
Visualizações
What filetype do I need to make image in docs to work?

I use docxtemplater to place my image in docx file but it keeps ending up an error image Like this

I tried sending it as filelist, base64 , buffer but it never works

this is my code, thank you in advanced.

export const generateDocument = async (data, file, setFile) => {

  const opts = {
    centered: true,
    getImage: function (tagValue, tagName) {

      return PizZipUtils.getBinaryContent(data.imageData[0], (error, content) => content);
    },
    getSize: function (img, tagValue, tagName) {
      return [110, 130];
    },
  };

  loadFile(data.logo === "BBS" ? './BBS.docx' : "./PPT.docx", (error, content) => {
    if (error) {
      throw error;
    }
    let zip = new PizZip(content);
    let doc = new Docxtemplater(zip, {
      modules: [new ImageModule(opts)],
      paragraphLoop: true,
      linebreaks: true
    });
    doc.setData({...data});


    // render the document (replace all occurences of {first_name} by John, {last_name} by Doe, ...)
    doc.render();

    let out = doc.getZip().generate({
      type: "blob",
      mimeType: "docxType",
    });
    saveAs(out, 'Resume.docx');
  });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There may be other ways, but it definitely works if your getImage() function returns an ArrayBuffer with the image data. Buffer seems to be part of node.js. If your code runs in the browser, you can npm install buffer.

If your image data is base64 encoded, you could use this conversion function:

import { Buffer } from "buffer";

function base64DataURLToArrayBuffer(stringBase64) {
  const binaryString = window.atob(stringBase64);
  const len = binaryString.length;
  const bytes = Buffer.alloc(len, 0);
  for (let i = 0; i < len; i += 1) {
    const ascii = binaryString.charCodeAt(i);
    bytes[i] = ascii;
  }
  return bytes;
}
about 4 years ago · Juan Pablo Isaza Relatório
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