PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jul 01, 2024 2:13 pm

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: Sat Mar 24, 2012 3:08 am 
Offline

Joined: Sat Mar 24, 2012 2:54 am
Posts: 3
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


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 24, 2012 3:13 am 
Offline

Joined: Sat Mar 24, 2012 2:54 am
Posts: 3
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


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 24, 2012 3:50 am 
Offline

Joined: Sat Mar 24, 2012 2:54 am
Posts: 3
This works
Code:
$page.Orientation = "Landscape"


~dpc


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: No registered users and 18 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