How can I get a document's dimensions with PrizmDoc?

Question

How can I get a document’s dimensions with PrizmDoc?

Answer

There are two methods you can use to do this with PrizmDoc:

The first method is using the requestPageAttributes() method from ViewerControl. This method allows you to get the width and height of a page in the document in pixels. Below is sample code on how to use requestPageAttributes() to get the attributes of page 1 of a document:

viewerControl.requestPageAttributes(1).then(function(attributes) {
    var pageWidth = attributes.width;
    var pageHeight = attributes.height;
});

The second method is done by making a GET request to the PrizmDoc server to get metadata for a page of the source document in a viewing session. The request is:

GET /PCCIS/V1/Page/q/{{PageNumber}}/Attributes?DocumentID=u{{viewingSessionId}}&ContentType={{ContentType}}

The content type needs to be set to “png” for raster content and “svgb” for SVG content. The request returns the data in a JSON object containing the image’s width and height. The units for the width and height are in pixels when the contentType is set to “png” and unspecified units when the content type is set to “svgb”.

The request also returns the horizontal and vertical resolution of raster content when the content type is set to “png”. This information is similar to pixels per inch, but the units are unspecified, so if you wanted to calculate the size of the document you can calculate it by width divided by horizontal resolution or height divided by vertical resolution. The resolution is hard-coded to 90 when contentType is set to “svgb”.