简体   繁体   中英

C# WPF Print pdf multi pages per sheet

I'm working on a C# WPF app that create pdf reports. After creating files, I need to print them out. The files created are in A7 format and stored in the same directory.

To help the forest, I want to print 4 files on one paper sheet :-)

I am able to print file per file. I've tried to set printer preference to stack 4 files on one sheet but it still print, one file per sheet.

I've searched over the Net for a solution but can't find my way.

Any ideas how to achieve this?

Thanks for your advise

you may render the pdf files into images - concatenate them and send to printer.

Or you may use the following code sample(as a sample I have used Apitron PDF Kit):

using System;
using System.Collections.Generic;
using System.IO;

using Apitron.PDF.Kit.FixedLayout;
using Apitron.PDF.Kit.FixedLayout.Content;

public void CombinePDFDocuments()
    {
        using (Stream stream1 = new FileStream("input1.pdf", FileMode.Open, FileAccess.Read))
        using (Stream stream2 = new FileStream("input2.pdf", FileMode.Open, FileAccess.Read))
        using (Stream stream3 = new FileStream("input3.pdf", FileMode.Open, FileAccess.Read))
        using (Stream stream4 = new FileStream("input4.pdf", FileMode.Open, FileAccess.Read))
        {
            using (FixedDocument doc1 = new FixedDocument(stream1))
            using (FixedDocument doc2 = new FixedDocument(stream2))
            using (FixedDocument doc3 = new FixedDocument(stream3))
            using (FixedDocument doc4 = new FixedDocument(stream4))
            {
                using (FixedDocument result = new FixedDocument())
                {
                    Page page = new Page(Boundaries.A4);
                    result.Pages.Add(page);

                    // Left bottom
                    page.Content.AppendContent(doc1.Pages[0].Content);

                    // Left Top
                    page.Content.SetTranslate(0, Boundaries.A7.Height);
                    page.Content.AppendContent(doc2.Pages[0].Content);

                    // Right Top
                    page.Content.SetTranslate(Boundaries.A7.Width, 0);
                    page.Content.AppendContent(doc3.Pages[0].Content);

                    // Right Bottom
                    page.Content.SetTranslate(0, -Boundaries.A7.Height);
                    page.Content.AppendContent(doc4.Pages[0].Content);

                    using (Stream outStream = new FileStream("out.pdf", FileMode.Create, FileAccess.ReadWrite))
                    {
                        result.Save(outStream);
                    }                        
                }
            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM