You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using an object with an interface to generate the PDF. The loop has two functions: Create the page and generate the content on the page. I've noticed that by looping and generating the pages, somehow, it's generating more pages than expected and the content is being distributed among those pages created.
Code sample
This is the interface.
exportinterfacePageInfo{pages: {to:string;pageNumber: number;data:{content: [string|string[],any]|string[];coordinates?: {x: number;y: number;};}[]}[];}```This is the methods ```tsprivateasynccreatePDF(pageInfo:PageInfo,pagesLength:number){returnnewPromise<Buffer>((resolve,reject)=>{console.time('Creating PDF');// Configuração do PdfkitconstpdfDoc=pdfCreateconstbuffers: Buffer[]=[];pdfDoc.on('data',buffers.push.bind(buffers));pdfDoc.on('end',()=>{constpdfData=Buffer.concat(buffers);resolve(pdfData);});for(letj=0;j<pagesLength;j++){pdfDoc.addPage();pdfDoc.switchToPage(j);// bug letdata=pageInfo.pages[j].data;for(leti=0;i<data.length;i++){letcontent=data[i].contentletstringContent=content.toString();let{ x, y }=data[i].coordinates;pdfDoc.text(stringContent,x,y,{align: 'justify',ellipsis: true})}pdfDoc.save();}pdfDoc.end();console.timeEnd('Creating PDF');});}asynccreateAndSavePDF(pageInfo:PageInfo,pagesLength:number,Response){try{constpdfData=awaitthis.createPDF(pageInfo,pagesLength);Response.setHeader('Content-Length',pdfData.length);Response.setHeader('Content-Type','application/pdf');Response.setHeader('Content-Disposition','attachment;filename=out.pdf');Response.end(pdfData);}catch(error){Response.status(500).json({error: error.message});}}
This is the result of a example of PDF:
Your environment
pdfkit version: 0.13
Node version: 18.17
Browser version (if applicable):
Operating System: Ubuntu 18.04.6
The text was updated successfully, but these errors were encountered:
Bug Report
Description of the problem
I'm using an object with an interface to generate the PDF. The loop has two functions: Create the page and generate the content on the page. I've noticed that by looping and generating the pages, somehow, it's generating more pages than expected and the content is being distributed among those pages created.
Code sample
This is the interface.
This is the result of a example of PDF:
Your environment
The text was updated successfully, but these errors were encountered: