Search code examples
azure-blob-storagepdfkit

Create and upload PDF to azure blob storage


I'm using PDFkit to create a PDF, however I want to upload the created PDF to azure blob storage. I have the below code (typescript) but its not working:

const doc = new PDFDocument();
doc.fontSize(27).text("test", 100, 100);
doc.end();

const uploadBlobResponse = await blockBlobClient.upload(
      doc,
      Buffer.byteLength(doc)
    );

i'm able to connect to the azure blob storage, however the uploading part is not working


Solution

  • I have tested in my environment

    You can use the below code to upload PDF file from PDFKIT to Azure Blob Storage

    const PDFDocument = require('pdfkit');
    const fs = require('fs');
    const blobName = "doc.pdf";
    const doc = new PDFDocument();
    doc.pipe(fs.createWriteStream(blobName));
    doc.fontSize(27).text("test", 100, 100);
    doc.end();
    
    const uploadBlobResponse = await blockBlobClient.uploadFile(blobName);