PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Dec 10, 2024 11:32 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Nov 28, 2024 12:19 pm 
Offline

Joined: Thu Nov 28, 2024 12:11 pm
Posts: 2
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).


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 02, 2024 5:17 pm 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1021
Location: CCAA
Sounds as if the Two Page on One sample does more or less what you need:
https://www.pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 04, 2024 3:15 pm 
Offline

Joined: Thu Nov 28, 2024 12:11 pm
Posts: 2
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group