GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / NewPDF Method / NewPDF() Method
Example





In This Topic
NewPDF() Method
In This Topic
Prepares a brand new empty PDF document within a GdPicturePDF object. You will always need an object of the GdPicturePDF class to create a new PDF document. Please note that a newly created GdPicturePDF object does not automatically create a new PDF document. The created PDF document also does not contain any pages. You are also able to reuse the created GdPicturePDF object for manipulation with another PDF document simply by calling this method again.
Syntax
'Declaration
 
Public Overloads Function NewPDF() As GdPictureStatus
public GdPictureStatus NewPDF()
public function NewPDF(): GdPictureStatus; 
public function NewPDF() : GdPictureStatus;
public: GdPictureStatus NewPDF(); 
public:
GdPictureStatus NewPDF(); 

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
Just to inform you, that the toolkit will create the PDF document conformed to the lowest PDF version (version 1.3 is the minimum) based on what the output PDF document will contain. This is the same as what the NewPDF(PdfConformance) method does if you use the PdfConformance.PDF parameter.

The origin's location and the measurement unit for any newly created document are reset to their default values: PdfOrigin.PdfOriginBottomLeft, PdfMeasurementUnit.PdfMeasurementUnitPoint.

Example
How to create a new single page PDF document with the Hello World written in the middle of the first page.
Using gdpicturePDF As New GdPicturePDF()
    'A brand new empty document without any page.
    Dim status As GdPictureStatus = gdpicturePDF.NewPDF()
    If status = GdPictureStatus.OK Then
        Dim fontResName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
            If (gdpicturePDF.NewPage(500, 500) = GdPictureStatus.OK) AndAlso
               (gdpicturePDF.SetFillColor(Color.Blue) = GdPictureStatus.OK) AndAlso
               (gdpicturePDF.SetTextSize(30) = GdPictureStatus.OK) AndAlso
               (gdpicturePDF.DrawText(fontResName, 200, 250, "Hello World") = GdPictureStatus.OK) Then
                status = gdpicturePDF.SaveToFile("test_HelloWorld.pdf")
                If status = GdPictureStatus.OK Then
                    MessageBox.Show("Your new PDF document has been successfully created.", "Example: NewPDF")
                Else
                    MessageBox.Show("The file can't be saved. Status: " + status.ToString(), "Example: NewPDF")
                End If
            End If
        End If
        gdpicturePDF.CloseDocument()
    Else
        MessageBox.Show("The NewPDF() method has failed with the status: " + status.ToString(), "Example: NewPDF")
    End If
End Using
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
    //A brand new empty document without any page.
    GdPictureStatus status = gdpicturePDF.NewPDF();
    if (status == GdPictureStatus.OK)
    {
        string fontResName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);
        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
        {
            if ((gdpicturePDF.NewPage(500, 500) == GdPictureStatus.OK) &&
                (gdpicturePDF.SetFillColor(Color.Blue) == GdPictureStatus.OK) &&
                (gdpicturePDF.SetTextSize(30) == GdPictureStatus.OK) &&
                (gdpicturePDF.DrawText(fontResName, 200, 250, "Hello World") == GdPictureStatus.OK))
            {
                status = gdpicturePDF.SaveToFile("test_HelloWorld.pdf");
                if (status == GdPictureStatus.OK)
                    MessageBox.Show("Your new PDF document has been successfully created.", "Example: NewPDF");
                else
                    MessageBox.Show("The file can't be saved. Status: " + status.ToString(), "Example: NewPDF");
            }
        }
        gdpicturePDF.CloseDocument();
    }
    else
    {
        MessageBox.Show("The NewPDF() method has failed with the status: " + status.ToString(), "Example: NewPDF");
    }
}
How to reuse the created GdPicturePDF object.
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.NewPDF()
If status <> GdPictureStatus.OK Then
    GoTo [end]
End If
status = gdpicturePDF.NewPage(500, 500)
If status <> GdPictureStatus.OK Then
    GoTo [end]
End If
status = gdpicturePDF.SaveToFile("FirstPDF.pdf")
If status <> GdPictureStatus.OK Then
    GoTo [end]
End If
MessageBox.Show("The FirstPDF.pdf document with one page has been successfully saved.", "Example: NewPDF")
status = gdpicturePDF.CloseDocument()
If status <> GdPictureStatus.OK Then
    GoTo [end]
End If
status = gdpicturePDF.NewPDF()
If status <> GdPictureStatus.OK Then
    GoTo [end]
End If
status = gdpicturePDF.NewPage(500, 500)
If status <> GdPictureStatus.OK Then
    GoTo [end]
End If
status = gdpicturePDF.SaveToFile("SecondPDF.pdf")
If status <> GdPictureStatus.OK Then
    GoTo [end]
End If
MessageBox.Show("The SecondPDF.pdf document with one page has been successfully saved.", "Example: NewPDF")
[end]:
gdpicturePDF.Dispose()
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.NewPDF();
if (status != GdPictureStatus.OK) goto end;
status = gdpicturePDF.NewPage(500, 500);
if (status != GdPictureStatus.OK) goto end;
status = gdpicturePDF.SaveToFile("FirstPDF.pdf");
if (status != GdPictureStatus.OK) goto end;
MessageBox.Show("The FirstPDF.pdf document with one page has been successfully saved.", "Example: NewPDF");
status = gdpicturePDF.CloseDocument();
if (status != GdPictureStatus.OK) goto end;
status = gdpicturePDF.NewPDF();
if (status != GdPictureStatus.OK) goto end;
status = gdpicturePDF.NewPage(500, 500);
if (status != GdPictureStatus.OK) goto end;
status = gdpicturePDF.SaveToFile("SecondPDF.pdf");
if (status != GdPictureStatus.OK) goto end;
MessageBox.Show("The SecondPDF.pdf document with one page has been successfully saved.", "Example: NewPDF");
end:
gdpicturePDF.Dispose();
See Also