Get the width and height of the document pages
Leave feedback
You can get the width and height of each document page using the getViewInfo method that returns a ViewInfo object. Use the getPages method to access the collection that contains each Page of the document.
The following code snippet shows how to get the width and height of each document page:
importcom.groupdocs.viewer.Viewer;importcom.groupdocs.viewer.options.ViewInfoOptions;importcom.groupdocs.viewer.results.ViewInfo;// ...
try(Viewerviewer=newViewer("sample.pdf")){// Get file information.
ViewInfoOptionsviewInfoOptions=ViewInfoOptions.forHtmlView();ViewInfoviewInfo=viewer.getViewInfo(viewInfoOptions);// Display width and height of each page.
for(Pagepage:viewInfo.getPages()){System.out.println("Page: "+page.getNumber()+"; Width: "+page.getWidth()+", pixels");System.out.println("Page: "+page.getNumber()+"; Height: "+page.getHeight()+", pixels");}}
The following image shows a sample console output:
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.