How to get page width and height for each page in pdf.js?
Refer to https://github.com/mozilla/pdf.js/blob/25c7a8c215fe5eccc6a14ab209a8bbea226e9520/examples/learning/prevnext.html#L64. Closing as answered.
Try this:
pdf.getPage(page_index).then(page => {
console.log(page.view);
});
@pavex what is unit of coordinates.it is a px or pt ??
@afidosstar pixels
hi, it is means canvas document size.
but i want the whole pagesize...
the data is in page.view: [left, top, width, height]
Here is an example that I have used. This will scale the PDF viewer to have a full page width. Then, it will resize the canvas to match the full size of the PDF page.
pdfDoc.getPage(num).then(function(page) {
canvas.width = document.body.clientWidth;
let scale = (canvas.width / page.view[2]);
let viewport = page.getViewport({scale: scale});
canvas.height = page.view[3] * scale;
// Render PDF page into canvas context
var renderContext = {
canvasContext: ctx, // Initialized in a higher scope using: ctx = canvas.getContext('2d');
viewport: viewport
};
var renderTask = page.render(renderContext);
// etc.
}
Most helpful comment
Here is an example that I have used. This will scale the PDF viewer to have a full page width. Then, it will resize the canvas to match the full size of the PDF page.