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

Landscape Page in Powershell?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1953
Page 1 of 1

Author:  dpc [ Sat Mar 24, 2012 3:08 am ]
Post subject:  Landscape Page in Powershell?

Hi Folks,

The following PowerShell code works on converting me a img (jpg,png, etc) to a PDF

Code:
[reflection.assembly]::loadfrom("C:\assemblies\PdfSharp.dll ") | out-null

Function Img2PDF {
   Param($img, $pdf)

   #  Create a new PDF document
   $document = new-object PdfSharp.Pdf.PdfDocument
   #  Create an empty page
   $page = $document.AddPage()
   
$page.Orientation

   #  Get an XGraphics object for drawing
   $gfx = [PdfSharp.Drawing.XGraphics]::FromPdfPage($page)
   
   #$image = New-Object PdfSharp.Drawing.XImage
   $image = [PdfSharp.Drawing.XImage]::FromFile($img)

   $gfx.DrawImage($image, 0, 0, $page.Width, $page.Height)

   #  Save the document...
   $document.Save($pdf)
}

Img2PDF -img c:\test\123.png -pdf c:\test\test123.pdf


I cant seem to figure out the last part on how to get the page to landscape. I have looked at the PDFSharp Page Sizes example but cant seem to get it to work. In the above "$page.Orientation" will print out "Portrait" (ie its working) but I want to set the page to Landscape.

Thoughts?

~dpc

Author:  dpc [ Sat Mar 24, 2012 3:13 am ]
Post subject:  Re: Landscape Page in Powershell?

Trying
Code:
$page.Orientation = $page.Orientation.Landscape
gives out this error:
Quote:
Exception setting "Orientation": "Cannot convert null to type "PdfSharp.PageOrientation" due to invalid enumeration values. Specify one of the following enumeration values and try again. The possible enumeration values are "Portrait, Landscape"."
At C:\1.ps1:11 char:8
+ $page. <<<< Orientation = $page.Orientation.Landscape
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException

Author:  dpc [ Sat Mar 24, 2012 3:50 am ]
Post subject:  Re: Landscape Page in Powershell?

This works
Code:
$page.Orientation = "Landscape"


~dpc

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