Save All Print Jobs As PDF - c#

The Goal
The company I work for currently uses a black box shipping system. Each morning our shipping manager prints out shipping tickets for his drivers. Using C#, I would like to save a copy of each ticket printed as a PDF. The action of saving to a PDF should be done behind the scenes.
Note: The PDF copy would be in addition to the hard copy, however, I would like to generate the PDF copy when the hard copy is printed (or directly after if I can use the saved print job).
End Result: The manager prints a hard copy and a PDF gets saved to an archive folder without any interaction from the manager.
What I've Tried
I've instructed the printer to "Keep printed documents" after printing. This leaves a .shd and a .spl file in the print spool folder. I've experimented with the PrintDocument class, but I can find no way to instruct a job to reprint (to a PDF driver) using a completed print job.
Question
Is what I'm trying to accomplish possible?
Further Clarification:
In case it wasn't clear, I do not want the manager to print the document a second time to a PDF print driver. On average he must print 60 tickets each morning before he can send his drivers out. I don't want to increase that number to 120 AND force him to type in the file names.
Additionally, the "black box" shipping system includes other modules that run other portions of our manufacturing plant - changing software is not an option.

I suggest you go with an existing solution to problems like this: Use a software that can install virtual printers that print the document on the printers you want. One such software is PrintDistributor. I don't have any experience with this software but the screenshot named "Virtual Printers" looks promising: The second printer is named "Print and save".
There is other software like this, see here.

According to your goal that you don't want to force him to enter file names, You should do this:
Use a PDF Printer software that provides automatic file naming, like these:
PDF Desk
Cute PDF
And tell the manager to print tickets just with that PDF Printer.
Then, write a c# or vb.net application. use FileSystemWatcher to detect if a new file is created in PDFs directory. and when a new PDF is created, print it.
Here are some tutorials that explains how to Print a PDF file in c#:
Print existing PDF (or other files) in C#
Printing PDF documents in C#

Trapping things being sent to the printer can be very tricky.
A simpler way would be to set up a 'pdf printer' using a piece of software such as:
http://www.bullzip.com/products/pdf/info.php
Configure this to output to a specific directory, and then write a windows service to monitor the directory and automatically send PDF files to the physical printer and archive the file off to a network folder.
[and remove the printer driver from his PC so he can't bypass your new system]

Issue two print commands... one to the paper printer, one to the PDF printer.

Related

Printing with winspool.Drv-WritePrinter prints hundreds of pages with symbols instead of correct page

I have a svc that receives a string with a printer name and, after some things, it finishes printing a pdf document.
I'm using something like this code to print the pdf
https://vishalsbsinha.wordpress.com/2014/05/06/how-to-programmatically-c-net-print-a-pdf-file-directly-to-the-printer/
And it works perfectly on my computer/printer. But when I publish and deploy on the server, when I use the service it starts printing hundreds of pages filled with symbols instead of the expected one page pdf. The server does not have Adobe Acrobat installed (and neither I can install it) so I can't use other alternatives like 'new Process()->Verb="PrintTo".
The pdf fonts are Calibri and Arial, and they are installed on both my team and server.
Does anyone can tell me why does it prints on a wrong way and what alternatives do I have?
The model of the printer is: RICOH Aficio MP C4501 PCL 6
Your solution requires that the printer handles PDF files natively, and many printers don't support PDF. A printer driver translates from Windows GDI to the native format of the printer, but you're bypassing the printer driver by using WritePrinter. You will either need to use a different paper printer that supports PDF, or send the file to the printer using the printer driver instead of WritePrinter.

Monitor print queue and merge jobs into one using .Net

I have an automated app which creates a set of outputs and sends them separately to the printer. Each page of the job is being sent as a separate print job which is undesirable, as it makes it almost impossible to use a PDF printer and convert create a single PDF file out of them.
I was wondering if there is a way to write a simple console or windows program that would receive these print jobs, merge them together and send the whole thing as one job to another printer. Is there anyway to accomplish that?
There are three ways I see to accomplish this.
The first would be to modify the original program. Have it drop PDFs off in a directory that is monitored by another program to do the combining.
The second is to install a PDF print driver whose output is a file on the file system. Every print job would output as a separate file. Your program would then monitor that and combine as necessary
The third way is to write your own print driver which takes the jobs and combines them.
However all of these "solutions" require you to be able to identify which page goes with which document and in what position of that document. Honestly, without far more information, the best route would be to modify the originating program to just do what you want.
It is not possible to merge print jobs, after they have been added to the queue.
What application is producing these documents?
What output format does it produce?
What is your intended output format and destination?
(printer/email/something else?)

How to get document in print queue

Is there any way in C# to get the documents sent to the printer from another program and use those documents again for something else?
I want to build an application which can get invoice sent to the printer by some point of sale system and gives opportunity to send that invoice to customer's email.
Well, you could print to the XPS printer and have it create a file. Then, let the system print the XPS file using the standard application. This may or may not work depending on some factors:
Is there XPS support on the system?
Did the user change the default application that handles XPS files? Maybe printing is no longer possible...
Is XPS a file format you want to send to the users?
etc.
That said, of course you could do the same thing with PDF, but you'd have to have access to an application that can actually print PDF. It has been asked multiple times here how to "send PDF bytes" to a printer - you can't. There are solutions, but in the end you have to answer this question for yourself:
Is it really worth the hassle or isn't it just easier to print the document and then create it again as PDF (for examples) to send to the user?

How to create a postscript file using print to file option in word with C#?

I want to create a postscript file from a word document(.doc) using print to file from Microsoft word and C#, I found lots of ways to print a file but couldn't find "Print to file".
Unless things have changed, you don't 'print to file' you 'print to a printer on FILE:'
So what you need to do is create a printer instance using the driver of your choice, and have it send its data to the FILE: hardware (rather than LPT!: COM!: USB001: etc).
On Windows versions up to 7 (I have no information yet on Windows 8) it is possible to create a Port Monitor and install that, this can then write the data to file instead. You still have to create a printer instance which uses that Port Monitor though.
Add a new printer.
Select - Local printer attached to this printer
Use port - FILE: (print to file)
Choose a postscript printer from the list, such as an Apple LaserWriter 16/600 PS (or an 11x17 printer for larger output or an imagesetter for variable page size ability)
Then just print to the printer

How to merge different document types and show as stack in .NET application

Suppose in .NET (don't care what language) I want to show a user a PDF, Word and Excel file together. I am trying to replicate a document process where a user might have a PDF file and he would like to attach a WORD file and an Excel file let's say to make a stack of documents (that I would save in some directory). Then he would like to click on a button and see a stack of these documents in 1 application of some sort.
How can I display the stack of documents WITHOUT first opening WORD, then openinig EXCEL and then openining ADOBE ACROBAT - this would be really annoying for the user. I would like one unified application or some idea to mimic one in .NET that can just show all 3 documents as if they were printed one after the other on paper. (I hope I am explaining this clearly)
The only thing I can think of to do this would be to leverage some sort of PDF conversion process to create one PDF file containing all three of these documents in "printed" (page-by-page) form, and then show that. The one application I can think of that could show all of these files is a web browser with appropriate Office and Acrobat viewer plugins, and you might find it difficult to leverage that, as browser preference and other user OS settings can cause various strategies for application launching to fail.
I would convert the documents in PDF and develop a pdf viewer inside your application.
I would use a ready made library for that, don't reinvent the wheel.
For example: http://www.quickpdflibrary.com/products/quickpdf/index.php

Categories

Resources