Occasionally page info is wrong

I am using the PDFTron webviewer. Works great with most PDFs however, occasionally I get the wrong width and height with pageInfo.

I store annotations that the user makes on the browser using the approach below:

  1. I first get the page width / height using getPageInfo and store it in my java code:

docViewer.on(‘documentLoaded’, async () => {

// docViewer.on(‘documentLoaded’, function() {

await PDFNet.initialize();

const doc = await docViewer.getDocument().getPDFDoc();

pageCount = docViewer.getDocument().getPageCount()

dims = “”;

var i;

for(i=0;i<pageCount;i++) {

pi = docViewer.getDocument().getPageInfo(i);





  1. I then record annotation XML using below code:

annotManager.on(‘annotationChanged’, (annotations, action, { imported }) => {

if (imported) {return;}

const annots = annotManager.getAnnotCommand();

annots.then(function(val) {




Step 1 gave me page dimension of: 612 and 792 respectively for width and height.

Step 2 gave me annotation like below when I choose some text at bottom right of a PDF, which seems incorrect to me because the x2 co-ordinate is greater than page width.

x1=403.238095, y1=234.214286, x2=696.761905, y2=258.309524

Full XML from point 2:

<?xml version="1.0" encoding="UTF-8" ?>

This really throws off any custom annotation I want to add to the page since my page width & height calcs are wrong. Any idea on what I could be doing wrong here.



Hi Anand,

Would it be possible to provide the file along with the annotation you have added?

This is so that it can help us investigate further of what is going on.

Anthony Chen

Software Developer
PDFTron Systems, Inc.