• Contact
  • Company
  • Login / My Account
  • Shopping Cart (0)
Document Conversion Made Easy!
Peernet Menu
  • Products
      • Virtual Printers
        • tiff-image-printer-iconTIFF Image Printer – Create TIFF Images
        • raster-image-printer-iconRaster Image Printer – Create TIFF, PDF, JPEG, etc.
        • pdf-image-printer-iconPDF Image Printer – Create Searchable PDF
      • PDF Editor
        • pdf-creator-plus-iconPDF Creator Plus – Merge, Edit, Create Searchable PDF
      • Batch Converters
        • document-conversion-service-iconDocument Conversion Service – Unattended 24/7 Batch Converter
        • file-conversion-center-iconFile Conversion Center – Desktop Batch Converter
      • Reporting Software
        • peernet-reports-iconPEERNET Reports – Barcode, Report and Label Software
      • enterprise-licensingEnterprise Licensing for your Corporation
      • discounts-multiple-licensesDiscounts for Purchasing Multiple Licenses
      • distribute-bundle-peernet-softwareDistribute PEERNET Software Bundled with your Product
  • Purchase
      • Purchase Virtual Printers
        • tiff-image-printer-iconTIFF Image Printer – Create TIFF Images
        • raster-image-printer-iconRaster Image Printer – Create TIFF, PDF, JPEG etc.
        • pdf-image-printer-iconPDF Image Printer – Create Searchable PDF
      • Purchase PDF Editor
        • pdf-creator-plus-iconPDF Creator Plus – Merge, Edit, Create Searchable PDF
      • Purchase Batch Converters
        • document-conversion-service-iconDocument Conversion Service – Unattended 24/7 Batch Converter
        • file-conversion-center-iconFile Conversion Center – Desktop Batch Converter
      • Purchase Reporting Software
        • peernet-reports-iconPEERNET Reports – Barcode, Report and Label Software
      • peernet-online-store-purchase-optionsPurchase Options
      • peernet-software-license-levelsLicense Levels
      • peernet-software-purchase-resellerFind Resellers
      • peernet-software-sales-faqsSales FAQ
  • Learn & Support
        • peernet-help-centerTutorials
          • Learn the Basics or Go Beyond with Video Tutorials, FAQs and Guides

            At PEERNET we pride ourselves on providing the best support and the fastest response times in the industry.
          • Select Software Tutorials:
              • tiff-image-printer-iconTIFF Image Printer
              • raster-image-printer-iconRaster Image Printer
              • pdf-image-printer-iconPDF Image Printer
              • pdf-creator-plus-iconPDF Creator Plus
              • document-conversion-service-iconDocument Conversion Service
              • file-conversion-center-iconFile Conversion Center
              • peernet-reports-iconPEERNET Reports
        • peernet-software-faqsSales FAQ
          • Popular Topics

            Find all the answers you need to our most frequently asked questions.
              • Download & Install
                • How do I download software I already purchased?
              • Purchasing & Renewing
                • How do I purchase PEERNET software?
                • What license level do I need?
                • How do I add licenses to an existing serial number?
                • How do I renew my annual subscription?
              • Licensing & Operating
                • How do I activate my new PEERNET software?
                • How do I activate my software without an internet connection?
                • Where do I find my serial number?
                • How do I move my software to a new computer?
                • How do I update/upgrade my software to the latest release?
            • Read all Sales FAQs
  • Blog
  • Menu Menu

Using .NET or COM API to Automate Printing

April 6, 2022/by Robert Massart

Automate printing in your own custom applications or scripts using the PEERNET PNSrv12 COM Object. Included with TIFF Image Printer, Raster Image Printer and PDF Image Printer, no additional files need to be included with your application. The end-user only needs the appropriate printer installed and activated.

The PNSrv12 COM Object can be used in Visual Basic 6.0, Visual Basic .NET, Visual C# .NET, Visual C++, VBScript and PowerShell, and anywhere else you can use COM objects.

When using PNSrv12 COM, you can:

  • set file naming and conversion preferences on a per file basis
  • wait until the file has been created to continue your workflow
  • use a pool of printers to increase conversion capacity
  • track the files printed and the output files associated with each file
  • retrieve information about the output files created
  • interact with the printer in a thread-safe manner

Using the PNSrv12 COM Object

To reference the PNSrv12Lib in your application, from the list of available COM objects, you would select “PNSrv12 1.0 Type Library“.

SelectNewReference

Creating The Conversion Profiles

Conversion profiles are used to set the conversion settings when initializing the PNSrv12Lib COM. They are created and exported using the Profile Manager. These files are referenced by file path when initializing the COM object and can be included with your application’s program files. A conversion profile can contain all of your settings if you are always converting documents with the same options, or just the common settings and the COM methods can be used to change settings dynamically as you print. You can also have multiple conversion profiles and switch between them as needed.

Initializing PNSession

The PNSession object is used to initialize and connect with the Image Printer you are using, and establishes the number of printers in the printer pool and the conversion settings. A prefix can be added to the name of each printer in the printer pool for easy recognition. The process ID of your application is passed in to ensure all COM objects and printers are properly disposed of upon exit.

using PNSrv12Lib;

PNSession session = new PNSession();
int pID = Process.GetCurrentProcess().Id;


