Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
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();
        }


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
Posted

1 solution

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.

VB
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

Additionally the GenerateBarcode Method is defined as....
VB
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

Hope this helps,
-ArtificerGM
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900