PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Sep 17, 2021 1:27 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Aug 25, 2021 1:43 pm 
Offline

Joined: Wed Aug 25, 2021 1:34 pm
Posts: 1
Hello,

I want to create a new A3 Landscape document, based on existing A4 Portrait document.

Each page should be copied twice, to the left and right, one of the copies being rotated by 180 degrees.

I am using the following code:

Code:
Private Sub CreatePDF(input As String, output As String)
    Dim inputPDF As XPdfForm = XPdfForm.FromFile(input)

    Dim outPDF As New PdfDocument
    outPDF.PageLayout = PdfPageLayout.SinglePage

    Dim gfx As XGraphics
    Dim box As XRect

    For x As Integer = 0 To inputPDF.PageCount - 1
        Dim rotateLeft As Boolean = (x Mod 2 = 0)
        Dim page As PdfPage = outPDF.AddPage
        page.Size = PdfSharp.PageSize.A3
        page.Orientation = PdfSharp.PageOrientation.Landscape
        Dim width As Double = page.Width
        Dim height As Double = page.Height

        gfx = XGraphics.FromPdfPage(page)
        inputPDF.PageNumber = x + 1

        If rotateLeft Then
            inputPDF.Page.Rotate = (inputPDF.Page.Rotate + 180) Mod 360
        End If

        box = New XRect(0, 0, width / 2, height)
        gfx.DrawImage(inputPDF, box)

        inputPDF.Page.Rotate = (inputPDF.Page.Rotate + 180) Mod 360
        box = New XRect(width / 2, 0, width / 2, height)
        gfx.DrawImage(inputPDF, box)

    Next

    outPDF.Save(output)

End Sub


My problem is that I'm always getting two rotated copies on odd pages, while there should be one rotated copy to the left and one normal to the right (and vice versa on even pages of the A3 document)

What am I doing wrong?


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 26, 2021 8:17 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 659
Location: CCAA
pournaras wrote:
What am I doing wrong?
You modify the page. I guess it makes no difference whether you modify the page before or after calling DrawImage.

It should work with a Rotate transformation before drawing the page instead of setting the Rotate property of the page.
Cloning the page should work also, but would probably double the size of the resulting PDF file, so I would not choose this approach.

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


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 21 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