Reputation: 11
I am trying to find a generalized solution on how to save the document as PDF while giving print on my actual printer on Windows 7/10 OS. Scenario: Whatever I am printing whether an image or a file or from the third party app like POS or Screen Print (like user press pint button on the third party application or press CTRL+P if the third party app supported this hot key), i need to save the document as PDF which this document is reaching to the actual printer which is printing the hard copies. I wanted to generalized to support all kinds of printers be it dot matrix or laser or thermal etc...
Solution which I have tried out:
Could anyone help me on this. I am unable to find any solution over google as well so posting it here. It looks a normal thing to achieve but even after two weeks i am unable to find any solution for this. Is this something difficult to achieve the generalized solution?
Upvotes: 1
Views: 1451
Reputation: 61
Consider an approach using something like the ePrint Virtual Printer which works by capturing the Windows EMF file from the print job and converting it to PDF while also being able to still send the EMF to the physical printer and print it. The application itself allows for the creation of Print Tasks in a Virtual Printer, which can be configured to save to PDF and batch print to other printers.
On the other hand, ePrint is based on the LEADTOOLS Virtual Printer SDK, which could be useful for you to look into if you are looking to code your own approach.
For example, the code for an event that is hooked to a virtual printer to save the captured EMF as PDF:
// Write the EMF as file to disk as PDF.
static void VirtualPrinter_EmfEvent( object sender, EmfEventArgs e )
{
string pdfPath = Path.Combine(
@"c:\Output\PDF\",
Path.GetFileNameWithoutExtension( Path.GetRandomFileName() )
) + ".pdf";
Directory.CreateDirectory( Path.GetDirectoryName( pdfPath ) );
// Create an instance of the LEADTOOLS DocumentWriter
DocumentWriter docWriter = new DocumentWriter();
docWriter.BeginDocument( pdfPath, DocumentFormat.Pdf );
DocumentEmfPage page = new DocumentEmfPage() {
EmfHandle = new Metafile( e.Stream ) )
.GetHenhmetafile()
};
docWriter.AddPage( page );
docWriter.EndDocument();
}
If you are interested in more details, you can check out this article here.
Upvotes: 0