PrintGetPrinterName Method (GdPicturePDF)
In This Topic
Returns the name of the printer according to the index you have specified.
You can use the GdPicturePDF.PrintGetPrintersCount method to determine the number of all available printers. The printer index is simply an integer value from 1 to GdPicturePDF.PrintGetPrintersCount.
Syntax
'Declaration
Public Function PrintGetPrinterName( _
ByVal As Integer _
) As String
public string PrintGetPrinterName(
int
)
public function PrintGetPrinterName(
: Integer
): String;
public function PrintGetPrinterName(
: int
) : String;
public: string* PrintGetPrinterName(
int
)
public:
String^ PrintGetPrinterName(
int
)
Parameters
- PrinterNo
- The printer index. It must be a value from 1 to GdPicturePDF.PrintGetPrintersCount.
Return Value
The name of the specified printer. The
GdPicturePDF.GetStat method can be subsequently used or the
GdPicturePDF.PrintGetStat method to determine if this method has been successful.
Example
How to find out the printer's name and how to use it further.
Dim caption As String = "Example: PrintGetPrinterName"
Using gdpicturePDF As New GdPicturePDF()
Dim message As String = ""
Dim CurPrinter As String = gdpicturePDF.PrintGetActivePrinter()
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
Dim PrintersCount As Integer = gdpicturePDF.PrintGetPrintersCount()
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
For i As Integer = 1 To PrintersCount
Dim PrinterName As String = gdpicturePDF.PrintGetPrinterName(i)
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
If gdpicturePDF.PrintSetActivePrinter(PrinterName) = True Then
Dim prnSettings As System.Drawing.Printing.PrinterSettings
prnSettings = gdpicturePDF.PrintGetPrinterSettings()
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
message = message + "Printer: " + PrinterName + vbCrLf + "Settings: " + prnSettings.ToString() + vbCrLf + vbCrLf
Else
message = message + "Printer: " + PrinterName + " Error getting settings: " + gdpicturePDF.PrintGetStat().ToString() + vbCrLf
End If
Else
Exit For
End If
Else
Exit For
End If
Next
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
MessageBox.Show(message, caption)
Else
MessageBox.Show("The example has NOT been followed successfully. The last status: " + gdpicturePDF.PrintGetStat(), caption)
End If
If gdpicturePDF.PrintSetActivePrinter(CurPrinter) = False Then
MessageBox.Show("The PrintSetActivePrinter() method has failed with the status: " + gdpicturePDF.PrintGetStat(), caption)
End If
Else
MessageBox.Show("The PrintGetPrintersCount() method has failed with the status: " + gdpicturePDF.PrintGetStat(), caption)
End If
Else
MessageBox.Show("The PrintGetActivePrinter() method has failed with the status: " + gdpicturePDF.PrintGetStat(), caption)
End If
End Using
string caption = "Example: PrintGetPrinterName";
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
string message = "";
string CurPrinter = gdpicturePDF.PrintGetActivePrinter();
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
int PrintersCount = gdpicturePDF.PrintGetPrintersCount();
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
for (int i = 1; i <= PrintersCount; i++)
{
string PrinterName = gdpicturePDF.PrintGetPrinterName(i);
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
if (gdpicturePDF.PrintSetActivePrinter(PrinterName) == true)
{
System.Drawing.Printing.PrinterSettings prnSettings;
prnSettings = gdpicturePDF.PrintGetPrinterSettings();
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
message = message + "Printer: " + PrinterName + "\nSettings: " + prnSettings.ToString() + "\n\n";
else
message = message + "Printer: " + PrinterName + " Error getting settings: " + gdpicturePDF.PrintGetStat().ToString() + "\n";
}
else
break;
}
else
break;
}
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
MessageBox.Show(message, caption);
else
MessageBox.Show("The example has NOT been followed successfully. The last status: " + gdpicturePDF.PrintGetStat(), caption);
if (gdpicturePDF.PrintSetActivePrinter(CurPrinter) == false)
MessageBox.Show("The PrintSetActivePrinter() method has failed with the status: " + gdpicturePDF.PrintGetStat(), caption);
}
else
MessageBox.Show("The PrintGetPrintersCount() method has failed with the status: " + gdpicturePDF.PrintGetStat(), caption);
}
else
MessageBox.Show("The PrintGetActivePrinter() method has failed with the status: " + gdpicturePDF.PrintGetStat(), caption);
}
Example
How to find out the printer's name and how to use it further.
Dim caption As String = "Example: PrintGetPrinterName"
Using gdpicturePDF As New GdPicturePDF()
Dim message As String = ""
Dim CurPrinter As String = gdpicturePDF.PrintGetActivePrinter()
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
Dim PrintersCount As Integer = gdpicturePDF.PrintGetPrintersCount()
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
For i As Integer = 1 To PrintersCount
Dim PrinterName As String = gdpicturePDF.PrintGetPrinterName(i)
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
If gdpicturePDF.PrintSetActivePrinter(PrinterName) = True Then
Dim prnSettings As System.Drawing.Printing.PrinterSettings
prnSettings = gdpicturePDF.PrintGetPrinterSettings()
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
message = message + "Printer: " + PrinterName + vbCrLf + "Settings: " + prnSettings.ToString() + vbCrLf + vbCrLf
Else
message = message + "Printer: " + PrinterName + " Error getting settings: " + gdpicturePDF.PrintGetStat().ToString() + vbCrLf
End If
Else
Exit For
End If
Else
Exit For
End If
Next
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
MessageBox.Show(message, caption)
Else
MessageBox.Show("The example has NOT been followed successfully. The last status: " + gdpicturePDF.PrintGetStat(), caption)
End If
If gdpicturePDF.PrintSetActivePrinter(CurPrinter) = False Then
MessageBox.Show("The PrintSetActivePrinter() method has failed with the status: " + gdpicturePDF.PrintGetStat(), caption)
End If
Else
MessageBox.Show("The PrintGetPrintersCount() method has failed with the status: " + gdpicturePDF.PrintGetStat(), caption)
End If
Else
MessageBox.Show("The PrintGetActivePrinter() method has failed with the status: " + gdpicturePDF.PrintGetStat(), caption)
End If
End Using
string caption = "Example: PrintGetPrinterName";
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
string message = "";
string CurPrinter = gdpicturePDF.PrintGetActivePrinter();
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
int PrintersCount = gdpicturePDF.PrintGetPrintersCount();
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
for (int i = 1; i <= PrintersCount; i++)
{
string PrinterName = gdpicturePDF.PrintGetPrinterName(i);
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
if (gdpicturePDF.PrintSetActivePrinter(PrinterName) == true)
{
System.Drawing.Printing.PrinterSettings prnSettings;
prnSettings = gdpicturePDF.PrintGetPrinterSettings();
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
message = message + "Printer: " + PrinterName + "\nSettings: " + prnSettings.ToString() + "\n\n";
else
message = message + "Printer: " + PrinterName + " Error getting settings: " + gdpicturePDF.PrintGetStat().ToString() + "\n";
}
else
break;
}
else
break;
}
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
MessageBox.Show(message, caption);
else
MessageBox.Show("The example has NOT been followed successfully. The last status: " + gdpicturePDF.PrintGetStat(), caption);
if (gdpicturePDF.PrintSetActivePrinter(CurPrinter) == false)
MessageBox.Show("The PrintSetActivePrinter() method has failed with the status: " + gdpicturePDF.PrintGetStat(), caption);
}
else
MessageBox.Show("The PrintGetPrintersCount() method has failed with the status: " + gdpicturePDF.PrintGetStat(), caption);
}
else
MessageBox.Show("The PrintGetActivePrinter() method has failed with the status: " + gdpicturePDF.PrintGetStat(), caption);
}
See Also