PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Convert PDF to a two lane/column PDF
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4733
Page 1 of 1

Author:  raymond [ Thu Nov 28, 2024 12:19 pm ]
Post subject:  Convert PDF to a two lane/column PDF

Hello,

I am an PDFSharp rookie.
Can someone help me on the way with this?
I have one label PDF and I want to convert this to a new PDF document with twice this label PDF next to eachother (two columns/lanes).

Author:  TH-Soft [ Mon Dec 02, 2024 5:17 pm ]
Post subject:  Re: Convert PDF to a two lane/column PDF

Sounds as if the Two Page on One sample does more or less what you need:
https://www.pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx

Author:  raymond [ Wed Dec 04, 2024 3:15 pm ]
Post subject:  Re: Convert PDF to a two lane/column PDF

I gave it a try (as a newbie) and it works :D

Code:
        public void MssTwoLanePDF(byte[] ssinputPDF, out byte[] ssoutputPDF) {
         ssoutputPDF = new byte[] {};
            MemoryStream stream = new MemoryStream(ssinputPDF);

            // Create the output document
            PdfDocument outputDocument = new PdfDocument();

            // Show single pages
            // (Note: one page contains two pages from the source document)
            outputDocument.PageLayout = PdfPageLayout.SinglePage;
            XGraphics gfx;
            XRect box;

            // Open the input document stream as XPdfForm object
            XPdfForm form = XPdfForm.FromStream(stream);
            double width = form.PixelWidth;
            double height = form.PixelHeight;


            // Add a new page to the output document
            PdfPage page = outputDocument.AddPage();
            page.Width = new XUnit(width * 2);
            page.Height = new XUnit(height);

            gfx = XGraphics.FromPdfPage(page);

            // Draw first lane
            //box = new XRect(0, 0, width, height);
            //gfx.DrawImage(form, box);
            gfx.DrawImage(form, 0, 0, width, height);

            // Draw second lane
            box = new XRect(width, 0, width, height);
            //gfx.DrawImage(form, box);
            gfx.DrawImage(form, width, 0, width, height);

            // Save the document...
            MemoryStream outputstream = new MemoryStream();
            //Save the document into stream
            outputDocument.Save(outputstream);

            //Save the stream as a file in the ssoutputPDF variable
            ssoutputPDF = outputstream.ToArray();


I couldn't use XRect because the output 2 PDF's were out of proportion. No idea why.
One question left, how can I achieve a margin of 1mm in the output PDF on these four positions:

- Left of the first lane
- Between the two lanes
- Right of the last lane
- Below the 2 PDF's in every lane

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/