RDLC printing on half A4

What i want to accomplish

Requirement: Print an A4-wide receipt and half-height A4 and rotate it so that it can be printed on continuous A4 (CCP).

enter image description here

What i always get

enter image description here

What i tried

The RDLC report is defined as 205 mm x 145 mm, so it should fit well into the available space.
I tried the following

  • printing on A4 paper
  • printing on A4 paper
  • create your own paper size, defined as 210 x 147, and print portrait and landscape
  • enter the PrintingBegin ReportViewer event and set DefaultPageSettings to the same paper size

Nothing helped. It seems that I remember something that if the height of the report is less than the width, the printout automatically rotates to landscape. I don’t know if this function can be disabled ...

Update: Page size - 208 mm x 147 mm, margins on all sides 12 mm. The body of the report is 173 mm x 121 mm.

+4
source share
2 answers

I'll try. I assume that you are using a set of printing libraries that work well at a high level, but you should use something more "manual". My dad has a cafe, and I made him software for software. The receipt printer prints only those lines that are needed for the code that I will give you. I guess moving in this way might work for you.

This method does not print images, only text, which is important to know.

The printing methods in my code seem to be different from yours; they are "sensitive to characters." This means that if you need 3 spaces, then you have to write 3 spaces and then the text.

To run this code, you will need to create ".txt" and then send this text file as an argument to the print class. I'm not sure if you are using C # or VB, my code is in C #.

So, firstly, to create a text file anywhere in your program, you need a heading:

 using System.IO; 

Then at the point you need to start the text file:

 StreamWriter sw = new StreamWriter("receipt.txt"); 

This creates a file in your current folder - the same your .exe is located at. It will also overwrite the old ones, so you don’t have to worry about whether a file with the same name already existed. To write your receipt lines, you will use:

 sw.WriteLine(" the text is supposed to be written, you may use concatenations "); 

The WriteLine method writes a line of text to a file and then moves on to the next line.

When you finish writing, you need to close the file with ...

 sw.Close(); 

You will need to call the print class that I give you. Assuming you already have this, you need to instantiate it, as in:

 PimpMyPrint p = new PimpMyPrint(); 

And then call the PrintDoc method with ...

 p.PrintDoc("receipt.txt"); 

Once again, you need a class with all the necessary methods. I DO NOT ACCEPT CREDIT FOR THIS CLASS; This is the work of the author Francisco Javier Cebalos from Spain. Mr. Cebalos is a well-known author in the Spanish SD community, and this is from his book "Microsoft C # Curso de programación".

So here is the class you need to add:

 using System; using System.IO; using System.Drawing; using System.Drawing.Printing; namespace SomeNamespace { class PimpMyPrint { private Font font; private StreamReader sr; public void PrintDoc(string textfile) { try { sr = new StreamReader(textfile); try { font = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(this.PrintPage); pd.Print(); } finally { sr.Close(); } } catch (Exception e) { Console.WriteLine(e.Message); } } private void PrintPage(object obj, PrintPageEventArgs ev) { float LinesPerPage = 0; float pos_Y = 0; int count = 0; float marginLeft = ev.MarginBounds.Left; float marginUP = ev.MarginBounds.Top; string line = null; float fontHeight = font.GetHeight(ev.Graphics); LinesPerPage = ev.MarginBounds.Height / fontHeight; while (count < LinesPerPage && ((line = sr.ReadLine()) != null)) { pos_Y = marginUP + (count * fontHeight); ev.Graphics.DrawString(line, font, Brushes.Black, 0, pos_Y, new StringFormat()); count++; } if (line != null) ev.HasMorePages = true; else ev.HasMorePages = false; } } } 

I hope this works for you as well as it worked for me!

+1
source

I had the same issue when printing a while ago, I thought I should share a solution that worked for me. If you used an alternative route, you can also share, I would like to see what worked for you.

there is a trick, you need to create a report as a square, i.e. width = 210 mm and height = 210 mm, but use the first 145 mm of the report from top to bottom to place objects.

Leave a bottom clearance of 65 mm.

+1
source

All Articles