session.SetSessionPrinter(pID, "TIFF Image Printer 12", 2, "Converter-", "C:\Profiles\FaxTIFF.pntifprofile");

Dynamically Set the Output Location and Filename

The filename formatting options in the conversion profile provide many options for custom naming including path building, unique IDs, JobIDs, custom prefix and suffix and page numbers. See the Filename Creator topic for all the options to build your filename. When you need greater control over the filename, the method SetSaveOptionsOutputLocationAndOutputFileName allows you to override the output folder, the output file name or both before you print each file, while the OnGetNextFileName event can be used to set the output folder and filename just a s the output file is created on disk.

Printing to a Printer from the Pool

The PNSrv12Lib COM object is created with a chosen number of printers in it’s printer pool. This can be as little as one printer, or you can have as many printers in the pool as needed, up to the limits of your system resources. Having more than one printer in the pool of printers allows more than one file to be submitted at a time, or for the printer pool to be shared in a multi-threaded application.

Before each document is printed, a printer from the printer pool needs to be requested using the NewPrintSession method, and the document is then printed to that printer. The returned IPNPrintSession object contains the name of the printer to use when printing the document, and is used to test that the document was successfully sent, or spooled to the printer, as well as monitoring document conversion to know when the output file has been created on disk.

Waiting for the Output File

After printing the document, your workflow may need to know when the document is created, or done, in order to move on to the next file or to take the created file and perform the next task in your process. The IPPrintSession‘s WaitForJobsCompleted method is a timed method that is used to wait for the document to be created on disk and ready for further processing.

When you need more information about the files created, such as a list of the names of all the files created, the OnEndJob event on the IPNSession object should be used. This event is fired when the document has completed conversion and all files are on disk and ready to be processed. An IPNJob object is passed to the event that contains information about the job, such as the name of the source file, and a list of the file or files created, allowing you to get the exact name of the file created, even when serialized or other custom file naming properties have been set.

Dive in With Sample Programs 

Several C# samples are included that demonstrate how to automate printing with Microsoft Word, Adobe Reader and PNSrv12Lib COM. The samples cover such topics as initializing the COM object for the printer, creating printer pools, passing in a conversion profile containing the settings to for the output files, overriding the file name as you print or querying for unique file names just as the output file is being created, how to safely use the COM object in multiple threads using a Parallel.For loop, and methods to determine when the file has been converted.

For an overview of each sample and where to find this, see Getting Started With PNSrv12Lib.

Additional Information

For more detailed information on using PNSrv12 COM Object, see :

Using the PNSrv12 COM Object in TIFF User Guide
Using the PNSrv12 COM Object in Raster User Guide
Using the PNSrv12 COM Object in PDF User Guide

https://www.peernet.com/wp-content/uploads/tutorial-post-automation-tif-ras-pdf.png 600 900 Robert Massart https://www.peernet.com/wp-content/uploads/peernet-logo.png Robert Massart2022-04-06 16:03:402023-10-23 16:29:50Using .NET or COM API to Automate Printing
  • Document Conversion Service
  • TIFF Image Printer
  • Raster Image Printer
  • PDF Image Printer
  • PDF Creator Plus
  • File Conversion Center
  • PEERNET Reports
Search Search

Recent Posts

  • PNSrv11Lib to PNSrv12Lib: Migration Made Easy
  • Migrating to Version 12: Compatibility Mode Quick Start Guide
  • Well Logs: Stitch PDF Pages into a Continuous TIFF Image
  • Dynamic Stamp Content
  • Convert to PDF: The Power of On-Premise PDF Creation

INTERESTING LINKS

Below are some interesting links for you! Enjoy your stay :)

RSS Feed Logo RSS Feed Logo Subscribeto RSS Feed

OUR PRODUCTS

  • Document Conversion Service
  • TIFF Image Printer
  • Raster Image Printer
  • PDF Image Printer
  • PDF Creator Plus
  • File Conversion Center
  • PEERNET Reports

LATEST NEWS

  • PNSrv11Lib to PNSrv12Lib: Migration Made EasyMarch 14, 2025 - 2:10 pm
  • Migrating to Version 12: Compatibility Mode Quick Start GuideMarch 14, 2025 - 2:09 pm
  • Well Logs: Stitch PDF Pages into a Continuous TIFF ImageMarch 14, 2025 - 2:08 pm
  • Dynamic Stamp ContentNovember 4, 2024 - 4:47 pm

BUSINESS INFORMATION

Toll Free: 1-800-883-7980 North America

Tel: 1-613-224-6894

Our office hours are Monday to Friday, from 0900 hrs to 1700 hrs, Eastern Standard Time.

Email Address: [email protected]
Copyright © 1997-2026. All rights reserved. Terms and Conditions | Disclaimer | Privacy Policy | Trademarks.
PEERNET® is a registered trademark of PEERNET Inc.
  • Link to Youtube
  • Link to Rss this site
  • Products
  • Purchase
  • Company
  • Contact
Link to: Print Automation Using Script File Link to: Print Automation Using Script File Print Automation Using Script File Link to: Add Header and Footer Text to Each Page in PDF Image Printer Link to: Add Header and Footer Text to Each Page in PDF Image Printer Add Header and Footer Text to Each Page in PDF Image Printer
Scroll to top Scroll to top Scroll to top