mirror of
				https://github.com/Frooodle/Stirling-PDF.git
				synced 2025-11-01 01:21:18 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			32 lines
		
	
	
		
			742 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			742 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
 | 
						|
import { PDFDocument, ParseSpeeds } from 'pdf-lib';
 | 
						|
 | 
						|
export async function scalePage(snapshot: string | Uint8Array | ArrayBuffer, pageSize: {width:number,height:number}): Promise<Uint8Array> {
 | 
						|
    // Load the original PDF file
 | 
						|
    const pdfDoc = await PDFDocument.load(snapshot, {
 | 
						|
        parseSpeed: ParseSpeeds.Fastest,
 | 
						|
    });
 | 
						|
 | 
						|
    const new_size = pageSize;
 | 
						|
 | 
						|
    const pages = pdfDoc.getPages();
 | 
						|
 | 
						|
    pages.forEach(page => {
 | 
						|
        // Change page size
 | 
						|
        page.setSize(new_size.width, new_size.height);
 | 
						|
    });
 | 
						|
 | 
						|
    // Serialize the modified document
 | 
						|
    return pdfDoc.save();
 | 
						|
};
 | 
						|
 | 
						|
export const PageSize = {
 | 
						|
    a4: {
 | 
						|
        width: 594.96,
 | 
						|
        height: 841.92
 | 
						|
    },
 | 
						|
    letter: {
 | 
						|
        width: 612,
 | 
						|
        height: 792
 | 
						|
    }
 | 
						|
}; |