Printing long receipt pdf to fit on receipt paper - c#

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.

Related

How to set up and print with custom paper size in C# printdocument?

I am trying to use PrintDocument and set up the paper size to print or barcode thermal printer. Because I don't have the printer nearby I am using Microsoft Print To PDF option which appeared in Win10.
During initialization I have such code:
As you see, here I am trying to set up custom paper size for default paper size. But, I cannot specify Kind property, because it's readonly! RawKind property not helps.
As alternative I have such event. It does not help either. It correctly displays the page layout on preview, but in PDF document I observe pages printed in A4, as by default.
private void PrintDoc_QueryPageSettings(object sender, QueryPageSettingsEventArgs e)
{
PageSettings nSettings = new PageSettings();
int properWidthInHundretsOfInches = (int)(handlingClassRef.newconfig.labelParameters.barcodeLabelWidthMM * (1.0 / 25.4) * 100.0);
int properHeightInHundretsOfInches = (int)(handlingClassRef.newconfig.labelParameters.barcodeLabelHeightMM * (1.0 / 25.4) * 100.0);
nSettings.PaperSize = new PaperSize("label", (int)properWidthInHundretsOfInches, (int)properHeightInHundretsOfInches);
e.PageSettings = nSettings;
}
I am aware of question How to print with custom paper size in winforms , but I don't actually understand the answer. Should I reconfigure printer by using printer properties OS dialog? I would like rather not to require user to modify settings of of printer in one way or another. Also, I'd like to achieve appropriate result during printing to pdf exploration phase.
How to set up and print with custom paper size in C# printdocument?
Edit: using the line:
printDoc.DefaultPageSettings.PaperSize = new PaperSize("label", properWidthInHundretsOfInches, properHeightInHundretsOfInches);
did not resolve question.
Here is a result:
preview is nice and small but printed document is large and has not proper page size
You can try by initialising PaperSize class under System.Drawing.Printing and then you can specify the custom size
printDoc.DefaultPageSettings.PaperSize = new PaperSize("MyPaper", 600, 800);
I found the solution for this!
The Short Answer is :
printDocument1.DefaultPageSettings.PaperSize = new PaperSize("MyPaper", 700, 900);
Why it's printing A4 Paper Size, Not Full Report?
Because The Default Virtual pdf printer in Windows Microsoft Print To Pdf uses A4 Paper Size, you can try to change it to A5 from the Control Panel And try to print it again. You will notice that it has included more lines on the pdf output!
So don't worry, the code I have mentioned is Correct, but it depends on the printer you use. Because printers Use only Some Formatted Paper Sizes and it will not accept more pages out of the frame.
See This picture for more explanation
..
First, I was furious Because of this problem,
I thought that printpreviewDialog1 had another Printable area, and I tried to make it as exact as printdocument1, and then I noticed it's just a viewer.
After hours of research and many tries, I noticed that the printer wouldn't accept Any more lines; I was working on a Cashier report. I needed to make a long paper for the thermal printer, but when I was testing on the "print to pdf" printer, it didn't Print all the lines on preview control because it just prints to A4 size, mo more and no less!

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.

Continuous Labelling using iTextSharp PDF

I have working iTextsharp code for printing labels. Now the problem is, I have a requirement to print the labels in Continuous paper which i am not able to select in iTextsharp configuration (iTextSharp.text.PageSize.A4). Please advice how can i select the page size according to my current scenario.
Thanks
Your problem is related to PDF as a document format. In PDF, the content is distributed over different pages. You can define the size of such a page yourself. You mention iTextSharp.text.PageSize.A4, but you can define the page size as a Rectangle object yourself. See iTextsharp landscape document
If you want a long, narrow page, you could define the page size like this:
Document Doc = new Document(new Rectangle(595f, 14400f));
There are some implementation limits though. The maximum height or width of a page is 14,400 user units. See the blog post Help, I only see blank pages in my PDF!
However, I am pretty sure that you don't want to create a long narrow page. If you want to print labels on "continuous paper", you want to create a PDF document in which every page has the size of exactly one label. Your PDF will have as many pages as there are labels.
Suppose that the size of one label is 5 by 2 inch (width: 12.7cm; height: 5.08cm), then you should create a document like this:
Document Doc = new Document(new Rectangle(360, 144));
And you should make sure that all the content of a label fits on a single page. Your label printer should know that each page in the PDF should be printed on a separate label.
(Thank you #amedeeVanGasse for correcting my initial answer.)

Printing to a Dot Matrix Printer

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.

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