How can I use RDLC Reports to print a receipt with variable height? The height needs to be the sum of all elements inside the report. My report can grow and shrink in size.
My device info xml used inside the export method:
<DeviceInfo>
<OutputFormat>EMF</OutputFormat>
<PageWidth>6.5cm</PageWidth>
<PageHeight>10cm</PageHeight>
<MarginTop>0cm</MarginTop>
<MarginLeft>0cm</MarginLeft>
<MarginRight>0cm</MarginRight>
<MarginBottom>0cm</MarginBottom>
</DeviceInfo>
I've tried to sum the height of each item and set PageHeight to it but this doesn't work.
Here is a MSDN page where we can find a complete example.
You can set your height to a value bigger than what you think you'll be the highest possible height. The printer will stop printing at the end of the report because it'll only see blank space. See my report below:
This works every time with my report, the only downside is that you need to make sure the report real height will never be bigger than your fixed height. Also you could do some calculation and place your variable height inside the PageHeight like this:
double totalHeight = 0; //this will be your calculated height based on report elements
var sb = new StringBuilder();
var xr = XmlWriter.Create(sb);
xr.WriteStartElement("DeviceInfo");
xr.WriteElementString("OutputFormat", "EMF");
xr.WriteElementString("PageHeight", string.Format("{0}in", totalHeight));
xr.Close();
I recently found myself looking for help about this issue. I needed to print an RDLC report (Bill kind of report) to a thermal printer, but it got cut off at 11in (Letter size). After a lot of browsing and testing Paper sizes, Report sizes, Printer settings, etc. the one thing that fixed the problem was setting the Report height to the same Printer selected paper height (In my case, RollPaper 80x3276mm). It's pretty late, but hope this could help to save time to anyone in the same problem.
Related
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!
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.
My C# application generates a Crystal Report that contains many images with varying size, orientation, and aspect ratio. To make them appear correctly in the report, I use a white Square Canvas and center the image inside. This makes lot of wasted space:
Is it possible to resize each picture in the report to the appropriate size from C#? I have found a way to resize the images here, but I don't know if I can perform these steps from c#, especially when it comes to "Calculating and setting Width and Height to the proper number of twips."
I know the size of my image in C#, but can it be passed to and implemented in the report? Images are inside an xml file in base64 format.
Designer View:
Okay, i don't have a working solution but an idea that might help you ( and i hope it will )
I searched a programmatically way to do what you want, and i don't find anything. Unless the fact that you can manipulate your FieldObject with C#, it can't be used in your report.
So, i'll try to guide you with some screenshoots, but i am French and my screens will be in french, so sorry for the bad translations !
You can write a formula to change the display of your BinaryImage in your subreport. I just found a way to change the width of you data, not the height.
So, assuming my image is stored in "ARTICLE" table, and the name of the column is "ART_IMAGE". I put my data in the detail section and create a new formula, ignore the created formula, you need to access to the "formatting formulas" :
Here in my screen it is called "Formules de mise en forme". In the left you can see my simple report and on the right the formula panel, i clicked on my details section and i can see my only field.
Now right click on this field and create a new formatting formula :
A pop up is displayed, you'll need to choose something like that in english "
Adjusting the width" :
Now, you have to return the new width of your current image, a way to know what is the current width is to store it in a field in your database.
So if in your database you have a field for your image, and a field like image_width. In my example i have a field name ART_DIMENSION and i store the width of the image.
The tricky part is that this formula accept twips not inch or cm. For you information 1 inch = 1440 twips.
So in my example here is the formula :
So for each image to display, the width of my image will be the width stored in "ART_DIMENSIONS" ( with the good convert : inch to twips )
In your report design, with a formula like this which set the width dynamically for your image, you can set the section and your image object with a very small width. In this case your images will be displayed one by another because the section width will be edited for each image to display.
I tried to be very clear, hope it will help you, ask me any questions if you don't understand something.
Regards,
I am trying to print a report using C# Report Viewer Control.
By the way, I bumped into a problem.
I wanted my .rdlc file to be printed on A4 size. so I changed .rdlc file size with A4 size 210X297(mm) in the VS2010 designer. But the report viewer object that uses this .rdlc file automatically sets the margins on the paper. So the total size of the paper that will be printed was over A4 size.
I can't estimate the size of the margin.
Is there any way to estimate or control the size of the margin?
I have been searching for the last some days...
I need help. please give me a hand.
My platform is VS2010 / .Net 4.0 / C#
Thanks tezzo for your help. I appriciate it.
My problem was which I didn't know the fact that Report > Report properties > Page setup exists.
I could resolve my problem by your advice.
But I had what makes me confused. so I leave some aditional pictures.
I hope it is helpful to another person who encounters such a problem.
You have to click the point that the picture 1 expresses by the check sign. If you click the point that the picture 2 expresses by the check sign, you can not see such a properties window that have a Margins and a PageSize Property, which makes me confused.
When you reach here, you can follow tezzo's advice. then you can print rdlc file on A4 size.
I am first to write here. so I can't add any picture on it.
I link pictures.
< picture 1>
< picture 2 >
You can set paper size and margins in Report > Report properties > Page setup.
I usually use this settings:
paper size: A4
size: 21 x 29,7 (landscape: 29,7 x 21)
left/right margin: 1,3cm
bottom/top margins: 1,5cm
So the maximum width of report will be:
21 - (1,3*2) = 18,4cm
29,7 - (1,3*2) = 27,1cm (landscape)
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.