GdPicture.NET.14
GdPicture14 Namespace / GdViewer Class / PdfGetPageWidth Method
Example





In This Topic
PdfGetPageWidth Method (GdViewer)
In This Topic
Returns the page width in PDF point units of the currently selected page in the displayed PDF document. If the document currently displayed in the GdViewer control is not the PDF file, the method will fail.
Syntax
'Declaration
 
Public Function PdfGetPageWidth() As Double
public double PdfGetPageWidth()
public function PdfGetPageWidth(): Double; 
public function PdfGetPageWidth() : double;
public: double PdfGetPageWidth(); 
public:
double PdfGetPageWidth(); 

Return Value

The page height in points. The GetStat method can be subsequently used to determine if this method has been successful.
Remarks
This method is only meaningful for PDF documents, otherwise it returns 0. It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any.

Just to inform you that 1 point = 1/72 inch. For example, to get the current page width in inches, use Width = PdfGetPageWidth() / 72, similarly to get the page width in centimeters, use Width = PdfGetPageWidth() / 72 * 2.54.

Example
How to retrieve the page height of the currently displayed page of the loaded PDF document.
'We assume that the GdViewer1 control has been properly integrated.
If GdViewer1.DisplayFromFile("") = GdPictureStatus.OK Then
    Dim message As String = "The current file is: " + GdViewer1.GetLastPath()
    If GdViewer1.GetDocumentType() = DocumentType.DocumentTypePDF Then
        message += vbCrLf + "Number of pages: " + GdViewer1.PageCount.ToString() +
                   vbCrLf + "Page height: " + (GdViewer1.PdfGetPageHeight()) / 72 * 2.54 + " cm" +
                   vbCrLf + "Page width: " + (GdViewer1.PdfGetPageWidth()) / 72 * 2.54 + " cm"
    Else
        message += vbCrLf + "This file is not a PDF document, its format is: " + GdViewer1.GetDocumentType().ToString()
    End If
            
    MessageBox.Show(message, "GdViewer.PdfGetPageHeight")
Else
    MessageBox.Show("The file can't be loaded. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.PdfGetPageWidth")
End If
//We assume that the GdViewer1 control has been properly integrated.
if (GdViewer1.DisplayFromFile("") == GdPictureStatus.OK)
{
    string message = "The current file is: " + GdViewer1.GetLastPath();
    if (GdViewer1.GetDocumentType() == DocumentType.DocumentTypePDF)
    {
        message += "\nNumber of pages: " + GdViewer1.PageCount.ToString() +
                   "\nPage height: " + (GdViewer1.PdfGetPageHeight())/72*2.54 +
                   " cm\nPage width: " + (GdViewer1.PdfGetPageWidth())/72*2.54 + " cm";
    }
    else
    {
        message += "\nThis file is not a PDF document, its format is: " + GdViewer1.GetDocumentType().ToString();
    }
    MessageBox.Show(message, "GdViewer.PdfGetPageWidth");
}
else
    MessageBox.Show("The file can't be loaded. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.PdfGetPageWidth");
See Also