直接打印,我不想创建.emf文件. [英] Direct Printing ,I don't want to create .emf file.
本文介绍了直接打印,我不想创建.emf文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
能帮帮我吗?
我想创建直接打印,但是我不想创建文件(例如emf)
我正在使用rdlc报告文件.
现在我使用以下
Can you help me!
I want to create direct printing, but i don''t want to create files(eg. emf)
I using rdlc report file.
Now i using these following
private void Export(LocalReport report)
{
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>EMF</OutputFormat>" +
" <PageWidth>3in</PageWidth>" +
// " <PageHeight>8.5in</PageHeight>" +
// " <MarginTop>0in</MarginTop>" +
" <MarginLeft>0.1in</MarginLeft>" +
" <MarginRight>0.2in</MarginRight>" +
" <MarginBottom>0.2in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
m_streams = new List<Stream>();
report.Render("Image", deviceInfo, CreateStream,
out warnings);
foreach (Stream stream in m_streams)
stream.Position = 0;
}
// Handler for PrintPageEvents
private void PrintPage(object sender, PrintPageEventArgs ev)
{
Metafile pageImage = new
Metafile(m_streams[m_currentPageIndex]);
ev.Graphics.DrawImage(pageImage, ev.PageBounds);
m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
private Stream CreateStream(string name,
string fileNameExtension, Encoding encoding,
string mimeType, bool willSeek)
{
Stream stream = new FileStream(@"..\..\" + name +
"." + fileNameExtension, FileMode.OpenOrCreate);
m_streams.Add(stream);
return stream;
}
private void Print()
{
//Printer Path
string printerName = "";
printerName = POSPOSTools.GetData("SELECT ReceiptPrinterPath FROM POS_MasterCode");
if (m_streams == null || m_streams.Count == 0)
return;
PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings.PrinterName = printerName;
if (!printDoc.PrinterSettings.IsValid)
{
printerName = printerName = POSPOSTools.GetData("SELECT ReceiptPrinterPath FROM POS_MTerminal WHERE ComputerName = ''" + SystemInformation.ComputerName.Trim() + "''");
printDoc.PrinterSettings.PrinterName = printerName;
if (!printDoc.PrinterSettings.IsValid)
{
string msg = String.Format(
"Can''t find printer \"{0}\".", printerName);
//MessageBox.Show(msg, "Print Error");
ExternalClass.ShowMessageBox(msg, "Print Error",2);
return;
}
}
//Printer Path
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
printDoc.PrintController = new StandardPrintController();
printDoc.Print();
}
创建一个emf文件后,它是一个打印文件.对我来说这是最大的问题.
请给我建议解决我的问题!
Theingi Win
It is one print file after create one emf file. It is biggest problem for me.
Plese give me suggestion to solve my problem!
Theingi Win
推荐答案
我不确定这个问题的本质,但是我确实有一些代码可以同时打印文本和图像,而不会生成其他文件流中运行时生成的条形码图像.但是硬盘上没有文件.
I''m not entirely sure of the nature of this question BUT I do have some code that prints both Text and Images without generating a file other than a run-time generated Barcode image in a stream. But no files physically on the hard-drive.
Public Sub PrinterDocument_PrintPage(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs) Handles PrinterDocument.PrintPage
e.Graphics.CompositingMode = Drawing2D.CompositingMode.SourceCopy
e.Graphics.CompositingQuality = Drawing2D.CompositingQuality.AssumeLinear
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.None
e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.SingleBitPerPixel
e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
Dim barcodetext As String = MyBarCode.Value
Dim barcodecaption As String = MyBarCode.Caption
Dim captionfont As Font = New Font("Arial", 6.0F, FontStyle.Regular)
PrinterText = barcodecaption
PrinterFont = New Font("Arial", 8.0F, FontStyle.Regular)
PrinterBrush = New SolidBrush(Color.Black)
XPosition = 100.0F
YPosition = 100.0F
e.Graphics.PageUnit = GraphicsUnit.Document
e.Graphics.DrawImageUnscaled(MyBarCode.GenerateBarcode(), New Point(60, 22))
e.Graphics.DrawString(barcodecaption, captionfont, PrinterBrush, 140.0F, 72.0F)
e.Graphics.DrawString(PrinterText, PrinterFont, PrinterBrush, XPosition, YPosition)
e.HasMorePages = False
End Sub
此外,GenerateBarcode方法定义为....
Additionally the GenerateBarcode Method is defined as....
Private Function GenerateBarcode(ByVal text As String) As Bitmap
Dim ret As Bitmap
Dim barcode39 As Barcode3of9 = New Barcode3of9()
Dim barcodefont As Font = barcode39.GetBarcodeFont(BarcodeType.Barcode3of9Regular, 29.0F)
Dim barcodesize As Size
barcodesize = TextRenderer.MeasureText(text, barcodefont)
BarcodeLabel = New Label()
BarcodeLabel.UseCompatibleTextRendering = True
BarcodeLabel.BackColor = Color.White
BarcodeLabel.Font = barcodefont
BarcodeLabel.Width = barcodesize.Width + 20
BarcodeLabel.Text = text
BarcodeLabel.Height = 16
ret = New Bitmap(BarcodeLabel.Width, BarcodeLabel.Height)
BarcodeLabel.DrawToBitmap(ret, New Rectangle(0, 0, BarcodeLabel.Width, BarcodeLabel.Height))
Return ret
End Function
希望这会有所帮助,
-ArtificerGM
Hope this helps,
-ArtificerGM
这篇关于直接打印,我不想创建.emf文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文