File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -153,18 +153,16 @@ export class PdfService {
153153 const images = await pdfToPng ( buffer as any , {
154154 viewportScale : this . cfg . pngQuality ,
155155 } ) ;
156- const oldPdf = await PDFDocument . load ( buffer ) ;
157156 const newPdf = await PDFDocument . create ( ) ;
158157 for ( let i = 0 ; i < images . length ; i ++ ) {
159158 const image = images [ i ] ;
160- const oldPage = oldPdf . getPage ( i ) ;
161159 const img = await newPdf . embedPng ( image . content ) ;
162- const page = newPdf . addPage ( [ oldPage . getWidth ( ) , oldPage . getHeight ( ) ] ) ;
160+ const page = newPdf . addPage ( [ image . width , image . height ] ) ;
163161 page . drawImage ( img , {
164162 x : 0 ,
165163 y : 0 ,
166- width : oldPage . getWidth ( ) ,
167- height : oldPage . getHeight ( ) ,
164+ width : image . width ,
165+ height : image . height ,
168166 } ) ;
169167 }
170168 this . logger . log ( `Converted PDF to image and back to PDF` ) ;
You can’t perform that action at this time.
0 commit comments