我们可以发送PDF字节来处理打印.NET核心ubuntu [英] Can we send PDF bytes to process for printing .NET core ubuntu

查看:131
本文介绍了我们可以发送PDF字节来处理打印.NET核心ubuntu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LPR命令打印PDF文件,这是使用iTextSharp创建的。

打印时,我正在传递PDF文件路径,保存在我的机器上。

I am using LPR command for printing PDF file, which is created by using iTextSharp.
For printing, I am passing PDF file path, saved on my machine.

Process objP = new Process();
objP.StartInfo.FileName = "lpr";
objP.StartInfo.Arguments = " -P " + printerName + " " + fileName;



现在我想要的是,发送PDF字节直接发送到打印机,而不是发送PDF文件路径。



我想避免在每台打印命令的机器上保存PDF文件,然后在打印后删除它完成。



我从iTextSharp获取PDF字节。我可以将这些字节传递给进程吗?



我尝试了什么:



我可以打印PDF文件,给出物理路径。


Now what I want is, sending PDF bytes directly to printer, instead of sending PDF file path.

I want to avoid saving of PDF file on machine for every print command, and then deleting it after printing completes.

I get PDF bytes from iTextSharp. Can I pass these bytes to process?

What I have tried:

I am able to print PDF file, y giving its physical path.

推荐答案

好问题,:-)



事实上,这个程序允许你从命令中删除文件名,然后它读取的是你传递给它的输入, lpr的手册页 [ ^ ],读为,

Good question, :-)

The fact is that this program allows you to strip out the file name from the command, then what it reads is the input that you pass to it, man page for lpr[^], reads as,
引用:

如果没有出现名称,则标准输入是假定的。

If no names appear, the standard input is assumed.

输入可以是您要发送的字节。但是,在C#中,您将使用该过程的标准输入, Process.StandardInput 属性(System.Diagnostics) [ ^ ]。然后你将字节写入此属性(它是一个编写器对象,阅读文档更多)。



要获取字节,只需使用 File.ReadAllBytes(string) 系统.IO 名称空间,完美无缺。然后通过writer将它们传递给输入流。

Input can be the bytes that you want to send. In C# however, you would use the standard input for the process, Process.StandardInput Property (System.Diagnostics)[^]. Then you write the bytes to this property (it is a writer object, read documentation for more).

To get the bytes, just use File.ReadAllBytes(string) of System.IO namespace, that would work perfectly. Then pass them via writer to the input stream.


这篇关于我们可以发送PDF字节来处理打印.NET核心ubuntu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