简体   繁体   中英

Why report is shrunk When RDLC Report is printed directly to POS printer

i am trying to print an RDLC Report Directly to a POS Printer, using source code from MSDN ( Link ), by exporting the report to ( EMF ) Image, then printing the image to the printer using PrintDocument ,I calculate the height of the report based on number of rows (height of one row = 0.6 cm).

The problem is that when the report is too long (more than one page), I got its rows shrunk (compressed) to each other.

How to solve this problem ? Do I have to use POS Printer library (.NET POS) instead of the exporting the report to image and printing the image? . you can download the source code from ( Here ).

thanks in advanced.

I solved it by changing the size of the paper :

PaperSize pkCustomSize = new System.Drawing.Printing.PaperSize("Custom Paper Size", Convert.ToInt32((WidthInInCM / 2.54) * 100), Convert.ToInt32((HeightInInCM / 2.54) * 100));
            printDoc.DefaultPageSettings.PaperSize = pkCustomSize;
            printDoc.DefaultPageSettings.Margins.Top = 0;
            printDoc.DefaultPageSettings.Margins.Bottom = 0;
            printDoc.DefaultPageSettings.Margins.Left = 0;
            printDoc.DefaultPageSettings.Margins.Right = 0;

            if (!printDoc.PrinterSettings.IsValid)
            {
                String msg = String.Format("Can't find printer \"{0}\".", PrinterName);
                MessageBox.Show(msg, "Print Error");
                return;
            }
            printDoc.PrinterSettings.DefaultPageSettings.PaperSize = printDoc.DefaultPageSettings.PaperSize;
            printDoc.PrinterSettings.DefaultPageSettings.Margins = printDoc.DefaultPageSettings.Margins;

you can download the updated source code from ( here ).

another solution is to print the large image (which I export the report to it) to many pages :

private void PrintPage(Object sender, PrintPageEventArgs ev)
        {
            if (pageImage == null)
                return;
            ev.Graphics.PageUnit = GraphicsUnit.Pixel;

            ev.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            ev.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
            float a = (ev.PageSettings.PrintableArea.Width / 100) * ev.Graphics.DpiX;
            float b = ((ev.PageSettings.PrintableArea.Height / 100) * ev.Graphics.DpiY);
            float scale = 1500;
            scale = 0;
            RectangleF srcRect = new RectangleF(0, startY, pageImage.Width, b - scale);
            RectangleF destRect = new RectangleF(0, 0, a, b);
            ev.Graphics.DrawImage(pageImage, destRect, srcRect, GraphicsUnit.Pixel);
            startY = startY + b - scale;
            float marignInPixel = (0.5f / 2.54f) * ev.Graphics.DpiY;
            ev.HasMorePages = (startY + marignInPixel < pageImage.Height);
        }

you can download the source code from ( here )

I've been stuck on a similiar problem.

I've managed to fix it using the following:

    private void PrintPage(object sender, PrintPageEventArgs ev)
    {

        Metafile pageImage =
          new Metafile(m_streams[m_currentPageIndex]);
//That's the fix - Units set to Display
        ev.Graphics.PageUnit = GraphicsUnit.Display;
//Drawing it scaled
        ev.Graphics.DrawImage(pageImage, 0, 0, ev.MarginBounds.Width, ev.MarginBounds.Height);

        m_currentPageIndex++;
        ev.HasMorePages = (m_currentPageIndex < m_streams.Count);            
    }

The page gets drawn to printer canvas scaled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM