Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / ClearPageContent Method

ClearPageContent Method (GdPicturePDF)

In This Topic
Empties, that means completely removes, the whole content of the currently selected page in the loaded PDF document. The selected page becomes blank, but it retains its properties, for example, page dimensions or the rotation.
Syntax
'Declaration
 
Public Function ClearPageContent() As GdPictureStatus
public GdPictureStatus ClearPageContent()
public function ClearPageContent(): GdPictureStatus; 
public function ClearPageContent() : GdPictureStatus;
public: GdPictureStatus ClearPageContent(); 
public:
GdPictureStatus ClearPageContent(); 

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
This method is only allowed for use with non-encrypted documents.
Example
How to remove the whole content of the first page in the PDF document.
Dim caption As String = "Example: ClearPageContent"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
    Dim count As Integer = gdpicturePDF.GetPageCount()
    Dim status As GdPictureStatus = gdpicturePDF.GetStat()
    If status = GdPictureStatus.OK Then
        If count > 0 Then
            status = gdpicturePDF.SelectPage(1)
            If status = GdPictureStatus.OK Then
                status = gdpicturePDF.ClearPageContent()
                If status = GdPictureStatus.OK Then
                    Dim message As String = "The pages have been cleared successfully"
                    If gdpicturePDF.SaveToFile("test_ClearPageContent.pdf") = GdPictureStatus.OK Then
                        message = message + " and the file has been saved."
                    Else
                        message = message + ", but the file can't be saved."
                    End If
                    MessageBox.Show(message, caption)
                Else
                    MessageBox.Show("The ClearPageContent() method has failed with the status: " + status.ToString(), caption)
                End If
            Else
                MessageBox.Show("The page can't be selected.", caption)
            End If
        Else
            MessageBox.Show("This document contains no pages.", caption)
        End If
    Else
        MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption)
    End If
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: ClearPageContent";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
    int count = gdpicturePDF.GetPageCount();
    GdPictureStatus status = gdpicturePDF.GetStat();
    if (status == GdPictureStatus.OK)
    {
        if (count > 0)
        {
            status = gdpicturePDF.SelectPage(1);
            if (status == GdPictureStatus.OK)
            {
                status = gdpicturePDF.ClearPageContent();
                if (status == GdPictureStatus.OK)
                {
                    string message = "The pages have been cleared successfully";
                    if (gdpicturePDF.SaveToFile("test_ClearPageContent.pdf") == GdPictureStatus.OK)
                        message = message + " and the file has been saved.";
                    else
                        message = message + ", but the file can't be saved.";
                    MessageBox.Show(message, caption);
                }
                else
                    MessageBox.Show("The ClearPageContent() method has failed with the status: " + status.ToString(), caption);
            }
            else
                MessageBox.Show("The page can't be selected.", caption);
        }
        else
            MessageBox.Show("This document contains no pages.", caption);
    }
    else
        MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption);
}
else
    MessageBox.Show("The file can't be loaded.", caption);
gdpicturePDF.Dispose();
See Also