PDF Printer

Documentation & code samples

C/C++
.NET Core
Java
C#

Printing

Features and Configuration

List printers and their properties

1// Create the printer object
2using (Printer printer = new Printer())
3{
4    // Create output text file containing a list of all available printers in localhost
5    using (StreamWriter writer = new StreamWriter(txtFilePath))
6    {
7        writer.WriteLine("List of available printers in localhost:");
8        writer.WriteLine("----------------------------------------");
9
10        // Loop over all printers in localhost
11        for (int printerNo = 0, printerCount = printer.GetPrinterCount(""); printerNo < printerCount; printerNo++)
12        {
13            string printerName = printer.GetPrinter(printerNo);
14            writer.WriteLine("Printer {0}: {1}", printerNo + 1, printerName);
15
16            // Open printer
17            if (!printer.OpenPrinter(printerName))
18                throw new Exception(String.Format("Printer {0} could not be opened. " + 
19                "{1} (ErrorCode: 0x{2:x}).", printerName, printer.ErrorMessage, printer.ErrorCode));
20
21            // List duplex modes for selected printer
22            writer.WriteLine("  Duplex Modes:");
23            for (int i = 0, n = printer.GetDuplexModeCount(printerName); i < n; i++)
24                writer.WriteLine("    - {0}", printer.GetDuplexMode(i));
25
26            // List bins for selected printer
27            writer.WriteLine("  Bins:");
28            for (int i = 0, n = printer.GetBinCount(printerName); i < n; i++)
29                writer.WriteLine("    - {0}", printer.GetBin(i));
30
31            // List paper sizes for selected printer
32            writer.WriteLine("  Paper:");
33            for (int i = 0, n = printer.GetPaperCount(printerName); i < n; i++)
34                writer.WriteLine("    - {0}", printer.GetPaper(i));
35
36            // List media types for selected printer
37            writer.WriteLine("  Media Types:");
38            for (int i = 0, n = printer.GetMediaTypeCount(printerName); i < n; i++)
39                writer.WriteLine("    - {0}", printer.GetMediaTypeName(i));
40
41            // Close printer
42            printer.ClosePrinter();
43
44            writer.WriteLine("----------------------------------------");
45        }
46    }
47}
48
Download code samples for
1// Create the printer
2printer = new Printer();
3
4// Create output text file containing a list of all available printers in localhost
5PrintWriter writer = new PrintWriter(new FileOutputStream(txtFilePath));
6
7writer.println("List of available printers in localhost:");
8writer.println("----------------------------------------");
9
10// Loop over all printers in localhost
11for (int printerNo = 0, printerCount = printer.getPrinterCount(""); printerNo < printerCount; printerNo++)
12{
13    String printerName = printer.getPrinter(printerNo);
14    writer.println("Printer "+ (printerNo + 1) + ": " + printerName);
15
16    // Open printer
17    if (!printer.openPrinter(printerName))
18        throw new IOException(String.format("Printer %s could not be opened. " + 
19            "%s (ErrorCode: 0x%08x).", printerName, printer.getErrorMessage(), 
20            printer.getErrorCode()));
21
22    // List duplex modes for selected printer
23    writer.println("  Duplex Modes:");
24    for (int i = 0, n = printer.getDuplexModeCount(printerName); i < n; i++)
25        writer.println("    - " + printer.getDuplexMode(i));
26
27    // List bins for selected printer
28    writer.println("  Bins:");
29    for (int i = 0, n = printer.getBinCount(printerName); i < n; i++)
30        writer.println("    - " + printer.getBin(i));
31
32    // List paper sizes for selected printer
33    writer.println("  Paper:");
34    for (int i = 0; i < printer.getPaperCount(printerName); i++)
35        writer.println("    - " + printer.getPaper(i));
36
37    // List media types for selected printer
38    writer.println("  Media Types:");
39    for (int i = 0, n = printer.getMediaTypeCount(printerName); i < ; i++)
40        writer.println("    - " + printer.getMediaTypeName(i));
41
42    // Close printer
43    if (!printer.closePrinter())
44        throw new IOException(String.format("Printer %s could not be closed. " + 
45            "%s (ErrorCode: 0x%08x).", printerName, printer.getErrorMessage(), 
46            printer.getErrorCode()));
47
48    writer.println("----------------------------------------");
49}
50writer.flush();
51writer.close();
52
Download code samples for
1// Create the printer object
2pPrinter = PDFPrnCreateObject();
3
4// Create output text file containing a list of all available printers in localhost
5pTxtFile = _tfopen(szTextFilePath, _T("w"));
6_ftprintf(pTxtFile, _T("List of available printers in localhost:\n"));
7_ftprintf(pTxtFile, _T("----------------------------------------\n"));
8
9// Loop over all printers in localhost
10for (int iPrinter = 0, nPrinters = PDFPrnGetPrinterCount(pPrinter, ""); iPrinter < nPrinters; iPrinter++)
11{
12    TCHAR szPrinterName[256];
13   _tcscpy(szPrinterName, PDFPrnGetPrinter(pPrinter, iPrinter));
14   _ftprintf(pTxtFile, _T("Printer %d: %s\n"), iPrinter + 1, szPrinterName);
15
16   // Open printer
17   if (!PDFPrnOpenPrinter(pPrinter, szPrinterName))
18   {
19       _tprintf(_T("Printer %s could not be opened. %s (ErrorCode: 0x%08x).\n"), szPrinterName, PDFPrnGetErrorMessage(pPrinter), PDFPrnGetErrorCode(pPrinter));
20       continue;
21   }
22
23    // List duplex modes for selected printer
24    _ftprintf(pTxtFile, _T("  Duplex Modes:\n"));
25    for (int j = 0, n = PDFPrnGetDuplexModeCount(pPrinter, szPrinterName); j < n; j++)
26        _ftprintf(pTxtFile, _T("   - %s\n"), PDFPrnGetDuplexMode(pPrinter, j));
27
28    // List bins for selected printer
29    _ftprintf(pTxtFile, _T("  Bins:\n"));
30    for (int j = 0, n = PDFPrnGetBinCount(pPrinter, szPrinterName); j < n; j++)
31        _ftprintf(pTxtFile, _T("   - %s\n"), PDFPrnGetBin(pPrinter, j));
32
33    // List paper sizes for selected printer
34    _ftprintf(pTxtFile, _T("  Paper:\n"));
35    for (int j = 0, n = PDFPrnGetPaperCount(pPrinter, szPrinterName); j < n; j++)
36        _ftprintf(pTxtFile, _T("   - %s\n"), PDFPrnGetPaper(pPrinter, j));
37
38    // List media types for selected printer
39    _ftprintf(pTxtFile, _T("  Media Types:\n"));
40    for (int j = 0, n = PDFPrnGetMediaTypeCount(pPrinter, szPrinterName); j < ; j++)
41        _ftprintf(pTxtFile, _T("   - %s\n"), PDFPrnGetMediaTypeName(pPrinter, j));
42
43    // Close printer
44    PDFPrnClosePrinter(pPrinter);
45
46    _ftprintf(pTxtFile, _T("----------------------------------------\n"));
47}
48
Download code samples for

Customize Printing