I need to print a receipt on thermal paper from Crystal Reports. I created a print layout which works fine if printed from the preview. If I try to print from code, the printer just rolls out empty paper. The printer is installed properly (POS58). How can I properly print this from code?
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load(Directory.GetCurrentDirectory() + #"\Reports\receipt.rpt");
rptDoc.SetParameterValue("pOrderID",OrderID);
rptDoc.PrintOptions.PrinterName = "POS58";
rptDoc.PrintToPrinter(1,false,0,0);
Since I can't comment on your question, I am going to ask you here: Do you have any data on the report to show? I don't see any datasource assignment in your code, so maybe you need to provide some data to be printed.
Have you tried setting the paperSize in your code using the PrintOption in your report? I did this once; I was printing to a receipt printer but my paper was set to A4 so my actual report data were printed outside of the receipt paper. Try to send your document to a printer with A4 paper or better yet send it to oneNote so you don't waste paper and see how it prints.
As per suggestion and provided link by #HansPassant and #Juan from (C# POS receipt printing issue), i have made the changes in code and now writing the print commands directly to the printer, bypassing the driver (using RawPrinterHelper class). But still there is an issue with the POS printer receipt. It is not taking full width to print the row though the text is not cutting now and it is showing as full text (Screenshot attached)
But as you can see in screenshot, there are enough space left in between the right side border (Marked black) and where the text ends. If text is large string then it breaks into new line but not printing to the right side.The receipt is printing with max width which is up-to the end of dotted line.Rest right side part is blank.
Also, Can you tell me how to print Rupee Symbol before the price or amount while writing the print commands directly to the printer. Earlier when i was using the printer driver for a POS printer, there in c# code i was writing as following:
CultureInfo ci = new CultureInfo("hi-IN"); String.Format(ci, "{0:c}",ProductPrice);
But this is not working with print commands directly to the printer. It prints as "?" as you can see just before the price of each item in attached screenshot.
Thanks in advance.
I have a client that is asking me to add a fixed width (510 character) header record to a PDF file. They have asked that I create a new page (not problem) in which I write this fixed width header record on.
I can do this, and see the header record as page 1, followed by the original PDF. The problem is white space. The 510 character fixed width header is about 60% white space and all the ways I've tried generating the PDF cause this to be truncated. There are also line breaks where the text wraps. The client want to be able to use some OCR software they have purchased in order to read this header file from page 1.
I know very little about PDF file format. I've tried using ABCpdf, PDFsharp, and also created an RDLC and bound it to this header string and then generated a PDF from that. All 3 resulted in the same outcome.
Let me say I know how crazy this sounds, but it's what a client is requesting. I proposed several other ways in which we could solve their problem, but this (right now) is the only one they are comfortable with. They are not comfortable with me just appending the 510 characters onto the byte array, and having them separate it out programatically.
Are you looking to have a page displaying the long header? You can create a PDF page of any size (Print to PDF with a custom pages size of 20" wide by 6" tall. Weird but possible.)
Once that page is created, it can be inserted into another document of regular letter size pages.
Are you looking for consecutive pages displaying chunks of the header?
Using an OCR to read content that you put in is an overkill. Instead of rendering the 500-character header as text. Render it as single-character form fields. This way it will be easy to access those form-fields by name and retrieve the values using the same PDF library which you created the PDFs.
I am generating PDF document using iTextSharp (winforms), now i need to print this generated PDF document using a Label Printer.
I have multiple Printers installed on my machine, so with VB.net I need to Select a certain Thermal printer.
Once the Printer is Selected I need to Specify Shipping Label Size (width & height).
So Once Label Printer is selected and I specified custom Label dimensions, I would like the label to be printed without any user action (Like skip the Confitm box to print).
I dont need the full code, I just need someone to put me into right direction.
Thanks
You can use the PrintDocument object. Use the Print method, and do the actual printing in the PrintPage handler. To do this, you can output to the graphics object of the parameter PrintPageEventArgs in your PrintPage handler.
anyone can please tell me the code how to print documents on dot matrix printer in C# windows application.
You can print to dot matrix "graphically", which is built-in in Windows, albeit slower.
But if you only want to print pure text with simple formattings, you need to send escape commands to your dot matrix printer, which is faster than graphical printing. Different printers has different escape commands.
Here are typical escape commands(for epson): http://www.printfil.com/manualen/c5.htm
This might help: https://web.archive.org/web/20051212193242/http://sacpcug.org:80/archives/0306/prc0603.html
What I do in VB6 then was to print to Generic / Text Only printer, you open the PRN or LPT1 as a file handle, then print escape commands on the file handle, all escape commands will be redirected to whatever printer is attached to LPT1 or PRN. You can do the same thing with C#, just open the PRN or LPT1 as a file, then print to it.
To add Generic / Text Only printer, Control Panel > Printers > Add Printer. On manufacturer, select Generic, then on printers, select Generic / Text only.
You can do the same (printing on Generic / Text Only) for Zebra printers which have their own escape commands for printing bar codes, which is faster than letting Windows print to it graphically.
When you print to an inkjet or laser printer, you generally do not use built-in fonts of the printer. You use Windows fonts. What happens is that the printer driver either builds an image of pixels (including the text) and sends it to the printer, or sends commands designed to draw lines, spline curves, and other shapes to the printer, with fonts expressed as lines and splines (outlines).
When you print to an older dot matrix printer, you can do it that way, but it’s slow. Each line of text has to be “built” from pixels, and often the lines of text do not match up with the passes of the print head (especially for fonts much larger or smaller than 12-point).
The old way of using these printers, the way they were intended, was to send the actual ASCII codes of the text to the printer. Send the number 65 (decimal), and you get a capital (upper-case) “A” for instance. The number 49 (decimal) would print the digit “1” while the number 32 would be a blank space, 33 an exclamation point (“!”), and so on. One byte = one character. The dot-matrix printer had its own built-in font, and would look the ASCII code up in its font ROM, and from there determine the exact timings of which print wires would have to strike the page exactly when to produce those letters.
By using ESCape codes, you could specify such effects as pseudo-boldfaced (basically striking the letter twice, with the second copy shifted to the right by only one dot width), double-wide (striking each column of wires twice in a row for each one time that it would normally be struck, thus doubling the width of the letter), underline (striking the bottom print wire throughout regardless of whether the letter shape calls for it at that point or not), and so on.
The printer’s own ROM handled all of these mechanical details about print wires and such. All your program had to supply is the actual ASCII codes of the text (including control codes such as the number 13 [Carriage Return aka CR] to return the print head to the left margin [or, for a bidirectional printer, prepare to print the next line in the reverse order of the previous line], usually followed by the number 10 [Line Feed aka LF] to roll the paper up one line to prepare for printing the next line).
If you wanted to print in fancy fonts that the printer didn’t have, or print graphics, you had to use an ESCape code to set the printer into “graphics mode” in which you basically sent bytes whose bits would specify to fire the individual wires of the printhead under direct program control, rather than looking up character shapes in the printer’s Font ROM. When you print normally from Windows using a printer-specific driver, this is usually what happens.
For daisy-wheel or other fixed-character printers (e.g. IBM Selectric type-ball mechanisms), the ASCII code would spin the wheel or ball to the proper position and then strike the ribbon and thus print the letter on the page, or send the right hammer up to hit the ribbon and thus the page (TeleType or old typewriter mechanism). It was not possible to do pixel graphics with these except by printing repeated periods and micro-advancing the print head and paper the width/height of a period instead of a character / row of text, respectively (which would generally wear out the period character of the daisy-wheel or ball really quickly, so many of them had metal-reinforced periods for that very reason).
How is this different from printing on inkjet or laser printer?
MSDN: Printing Overview
Preview and Print from Your Windows Forms App with the .NET Printing Namespace
Whilst it wasn't in C#, I have written Access reports that used the native fonts of an Epson printer. It was a few year ago - using Windows XP - but when the printer was selected as the default it was possible to choose the "native" fonts of the printer via the font chooser.
It was pretty neat - I could use any font I liked for the headings, which were slow to print. Then I could select the native printer font for the detail rows, which were fast. Doing it that way I had to be careful that all the "native" font detail stauff had exactly the same vertical alignment, otherwise it became slow again.