Printing in Continuous Paper (paper roll)

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.


What kind of approach shall I take ? Create a paper of any height but with zero top and bottom margin, or dynamically change the paper (page) height ?

Any solution are welcome, but I would prefer to have a doc inside a unique page (long as needed), because these printers can cut the paper in some situations, like on each page break.

Regards,

Luciano

I tried this approach: c# - Printing .DOC with variable height in continuous paper (paper roll) with "Aspose Words" - Stack Overflow

Hi Luciano,


Thanks for your inquiry. Microsoft Word limits the paper height to 22". I think, you can remove top, bottom margins and empty headers/footers from your document before printing. You can also remove explicit Page Breaks from document using Aspose.Words. As an option, you can convert your Word document to HTML (page less format) and then print this HTML but 100% fidelity is not guaranteed in this case. Please let me know if I can be of any further assistance.

Best regards,

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:

  1. The template document has a table with 1 row and a mergefield in it.
  2. After executing the mailmerge, I get the height of the row in the table.
  3. 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.