I’m building a .Doc programatically (using Aspose.Words), which has only page width limitations, I don’t have page height limitations because it will be printed in a roll of paper (see thermal printers), and the document will have variable height.
I tried this approach: c# - Printing .DOC with variable height in continuous paper (paper roll) with "Aspose Words" - Stack Overflow
Hi Luciano,
Could anyone post some code on this topic. We face the same issue that we need to print a receipt from a card terminal to PDF. As these types of receipts are always printed from a roll, we need to adjust the paper-height to fit the content of the receipt.
@Jan_Gils You can specify page height using PageSetup.PageHeight properly. But as it was already mentioned maximum height of page is limited to 1584 points or 22 inches.
@alexey.noskov Thanks for the answer. I know of this property, but how do you determine the height based on the text content of the document. So basically, set the height to fit the content.
So far I’ve been trying the following approach with the mailmerge:
- The template document has a table with 1 row and a mergefield in it.
- After executing the mailmerge, I get the height of the row in the table.
- Adjust the pageheight to the height of this row.
The problem is that the rowheight remains 0, although through a mailmerge the content was injected.
@Jan_Gils You can get pages count and multiply by page height without top and bottom page margins. This will give an approximate content height in the document. But note this trick will work only if all pages has the same page size and orientation.
For future reference, there is a pretty exact way of accomplishing this using the LayoutEnumerator:
https://github.com/aspose-words/Aspose.Words-for-.NET/issues/242
I noticed that if you add the BottomMargin * 1.5 the results are pretty perfect and consistent:
var collector = new LayoutCollector(doc);
var enumerator = new LayoutEnumerator(doc);
enumerator.Current = collector.GetEntity(doc.FirstSection.Body.LastParagraph);
ps.PageHeight = enumerator.Rectangle.Bottom + ps.BottomMargin * 1.5;
@Jan_Gils It is perfect that you managed to achieve what you need. Please feel free to ask in case of any issues. We will be glad to help you.