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?