AsP.NET MVC 4 application runs in Debian Squeeze Linux using Mono. Controller creates pdf file from html using code below.
How to print pdf file to Samsung printer connected to server ? It there some executable which can used for this ?
public class Test: Controller {
public ActionResult Print()
{
PrintOrderVormiga();
return new ContentResult() { Content = "OK" };
}
void PrintOrderVormiga()
{
StringBuilder sb = new StringBuilder();
sb.Insert(0, " test ", 500);
pdf = ConvertHtmlToPDF("<html><body>" +sb.Tostring()+ "</body></html>");
var doc = new PrintDocument();
doc.PrinterSettings.PrinterName = "Samsung ML-331x Series";
doc.PrintPage += new PrintPageEventHandler(ProvideContent);
pageHeight = doc.DefaultPageSettings.PaperSize.Height;
doc.Print();
}
byte [] pdf;
void ProvideContent(object sender, PrintPageEventArgs e)
{
?? of to print this.pdf contents as pdf ?
}
static byte[] ConvertHtmlToPDF(string html)
{
string programm = "wkhtmltopdf";
var p = new Process
{
StartInfo =
{
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
UseShellExecute = false,
FileName = Environment.OSVersion.Platform == PlatformID.Win32NT ?
@"C:\Program Files\wkhtmltopdf\bin\" + programm + ".exe" : "/usr/bin/" + programm
}
};
p.StartInfo.Arguments += " - -";
p.Start();
using (var stream = p.StandardInput)
{
byte[] ibuffer = System.Text.Encoding.UTF8.GetBytes(html);
stream.BaseStream.Write(ibuffer, 0, ibuffer.Length);
stream.WriteLine();
}
var buffer = new byte[32768];
byte[] file;
using (var ms = new MemoryStream())
{
while (true)
{
var read = p.StandardOutput.BaseStream.Read(buffer, 0, buffer.Length);
if (read <= 0)
{
break;
}
ms.Write(buffer, 0, read);
}
file = ms.ToArray();
}
p.WaitForExit(60000);
var returnCode = p.ExitCode;
p.Close();
return file;
}
}
来源:https://stackoverflow.com/questions/33712356/how-to-print-pdf-in-debian-linux-from-mvc-controller