DrawLine Method (GdPicturePDF)
In This Topic
Draws a line on the currently selected page of the loaded PDF document according to what you have specified. All coordinates of the starting and ending points of the line need to be set in the current units defined in the PDF document with respect to the currently located origin, related to the actual page. The line is clearly defined by the its starting and ending points. The other line parameters, which you might prefer, for example, the line color or the line width, you are allowed to set by using the
GdPicturePDF.SetLineColor method and the
GdPicturePDF.SetLineWidth method.
You can simply use the GdPicturePDF.GetMeasurementUnit method to determine the currently defined units and you can easily use the GdPicturePDF.SetMeasurementUnit method to reset the units according to your preference.
Syntax
'Declaration
Public Function DrawLine( _
ByVal As Single, _
ByVal As Single, _
ByVal As Single, _
ByVal As Single _
) As GdPictureStatus
public GdPictureStatus DrawLine(
float ,
float ,
float ,
float
)
public function DrawLine(
: Single;
: Single;
: Single;
: Single
): GdPictureStatus;
public function DrawLine(
: float,
: float,
: float,
: float
) : GdPictureStatus;
public: GdPictureStatus DrawLine(
float ,
float ,
float ,
float
)
public:
GdPictureStatus DrawLine(
float ,
float ,
float ,
float
)
Parameters
- StartX
- The horizontal (X) coordinate of the line's starting point, expressed in the current units specified by the SetMeasurementUnit method
with respect to the defined origin, related to the currently selected page.
- StartY
- The vertical (Y) coordinate of the line's starting point, expressed in the current units specified by the SetMeasurementUnit method
with respect to the defined origin, related to the currently selected page.
- DstX
- The horizontal (X) coordinate of the line's ending point, expressed in the current units specified by the SetMeasurementUnit method
with respect to the defined origin, related to the currently selected page.
- DstY
- The vertical (Y) coordinate of the line's ending point, expressed in the current units specified by the SetMeasurementUnit method
with respect to the defined origin, related to the currently selected page.
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 lines with different attributes.
Dim caption As String = "Example: DrawLine"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.NewPDF()
If status = GdPictureStatus.OK Then
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
If (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetLineColor(255, 140, 0) = GdPictureStatus.OK) AndAlso 'The color used to draw the line.
(gdpicturePDF.SetLineWidth(0.5F) = GdPictureStatus.OK) AndAlso 'the line width
(gdpicturePDF.DrawLine(2, 2, 18, 2) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetLineWidth(0.3F) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.DrawLine(2, 4, 18, 4) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetLineColor(210, 105, 30) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetLineWidth(0.2F) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetLineDash(2, 1) = GdPictureStatus.OK) AndAlso 'drawing a dash line
(gdpicturePDF.DrawLine(2, 6, 18, 6) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.DrawLine(2, 10, 18, 10) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetLineNoDash() = GdPictureStatus.OK) AndAlso
(gdpicturePDF.DrawLine(18, 6, 18, 10) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.DrawLine(2, 6, 2, 10) = GdPictureStatus.OK) Then
status = gdpicturePDF.SaveToFile("test_DrawLine.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 " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The NewPDF() method has failed with the status: " + status.ToString(), caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: DrawLine";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.NewPDF();
if (status == GdPictureStatus.OK)
{
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
if ((gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK) &&
(gdpicturePDF.SetLineColor(255, 140, 0) == GdPictureStatus.OK) && //The color used to draw the line.
(gdpicturePDF.SetLineWidth(0.5f) == GdPictureStatus.OK) && //the line width
(gdpicturePDF.DrawLine(2, 2, 18, 2) == GdPictureStatus.OK) &&
(gdpicturePDF.SetLineWidth(0.3f) == GdPictureStatus.OK) &&
(gdpicturePDF.DrawLine(2, 4, 18, 4) == GdPictureStatus.OK) &&
(gdpicturePDF.SetLineColor(210, 105, 30) == GdPictureStatus.OK) &&
(gdpicturePDF.SetLineWidth(0.2f) == GdPictureStatus.OK) &&
(gdpicturePDF.SetLineDash(2, 1) == GdPictureStatus.OK) && //drawing a dash line
(gdpicturePDF.DrawLine(2, 6, 18, 6) == GdPictureStatus.OK) &&
(gdpicturePDF.DrawLine(2, 10, 18, 10) == GdPictureStatus.OK) &&
(gdpicturePDF.SetLineNoDash() == GdPictureStatus.OK) &&
(gdpicturePDF.DrawLine(18, 6, 18, 10) == GdPictureStatus.OK) &&
(gdpicturePDF.DrawLine(2, 6, 2, 10) == GdPictureStatus.OK))
{
status = gdpicturePDF.SaveToFile("test_DrawLine.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 " + gdpicturePDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The NewPDF() method has failed with the status: " + status.ToString(), caption);
gdpicturePDF.Dispose();
Example
How to draw lines with different attributes.
Dim caption As String = "Example: DrawLine"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.NewPDF()
If status = GdPictureStatus.OK Then
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
If (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetLineColor(255, 140, 0) = GdPictureStatus.OK) AndAlso 'The color used to draw the line.
(gdpicturePDF.SetLineWidth(0.5F) = GdPictureStatus.OK) AndAlso 'the line width
(gdpicturePDF.DrawLine(2, 2, 18, 2) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetLineWidth(0.3F) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.DrawLine(2, 4, 18, 4) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetLineColor(210, 105, 30) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetLineWidth(0.2F) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetLineDash(2, 1) = GdPictureStatus.OK) AndAlso 'drawing a dash line
(gdpicturePDF.DrawLine(2, 6, 18, 6) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.DrawLine(2, 10, 18, 10) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetLineNoDash() = GdPictureStatus.OK) AndAlso
(gdpicturePDF.DrawLine(18, 6, 18, 10) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.DrawLine(2, 6, 2, 10) = GdPictureStatus.OK) Then
status = gdpicturePDF.SaveToFile("test_DrawLine.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 " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The NewPDF() method has failed with the status: " + status.ToString(), caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: DrawLine";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.NewPDF();
if (status == GdPictureStatus.OK)
{
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
if ((gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK) &&
(gdpicturePDF.SetLineColor(255, 140, 0) == GdPictureStatus.OK) && //The color used to draw the line.
(gdpicturePDF.SetLineWidth(0.5f) == GdPictureStatus.OK) && //the line width
(gdpicturePDF.DrawLine(2, 2, 18, 2) == GdPictureStatus.OK) &&
(gdpicturePDF.SetLineWidth(0.3f) == GdPictureStatus.OK) &&
(gdpicturePDF.DrawLine(2, 4, 18, 4) == GdPictureStatus.OK) &&
(gdpicturePDF.SetLineColor(210, 105, 30) == GdPictureStatus.OK) &&
(gdpicturePDF.SetLineWidth(0.2f) == GdPictureStatus.OK) &&
(gdpicturePDF.SetLineDash(2, 1) == GdPictureStatus.OK) && //drawing a dash line
(gdpicturePDF.DrawLine(2, 6, 18, 6) == GdPictureStatus.OK) &&
(gdpicturePDF.DrawLine(2, 10, 18, 10) == GdPictureStatus.OK) &&
(gdpicturePDF.SetLineNoDash() == GdPictureStatus.OK) &&
(gdpicturePDF.DrawLine(18, 6, 18, 10) == GdPictureStatus.OK) &&
(gdpicturePDF.DrawLine(2, 6, 2, 10) == GdPictureStatus.OK))
{
status = gdpicturePDF.SaveToFile("test_DrawLine.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 " + gdpicturePDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The NewPDF() method has failed with the status: " + status.ToString(), caption);
gdpicturePDF.Dispose();
See Also