Print reverse Word Documents

Is it possible to print word documents in reverse order? (without MS-Word)

Hi Claudio,

Thanks for your inquiry. I think, you can achieve this by rendering your document to a mlulti-page TIFF and then printing the image frames in reverse order. For example, please see the following code snippet:

// Open source document.
Document doc = new Document(@"C:\Temp\ReversePrintTest.docx");
// Save the document as an image.
using (MemoryStream imageStream = new MemoryStream())
{
    doc.Save(imageStream, SaveFormat.Tiff);
    // Load the image back into another document
    imageStream.Position = 0;
    Document imageDoc = LoadImageInReverseOrder(imageStream);
    // Print the document.
    imageDoc.Print("printername");
}
///
/// Loads an image in reverse Page order into Aspose.Words.Document object.
///
/// Stream with an image.
public static Document LoadImageInReverseOrder(Stream inputStream)
{
    // Create Aspose.Words.Document and DocumentBuilder.
    // The builder makes it simple to add content to the document.
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    // Read the image from file, ensure it is disposed.
    using (Image image = Image.FromStream(inputStream))
    {
        // Find which dimension the frames in this image represent. For example
        // the frames of a BMP or TIFF are "page dimension" whereas frames of a GIF image are "time dimension".
        FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]);
        // Get the number of frames in the image.
        int framesCount = image.GetFrameCount(dimension);
        // Loop through all frames.
        for (int frameIdx = framesCount - 1; frameIdx >= 0; frameIdx--)
        {
            // Insert a section break before each new page, in case of a multi-frame TIFF.
            if (frameIdx != 0)
                builder.InsertBreak(BreakType.SectionBreakNewPage);
            // Select active frame.
            image.SelectActiveFrame(dimension, frameIdx);
            // We want the size of the page to be the same as the size of the image.
            // Convert pixels to points to size the page to the actual image size.
            PageSetup ps = builder.PageSetup;
            ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
            ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
            // Insert the image into the document and position it at the top left corner of the page.
            Shape shape = builder.InsertImage(image,
            RelativeHorizontalPosition.Page,
            0,
            RelativeVerticalPosition.Page,
            0,
            ps.PageWidth,
            ps.PageHeight,
            WrapType.None);
        }
    }
    return doc;
}

I hope, this helps.

Best regards,

Thanks for the help. It does not work in all cases. But enough for me.

Hi Claudio,

It’s great you were able to achieve what you were looking for. Please let us know any time you have any further queries. We are always glad to help you.

Best regards,