Sunday, January 14, 2018

Print the document to a specific printer

printer-2178754_1920

In one of my previous posts, I have discussed how to download and print a remote file. Here is the blog link

http://www.navisionworld.com/2017/09/how-to-print-remote-file-from-nav.html

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

image

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.

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.

24 comments:

  1. Hey Suresh Kulla, thank you for your post. we try it out with txt files and pdf file, but the output is only a white paper with some black points in the header and footer area of the output.

    any idea for solution or what we can check to print the files correctly ?

    thank you in advance
    Arndt Loermann

    ReplyDelete
  2. Arndt,

    I ran into same issue for some printers, I will review and let you know if i find a solution.

    Thanks
    Suresh

    ReplyDelete
  3. Hi mate,
    Your code for this help me a lot.

    Can you tell me why I can't access my printer? Says "A call to System.Drawing.Printing.PrintDocument.Print failed with this message: Settings to access printer 'xxxxx' are not valid.

    There is anything that you can tell me in order to fix it?

    ReplyDelete
  4. Hi Suresh,

    Thanks a lot for sharing this great Blog.
    Could you please share the solution of White Paper Issue which is shared by @Arndt Loermann.
    It would be very useful for all of us.

    ReplyDelete
  5. Thanks for sharing the blog with us. Learn how to get your printer online with Printerofflinefix.us. For the more details you have to do just one click How Do I Get My Printer Online

    ReplyDelete
  6. Good to know about the printers. If you are looking for the cnc 3d printer for sale then, febtop.com is deals in the quality products.

    ReplyDelete
  7. Thanks for the feature description.

    ReplyDelete
  8. I think I have never seen such blogs ever before that has complete things with all details which I want. Buy the best quality Hybrid 3D Printer on optimus3dp.com. Visit here 3 in 1 3D Printer

    ReplyDelete
  9. This is an awesome post. Really very informative and creative
    printer service center in omr

    ReplyDelete
  10. New web site is looking good. Thanks for the great effort. wholesale label printing

    ReplyDelete
  11. Thanks for nice and informative post. This article is really contains lots of valuable information. For the Hybrid 3D Printer CNC you have to visit on optimus3dp.com.

    ReplyDelete

  12. Thanks for sharing information. Choosing computer accessories from leading IT store offer great discount and value for your money Computer Store Australia | Buy Printers Online

    ReplyDelete
  13. I really want to thank the author for such a nice blog that helped me to understand why it is important. If you are looking for 3d printer in USA then Maverick3dp.com is a good choice.

    ReplyDelete
  14. A very delightful article that you have shared here. Your blog is a valuable and engaging article for us, and also I will share it with my companions who need this info. Thankful to you for sharing an article like this.6 Heads American Screen Printing Machine

    ReplyDelete
  15. Nice article, which you have shared here. Your article is very informative and I liked your way to express your views in this post. The article you have shared here is very informative and the points you have mentioned are very helpful. Thanks for sharing this article here. Ink Supplies

    ReplyDelete
  16. This is a smart blog. I would not joke about this. You have fantastic information about this theme. A debt of gratitude is in order for sharing a particularly extraordinary online journal to us. 3d printing service

    ReplyDelete
  17. You've supplied us with an interesting article about Epson Sublimation Printer Ink Online India. This is a fantastic resource for expanding your understanding of the subject. Thank you very much.

    ReplyDelete
  18. Looking for a printer that can print sharp and great-looking prints? You must be looking for Sublimation printing process printers. Here's what you can get from Epson.

    ReplyDelete
  19. With laser printer rentals, you have the luxury of printing and reprinting when you need to. renting impresoras madrid

    ReplyDelete
  20. Extremely useful information which you have shared here about printing services bangalore This is a great way to enhance knowledge for us, and also beneficial for us. Thank you for sharing a blog like this.

    ReplyDelete
  21. Impressive and powerful suggestion by the author of this blog are really helpful to me. Robot 3D Printer

    ReplyDelete
  22. I would like to say this is a well-informed article as we have seen here. Your way of writing is very impressive and also it is a beneficial article for us. Thanks for sharing an article like this.Ink Toner Cartridge For Sale Online

    ReplyDelete
  23. This comment has been removed by the author.

    ReplyDelete
  24. Such beautifully written. And the information provided is very useful. Thanks for sharing such an informative and interesting article. Check this out too 3d printer fan.Thanks!

    ReplyDelete