Spire.PDFViewer is a powerful PDF Viewer component for .NET. It allows developers to load PDF document from stream, file and byte array.

Wed Sep 18, 2019 4:03 pm

I can quite figure this one out I was hoping I could get some help. What I want to do is be able to detect the page orientation and display the page correctly in landscape in the viewer. We mostly have portrait pages but occasionally there are landscape pages.

Also I currently have code to write annotation along the right edge of the page using the spirepdf for .net but I want to be able to ensure that the annotation is placed correctly if the page is landscape.

If this is not feasible an alternative would be to have all of the pages set to portrait but allow the user to rotate the page in the viewer. Either way I'm just trying to understand how the SDK handles the page rotation for an existing file in the viewer.

Thanks!

kodyhackbusch
 
Posts: 1
Joined: Wed Sep 04, 2019 12:27 am

Thu Sep 19, 2019 6:18 am

Hi,

Thanks for your inquiry.
When displaying PDF in Spire.PDFViewer, the PDF will be shown as 100% in viewer by default except there is some settings in viewer. And if the page orientation of PDF is landscape, then the page in viewer will be shown as landscape. Note if the width of PdfViewer is not enough to show the whole page, there will be scroll bar on the bottom of the viewer, you could drag the scroll bar to see the right side of page.

Besides, Spire.PDFViewer doesn't provide methods to detect the page orientation. Our Spire.PDF could judge the width and height of page to detect the page orientation. For example:
Code: Select all
            PdfDocument doc = new PdfDocument(PdfStream);
            PdfPageBase page = doc.Pages[0];
            if (page.Size.Width > page.Size.Height)
            {
                Console.WriteLine("The page orientation is Landscape");
                this.pdfViewer1.Width = page.Size.Width;
                this.pdfViewer1.Height= page.Size.Height;
                this.pdfViewer1.LoadFromStream(stream);
            }
            else
                Console.WriteLine("The page orientation is Portrait");

If there is any question, welcome to get it back to us with detailed information.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDFViewer