简体   繁体   中英

How to print dynamic paper height without cut using RDLC report c#?

Here is my code i work with:

set Dataset and parameter to RDLC report

private static int m_currentPageIndex;

report.DataSources.Add(new ReportDataSource("dsReceiptInfor", ReceiptInfor)); ReportParameter[] param = new ReportParameter[2];

param[0] = new ReportParameter("imgPath", FilePath); param[1] = new ReportParameter("BaseCurrencyFormat", BaseCurrencyFormat);

report.SetParameters(param);

Export(report);

Print();


Functions

--Export

    private static void Export(LocalReport report)
    {
     string deviceInfo =
          @"<DeviceInfo>
            <OutputFormat>EMF</OutputFormat>
            <PageWidth>8.5in</PageWidth>
            <PageHeight>11in</PageHeight>
            <MarginTop>0in</MarginTop>
            <MarginLeft>0in</MarginLeft>
            <MarginRight>0in</MarginRight>
            <MarginBottom>0in</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;
     }

--Print

    private static void Print()
    {
        if (m_streams == null || m_streams.Count == 0)
            throw new Exception("Error: no stream to print.");

        PrintDocument PrintBill = new PrintDocument();
        PrintBill.PrintPage += new PrintPageEventHandler(PrintPage);
        PrintBill.PrinterSettings.PrinterName = PrinterName;
        PrintBill.PrintController = new StandardPrintController();
        m_currentPageIndex = 0;
        PrintBill.Print();
    }

--PrintPage

    private static void PrintPage(object sender, PrintPageEventArgs ev)
    {
        try
        {
            Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);

            //Adjust rectangular area with printer margins.
            Rectangle adjustedRect = new Rectangle(
                0,
                0,
                765,
                ev.PageBounds.Height);
            //Draw a white background for the report
            ev.Graphics.FillRectangle(Brushes.White, adjustedRect);


            // Draw the report content
            ev.Graphics.DrawImage(pageImage, adjustedRect);

            // Prepare for the next page. Make sure we haven't hit the end.
            m_currentPageIndex++;
            ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
        }
        catch (Exception ex)
        {

        }

    }

When the data print (PageHeight > 11 inch) it will cut. Could you tell me how to print long as the paper. thanks for your attention :)

after long time i have searching the answer but still not found. So i have found one solution without coding. in Printer setting we can change printer preference :

Paper source --> Document (cut). Done

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