Print the document to a specific printer
In one of my previous posts, I have discussed how to download and print a remote file. Here is the blog link Print Remote File
The solution in the above post will print the file to the default printer and recently I was working on a modification where I have to print the file to a specific printer instead of the default printer and couple of readers of my blog post also asked how to do this, so I would like to share today the solution for it.
I was checking online to modify my old solution to print to a specific printer and few suggested to me to use the arguments property of the ProcessStartInfo and also the below MSDN example suggests the same, but unfortunately, I was not successful using that property.
https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.verbs(v=vs.110).aspx
To solve this issue I have found another solution which is to use the Print Document and in fact, I think this is an easy solution when compared to the other solution in my previous post.
Below is the function for it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
PROCEDURE PrintFile@1000000018(FilePath@1000000002 : Text[250]);
VAR
PrinterName@1240060002 : Text;
PrintDocument@1240060003 : DotNet "'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Drawing.Printing.PrintDocument";
PrinterSettings@1240060004 : DotNet "'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Drawing.Printing.PrinterSettings";
BEGIN
PrinterName := 'MF8200C Series';
PrintDocument := PrintDocument.PrintDocument;
PrintDocument.DocumentName := FilePath;
PrinterSettings := PrinterSettings.PrinterSettings;
PrinterSettings.PrinterName := PrinterName;
PrintDocument.PrinterSettings := PrinterSettings;
PrintDocument.Print;
MESSAGE('Complete');
END;
If you have any other Tips or suggestions, please do share them in the comments below.
Leave a comment