DrawPage Method (GdPicturePDF)
In This Topic
Draws content of the page, specified by its page number, from a source PDF document, onto the exactly defined area of the currently selected page of the destination PDF document. The coordinates and the dimensions of the destination area need to be set in the current units defined in the destination PDF document, related to the actual page, where the content of the source page is to be drawn.
You can use the GdPicturePDF.GetMeasurementUnit method to determine the currently defined units and you can use the GdPicturePDF.SetMeasurementUnit method to reset the units according to your preference.
Syntax
'Declaration
Public Function DrawPage( _
ByVal As GdPicturePDF, _
ByVal As Integer, _
ByVal As Single, _
ByVal As Single, _
ByVal As Single, _
ByVal As Single _
) As GdPictureStatus
public GdPictureStatus DrawPage(
GdPicturePDF ,
int ,
float ,
float ,
float ,
float
)
public function DrawPage(
: GdPicturePDF;
: Integer;
: Single;
: Single;
: Single;
: Single
): GdPictureStatus;
public function DrawPage(
: GdPicturePDF,
: int,
: float,
: float,
: float,
: float
) : GdPictureStatus;
public: GdPictureStatus DrawPage(
GdPicturePDF* ,
int ,
float ,
float ,
float ,
float
)
public:
GdPictureStatus DrawPage(
GdPicturePDF^ ,
int ,
float ,
float ,
float ,
float
)
Parameters
- SrcPDF
- The source PDF document, which contains the source page to draw.
- SrcPage
- The page number of the page, which content is to be drawn. This parameter is without any restrictions, the source page is selected by use of the GdPicturePDF.SelectPage method, so all there mentioned details remain in effect.
- DstX
- The horizontal (X) coordinate of the bottom left point of the destination area, where the page content is to be drawn,
expressed in the current units used in the destination PDF document, related to the currently selected page.
- DstY
- The vertical (Y) coordinate of the bottom left point of the destination area, where the page content is to be drawn,
expressed in the current units used in the destination PDF document, related to the currently selected page.
- DstWidth
- The width of the destination area, expressed in the current units used in the destination PDF document.
- DstHeight
- The height of the destination area, expressed in the current units used in the destination PDF document.
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.
Example
How to draw content of the first page of the source PDF document onto the first page of the destination PDF document twice, side by side, within the two same-sized areas.
Dim caption As String = "Example: DrawPage"
Dim srcPDF As New GdPicturePDF()
Dim dstPDF As New GdPicturePDF()
Dim status As GdPictureStatus = srcPDF.LoadFromFile("test.pdf", False)
If status = GdPictureStatus.OK Then
If (dstPDF.NewPDF() = GdPictureStatus.OK) AndAlso
(dstPDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) Then
Dim width As Single = dstPDF.GetPageWidth()
If dstPDF.GetStat() = GdPictureStatus.OK Then
Dim height As Single = dstPDF.GetPageHeight()
If dstPDF.GetStat() = GdPictureStatus.OK Then
'the new width of the destination area
width = width / 2
If (dstPDF.SelectPage(1) = GdPictureStatus.OK) AndAlso
(dstPDF.DrawPage(srcPDF, 1, 0, 0, width, height) = GdPictureStatus.OK) AndAlso
(dstPDF.DrawPage(srcPDF, 1, width, 0, width, height) = GdPictureStatus.OK) Then
status = dstPDF.SaveToFile("test_DrawPage.pdf")
If status = GdPictureStatus.OK Then
MessageBox.Show("The example has been followed successfully and the file has been saved.", caption)
Else
MessageBox.Show("The example has been followed successfully, but the file can't be saved. Status: " + status.ToString(), caption)
End If
Else
MessageBox.Show("The example has not been followed successfully." + vbCrLf + "The last known status is " + dstPDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The GetPageHeight() method has failed with the status: " + dstPDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The GetPageWidth() method has failed with the status: " + dstPDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The NewPDF() method or the NewPage() for the destination document has failed with the status: " + dstPDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The LoadFromFile() method for the source document has failed with the status: " + status.ToString(), caption)
End If
srcPDF.Dispose()
dstPDF.Dispose()
string caption = "Example: DrawPage";
GdPicturePDF srcPDF = new GdPicturePDF();
GdPicturePDF dstPDF = new GdPicturePDF();
GdPictureStatus status = srcPDF.LoadFromFile("test.pdf", false);
if (status == GdPictureStatus.OK)
{
if ((dstPDF.NewPDF() == GdPictureStatus.OK) &&
(dstPDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK))
{
float width = dstPDF.GetPageWidth();
if (dstPDF.GetStat() == GdPictureStatus.OK)
{
float height = dstPDF.GetPageHeight();
if (dstPDF.GetStat() == GdPictureStatus.OK)
{
//the new width of the destination area
width = width / 2;
if ((dstPDF.SelectPage(1) == GdPictureStatus.OK) &&
(dstPDF.DrawPage(srcPDF, 1, 0, 0, width, height) == GdPictureStatus.OK) &&
(dstPDF.DrawPage(srcPDF, 1, width, 0, width, height) == GdPictureStatus.OK))
{
status = dstPDF.SaveToFile("test_DrawPage.pdf");
if (status == GdPictureStatus.OK)
MessageBox.Show("The example has been followed successfully and the file has been saved.", caption);
else
MessageBox.Show("The example has been followed successfully, but the file can't be saved. Status: " + status.ToString(), caption);
}
else
MessageBox.Show("The example has not been followed successfully.\nThe last known status is " + dstPDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The GetPageHeight() method has failed with the status: " + dstPDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The GetPageWidth() method has failed with the status: " + dstPDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The NewPDF() method or the NewPage() for the destination document has failed with the status: " + dstPDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The LoadFromFile() method for the source document has failed with the status: " + status.ToString(), caption);
srcPDF.Dispose();
dstPDF.Dispose();
Example
How to draw content of the first page of the source PDF document onto the first page of the destination PDF document twice, side by side, within the two same-sized areas.
Dim caption As String = "Example: DrawPage"
Dim srcPDF As New GdPicturePDF()
Dim dstPDF As New GdPicturePDF()
Dim status As GdPictureStatus = srcPDF.LoadFromFile("test.pdf", False)
If status = GdPictureStatus.OK Then
If (dstPDF.NewPDF() = GdPictureStatus.OK) AndAlso
(dstPDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) Then
Dim width As Single = dstPDF.GetPageWidth()
If dstPDF.GetStat() = GdPictureStatus.OK Then
Dim height As Single = dstPDF.GetPageHeight()
If dstPDF.GetStat() = GdPictureStatus.OK Then
'the new width of the destination area
width = width / 2
If (dstPDF.SelectPage(1) = GdPictureStatus.OK) AndAlso
(dstPDF.DrawPage(srcPDF, 1, 0, 0, width, height) = GdPictureStatus.OK) AndAlso
(dstPDF.DrawPage(srcPDF, 1, width, 0, width, height) = GdPictureStatus.OK) Then
status = dstPDF.SaveToFile("test_DrawPage.pdf")
If status = GdPictureStatus.OK Then
MessageBox.Show("The example has been followed successfully and the file has been saved.", caption)
Else
MessageBox.Show("The example has been followed successfully, but the file can't be saved. Status: " + status.ToString(), caption)
End If
Else
MessageBox.Show("The example has not been followed successfully." + vbCrLf + "The last known status is " + dstPDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The GetPageHeight() method has failed with the status: " + dstPDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The GetPageWidth() method has failed with the status: " + dstPDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The NewPDF() method or the NewPage() for the destination document has failed with the status: " + dstPDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The LoadFromFile() method for the source document has failed with the status: " + status.ToString(), caption)
End If
srcPDF.Dispose()
dstPDF.Dispose()
string caption = "Example: DrawPage";
GdPicturePDF srcPDF = new GdPicturePDF();
GdPicturePDF dstPDF = new GdPicturePDF();
GdPictureStatus status = srcPDF.LoadFromFile("test.pdf", false);
if (status == GdPictureStatus.OK)
{
if ((dstPDF.NewPDF() == GdPictureStatus.OK) &&
(dstPDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK))
{
float width = dstPDF.GetPageWidth();
if (dstPDF.GetStat() == GdPictureStatus.OK)
{
float height = dstPDF.GetPageHeight();
if (dstPDF.GetStat() == GdPictureStatus.OK)
{
//the new width of the destination area
width = width / 2;
if ((dstPDF.SelectPage(1) == GdPictureStatus.OK) &&
(dstPDF.DrawPage(srcPDF, 1, 0, 0, width, height) == GdPictureStatus.OK) &&
(dstPDF.DrawPage(srcPDF, 1, width, 0, width, height) == GdPictureStatus.OK))
{
status = dstPDF.SaveToFile("test_DrawPage.pdf");
if (status == GdPictureStatus.OK)
MessageBox.Show("The example has been followed successfully and the file has been saved.", caption);
else
MessageBox.Show("The example has been followed successfully, but the file can't be saved. Status: " + status.ToString(), caption);
}
else
MessageBox.Show("The example has not been followed successfully.\nThe last known status is " + dstPDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The GetPageHeight() method has failed with the status: " + dstPDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The GetPageWidth() method has failed with the status: " + dstPDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The NewPDF() method or the NewPage() for the destination document has failed with the status: " + dstPDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The LoadFromFile() method for the source document has failed with the status: " + status.ToString(), caption);
srcPDF.Dispose();
dstPDF.Dispose();
See Also