Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / PrintFit Method
Example





In This Topic
    PrintFit Method (GdPicturePDF)
    In This Topic
    Prints the currently loaded PDF document to the active printer. The size of the document's pages is automatically adjusted to the actual paper size.
    Syntax
    'Declaration
     
    
    Public Function PrintFit() As GdPictureStatus
    public GdPictureStatus PrintFit()
    public function PrintFit(): GdPictureStatus; 
    public function PrintFit() : GdPictureStatus;
    public: GdPictureStatus PrintFit(); 
    public:
    GdPictureStatus PrintFit(); 

    Return Value

    A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

    We strongly recommend always checking this status first.

    Remarks
    Please note that you can use the PrintGetStat method to identify the specific reason for the printing failure.

    You also need to be aware that annotations and form fields included in the document are rendered by default using this method when printing.

    Just to inform you, that sometimes pages in the PDF document may have defined their internal rotation, which causes them to be unexpectedly rotated when printing. Then you need to use the NormalizePage method for each such page to remove that rotation. You can also use the GetPageRotation method to find out if the page should be rotated when printed.

    Example
    How to print the current document so the document's pages are adjusted to the specified paper size.
    Dim caption As String = "Example: PrintFit"
    Using oGdPicturePDF As New GdPicturePDF()
        If oGdPicturePDF.LoadFromFile("document_to_print.pdf", False) = GdPictureStatus.OK Then
            Dim ps As New System.Drawing.Printing.PaperSize("My Custom Size", 850, 1100)
            oGdPicturePDF.PrintSetPaperSize(ps)
            If oGdPicturePDF.PrintFit() = GdPictureStatus.OK Then
                MessageBox.Show("The file has been printed successfully.", caption)
            Else
                Dim message As String = "The file can't be printed." + vbCrLf + "Status: " + oGdPicturePDF.PrintGetStat().ToString()
                If oGdPicturePDF.PrintGetStat() = GdPictureStatus.PrintingException Then
                    message = message + "    Error: " + oGdPicturePDF.PrintGetLastError()
                End If
                MessageBox.Show(message, caption)
            End If
            oGdPicturePDF.CloseDocument()
        Else
            MessageBox.Show("The file can't be loaded. Status: " + oGdPicturePDF.GetStat().ToString(), caption)
        End If
    End Using
    string caption = "Example: PrintFit";
    using (GdPicturePDF oGdPicturePDF = new GdPicturePDF())
    {
        if (oGdPicturePDF.LoadFromFile("document_to_print.pdf", false) == GdPictureStatus.OK)
        {
            System.Drawing.Printing.PaperSize ps = new System.Drawing.Printing.PaperSize("My Custom Size", 850, 1100);
            oGdPicturePDF.PrintSetPaperSize(ps);
            if (oGdPicturePDF.PrintFit() == GdPictureStatus.OK)
            {
                MessageBox.Show("The file has been printed successfully.", caption);
            }
            else
            {
                string message = "The file can't be printed.\nStatus: " + oGdPicturePDF.PrintGetStat().ToString();
                if (oGdPicturePDF.PrintGetStat() == GdPictureStatus.PrintingException)
                    message = message + "    Error: " + oGdPicturePDF.PrintGetLastError();
                MessageBox.Show(message, caption);
            }
            oGdPicturePDF.CloseDocument();
        }
        else
        {
            MessageBox.Show("The file can't be loaded. Status: " + oGdPicturePDF.GetStat().ToString(), caption);
        }
    }
    See Also