RDLC POS report printing

Im trying to figure out a way to print in a POS printer without knowing the height of the print.

The idea to dynamically fill a RDLC report with elements in a tree view (that’s done) and then send it to silent printing. This is where it gets tricky. The report size its set to the default POS size (80mm to 3276mm)

The idea its to start with a height (need to experiment what value fits best)

And then start adding based on the number of items being aggregated to the report so it would be something like this

double paperWidthMm = report_imprime_comanda.LocalReport.GetDefaultPageSettings().PaperSize.Width;
 double totalHeight = 30;

 foreach (TreeNode parentNode in parentNodes)
 {
     if (parentNode.Tag is Comanda comandaMain)
     {
         double itemHeight = GetItemHeight(comandaMain);
         totalHeight += itemHeight;
         filteredComandas.Add(comandaMain);

    
     }
}

   // Dynamically set the page height based on total content height
   int paperWidthHundredthsOfInch = (int)(paperWidthMm / 25.4 * 100);
   int paperHeightHundredthsOfInch = (int)(totalHeight / 25.4 * 100);
  

PageSettings pageSettings = new PageSettings

  {

      PaperSize = new PaperSize("Custom", paperWidthHundredthsOfInch, paperHeightHundredthsOfInch)


  };

  MessageBox.Show("Paper Size: " + pageSettings, "Tamaño papel", MessageBoxButtons.OK, MessageBoxIcon.Warning);
 report_imprime_comanda.SetPageSettings(pageSettings);

 // Bind filtered data to the report
 report_imprime_comanda.LocalReport.DataSources.Clear();
 report_imprime_comanda.LocalReport.DataSources.Add(new ReportDataSource("Comandas", filteredComandas));

 // Refresh the report to apply the changes
 report_imprime_comanda.RefreshReport();
 PrintPOS printPOS = new PrintPOS();
 // Render and print the report
 printPOS.PrintReportToPrinter(report_imprime_comanda.LocalReport, printerName);


This the function that adds inches to the report based on the elements:

 private double GetItemHeight(Comanda item)
  {
      // Base height for each comanda item
      double baseHeight = 30;

      // Additional height for each child note
      double noteHeight = 15;

      // Calculate total height
      double totalHeight = baseHeight;

      // Split the notes by ';' to count them
      if (!string.IsNullOrEmpty(item.NOTAS))
      {
          string[] notes = item.NOTAS.Split(';');
          totalHeight += notes.Length * noteHeight;
      }

      return totalHeight;
  }

This is function that does the actual print

 public void PrintReportToPrinter(LocalReport report, string printerName)
    {
        // Configure print settings for the POS printer
        PrinterSettings printerSettings = new PrinterSettings
        {
            PrinterName = printerName,
            Copies = 1,
            PrintToFile = false,
        };

        // Create a PrintDocument object
        PrintDocument printDoc = new PrintDocument
        {
            PrinterSettings = printerSettings
        };

        printDoc.PrintPage += (sender, args) =>
        {
            // Render the report to an image
            Warning[] warnings;
            string[] streamIds;
            string mimeType;
            string encoding;
            string extension;

            byte[] bytes = report.Render(
                "Image", null, out mimeType, out encoding, out extension,
                out streamIds, out warnings);

            using (System.Drawing.Image image = System.Drawing.Image.FromStream(new System.IO.MemoryStream(bytes)))
            {
                args.Graphics.DrawImage(image, args.MarginBounds);
                args.HasMorePages = false;
            }
        };

        // Print the document
        printDoc.Print();
    }

}


If there is a more simple way. I’m all ears.

Any help is appreciated.

Thanks in advance !

Im expecting to print directly to a POS printer with dynamic data.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật