Printing to a Dot Matrix Printer - c#

I am printing a rdlc report to Dot matrix printer using this code . The report is in the format of a bill receipt. What i want is that the printer should stop exactly at the point where the receipt is fully printed (i.e. the end of the text to be printed) and not take in the rest of the paper and print nothing on it.
As loads of receipts are to be printed and there can be long queues, it will be time consuming if the end user has to reload the paper (which has been wasted) back to the printer. Hence i am looking for way by which the printer can stop the paper intake as soon as the text to be printed is complete.

It sounds like what you're asking for is how to print receipts as a continuous stream, instead of page by page. The code you linked to is entirely page driven and page oriented. You can work within a page-dominated view system, but you're going to have to do extra work.
You should be able to print multiple things on one page by changing the PrintPage code to output more than one image chunk per page. You will have to manage the offset of each rectangle to place the 2nd image below the 1st, and you will have to figure out what you want to do with the next report page does not fit on the space remaining on the current page. I expect the output will be clipped to the current page, so if you draw outside the page boundaries (past the end of the page) nothing will be output.
You could choose to advance to the next page when the next report image does not fit in the space remaining on the current page.
Or, you could print as much as will fit on this page, and then print the rest of that report image on the top of the next page. To do this, you will need to calculate the intersection of the remaining space on page 1 and the report image rectangle, and save the height of that intersection. End the page. When page 2 rolls around, print that same report image again, but this time offset the output rect by the height of the rectangle that was printed on the previous page. This is assuming a clipping rectangle is already in place on the print device handle (which is very likely).
The downside of splitting a report across pages like this is that you may end up with graphs or even lines of text that are cut off or split between pages. These will be hard to read. If you know the font height and line spacing and how the report is laid out I suppose you could make a calculated guess about where the lines of text fall in the output rectangle and round your output rectangle down to the nearest whole multiple of the line height, but this is getting deep into hacky kludge territory.

Related

Page resolution of the printed version of a document printed from a RichTextBox

I have a RadRichTextBox that have a RadDocument loaded. This is then used to print mentioned document using richTextBox.Print().
The main problem is that the resolution of the printed page is tied to the zoom of the document in the viewer (RadRichTextBox), i.e. if I have the document zoomed way out (small pages on screen) the resolution on the printed paper is terrible. On the other hand, if I zoom in, the resolution becomes really good.
Obviously, I want to always print at the best possible resolution, is there a way to achieve this?
In the end I went with a work around that works by saving the scaling, setting it to a high number, then restoring it after printing the document.
Size sf = richTextBox.ScaleFactor;
richTextBox.ScaleFactor = new Size(10,10);
richTextBox.Print(/*... settings ...*/);
richTextBox.ScaleFactor = sf;
This looks weird, as the documents zooms in while the document is printing, but the printed document have a proper resolution.

Printing long receipt pdf to fit on receipt paper

I want to print a very long PDF with a receipt printer (Epson TM-T88IV).
The PDF I want to print however is predefined (I cannot change how the file is produced).
When I want to print this PDF with the Receipt printer, it prints it very very small and the receipt is unreadable.
There is a large margin left and right. To me, it looks like the Receipt printer wants to print the PDF onto a very small area.
if (type == PRINTER_TYPE.RECEIPT)
{
settings.DefaultPageSettings.Landscape = false;
settings.DefaultPageSettings.PaperSize = (new PaperSize("Roll Paper",(int)(80*0.254), (int)(297 * 0.254))); //PaperSize is taken from the Printer Settings multiplied with a hundreth of an inch
}
I couldn't find anything related.
€dit:
After some testing and printing multiple documents. I found out that the PDF Documents that print correctly have a correct Size
This one prints correctly, everything can be read when printed:
This one cannot, as it is only one large page (What I want to print ):
Is it possible to ignore the height and let the printer print the whole page correctly?
PDF pages have a fixed size, both width and height. The receipt printer is most likely shrinking the page down while preserving the aspect ratio to fit it onto the paper.
Without a way to change the PDF itself, including the layout, I'm afraid you won't be able to fit it in a legible way on to the printer.

In iText 7 .net , how to determine data coordinates

I have a pdf that I want to grab a specific piece of info from.
My issue isn't how do I get it, my issue is I'm not under standing the coordinates of the rectangle.
I get the x,y, height & width, but not as it related to the actual page.
lets say for arguments sake I have a business letter with the date to the far right and address to far left. How do I grab the date?
ex:
(space space space space space space space space ) 01/02/2017
Mr Jones
some Address
blah, blah, blah.
Dear....
When ever I have tried to reference where I think the date should be, I end up with an empty value.
Thanks for any thoughts and or suggestions.
This is just one of the tries:
Rectangle rect = new Rectangle(96, 822, 72, 8);
This is harder than you might think.
Content isn't just placed on a page.
It's placed on a box on a page.
Both the content, the box, and the page are allowed to have custom transformations, and rotations.
And then of course there is the issue of how the coordinate system is defined. The origin usually lies in the bottom left corner. But this is again something that can be configured.
I would debug your problem by implementing a simple class that extends SimpleTextExtractionStrategy. In the method eventOccurred you should see events passing by of type TextRenderInfo. Those events contain the text being rendered and the bounding box. Print out the text, and its corresponding bounding box. Then at least you know where iText thinks your content is.

ReportViewer 2010 control either prints part of a table on a separate page or prints an extra empty page

I just started using ReportViewer control VS2010 (web, local).
My report is very simple - 4 columns, all fit on a screen fine.
When I click "print" button, the report is printed on 2 pages ( 2 columns on one and 2 on another).
If I change the margins on a page, all 4 pages are printed on the same page but I still have 2nd empty page printed as well.
If report spans across multiple pages (2 for example), with margins changed I get first page, second page is empty, then third page fine and the fourth page is empty.
Any suggestion how to make the report printed without empty pages?
Thank you,
Jenny
In my experience (which has been a painful one...), I found that if the report is printing an extra page it means that somewhere, your margins or page size of the subreports (if you're using any) are not equaling 8.5 X 11 (or whatever size paper you're using). make sure that your your table (i'm assuming that's what you're using?) is in the bounds of a sheet of paper. keep in mind you need take an inch of of each side (if you're using .5" margins [.5" for each side]) to keep the table on one page.
I had the same problem and m.webster's answer was spot on for me.
Check that the SIZE property of the reports BODY is within your REPORTs Pagesize and Margin properties.
In my case, I had set my report to A4 and the properties of the report (click in the grey area of the designed) showed: PageSize: 21cm, 29.7cm. I built my report but printing resulted in content spilling over to a second page.
When I turned on the RULER option, it was immediately obvious that my reports BODY (white content area) was wider that then PageSize of the Reports page size.
When I reduced the BODY's size->width property down to 21cm (after rearranging all my content to allow this resizing) I found there I was still getting the second page problem. A quick change to the reports margins down to 0 resolved this.
The final white space problem I had was an empty page appearing at the end of some of my reports. This was resolved by reducing the height of the reports BODY so that there was no blank space after my content. Because the initial report body appears in a nice portrait layout, I had assumed that it was just representing the final page which was not the case.
Its a bit of a late answer to the problem but I've added it to save someone else the wasted hour of head scratching when using this slightly unintuitive piece of kit.

iTextSharp self-expanding page width

I'm writing a web application to generate labels. The label printer that I'm targeting utilizes 12mm tape and the customer specified that they want to limit the labels to 3.25". I know that with iTextSharp I can specify the size of the document I want to create, however it appears that I have to specify both a width and height.
Document document = new Document(new iTextSharp.text.Rectangle(234f, 33.84f));
234 is 3.25" converted to points, and 33.84 is 12mm converted to points, so this sets the document to the maximum size allowed. Is there any way to set just the height and let the document auto-expand to the amount of content? With that, is there a way to determine if the expanded width of the document exceeds to maximum allowed by the customer? Thanks in advance for any help you can offer.
No, that is not possible in iText. It's not a particularly good idea anywhere else either. As Redman said, PDF is a print-based format. It's not HTML.
There are some tricks you can do to get around this to some extent:
Create your page with the maximum legal height. 200" * 72dpi = 14400 points.
Add a "generic tag" to your paragraphs.
create a tag event handler that tracks where the bottom of your last paragraph was drawn.
Save the PDF.
Open it again with a PDFStamper
Set the bottom of the page to match the location of that last paragraph. Remember that the bottom left starts off at 0,0, and the top right will be
Save the final PDF
This trick will only work if your total output is less that 200" high. If you go over that, you'll still get a second page, and your "where the bottom is" code had better be prepared for it.
PS: I don't see what's wrong with having a number of 12mm x 3.25" pages... won't that perfectly fit the labels they want printed?
As far as I know, because PDF is a print format, the document width and height must be set.
This is why reporting tools generally default page sizes to the default printer page size.
You best bet to try and calculate the size of the content and create the PDF accordingly.
Depending on the volume and nature of the workflow, you could provide a preview for the customer to check before printing.

Categories

Resources