jspdfchange ppi to 300 in javascript

You can set the resolution of the generated PDF document in jsPDF() constructor method using the putUserUnit and setRatiotUserUnit methods. Here is an example of how to create a PDF with resolution of 300ppi:

index.tsx
const doc = new jsPDF('p', 'pt', [595.28, 841.89]);
// Convert pixel to inches 
const pxToInches = 1/96;
const width = 8.5 / pxToInches;
const height = 11 / pxToInches;

doc.putUserUnit('pt');
doc.setRatiotUserUnit(1/72);

// Set the PDF size to 8.5 x11 inches
doc.internal.pageSize.setWidth(width*72);
doc.internal.pageSize.setHeight(height*72);

// Render your page here
doc.text('Hello World!', 20, 20);

// Save the PDF with resolution of 300ppi
doc.save('example.pdf');
475 chars
19 lines

In this example, we used the putUserUnit method to set the page unit to points where 1pt = 1/72 inch. We also used setRatiotUserUnit method to set ratio to 1/72, so that we can calculate our page size units more easily.

This example creates a PDF with dimensions (in inches) of 8.5 by 11 in portrait format. We converted the inch dimensions to points and then multiplied by 72 to get the size of the PDF page. Finally, we rendered some text on the PDF and saved the output.

related categories

gistlibby LogSnag