PDFsharp & MigraDoc Foundation http://forum.pdfsharp.com/ |
|
Create new document from existing http://forum.pdfsharp.com/viewtopic.php?f=2&t=4284 |
Page 1 of 1 |
Author: | pournaras [ Wed Aug 25, 2021 1:43 pm ] |
Post subject: | Create new document from existing |
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? |
Author: | TH-Soft [ Thu Aug 26, 2021 8:17 am ] |
Post subject: | Re: Create new document from existing |
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. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |