PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jul 14, 2024 11:25 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: New-PDF with Powershell
PostPosted: Wed Oct 12, 2011 5:16 pm 
Offline

Joined: Wed Oct 12, 2011 1:26 pm
Posts: 5
Using example New-PDF.ps1 written by your group and was wondering how to tell the code to allow data that has carriage return, line feeds?

If I supply a variable to it as is, it renders the PDF unreadable.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 13, 2011 7:12 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
jbruns2011 wrote:
Using example New-PDF.ps1 written by your group [...]
Sorry, but AFAIK this example is not from our team.
Where did you find it so we can have a look?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 13, 2011 1:16 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
I found the sample on the web. It uses DrawString to draw a string.
Use XTextFormatter for text that spans several lines.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 13, 2011 2:29 pm 
Offline

Joined: Wed Oct 12, 2011 1:26 pm
Posts: 5
Hate to be a prick, got any samples in Powershell?


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 13, 2011 3:25 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
No, we have C# samples only (and some VB sample code), but no Powershell samples yet.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 13, 2011 3:33 pm 
Offline

Joined: Wed Oct 12, 2011 1:26 pm
Posts: 5
Any chance you could take the NEW-PDF.ps1 example and add the XTextFormatter call and publish?

Code:
param($text="Hello World",$fileName="c:\test.pdf")

[reflection.assembly]::loadfrom("C:\downloads\pdfsharp\PDFsharp\code\PdfSharp\bin\Debug\PdfSharp.dll") | out-null

#  Create a new PDF document
$document = new-object PdfSharp.Pdf.PdfDocument

#  Create an empty page
$page = $document.AddPage()

#  Get an XGraphics object for drawing
$gfx = [PdfSharp.Drawing.XGraphics]::FromPdfPage($page)

$options = new-object PdfSharp.Drawing.XPdfFontOptions([PdfSharp.Pdf.PdfFontEncoding]"Unicode", [PdfSharp.Pdf.PdfFontEmbedding]"Always")

#  Create a font
$font = new-object PdfSharp.Drawing.XFont("Arial", 20, [PdfSharp.Drawing.XFontStyle]"Bold", $options)

#  Draw the text
$gfx.DrawString(
   $text,
   $font,
   [PdfSharp.Drawing.XBrushes]::Black,
   (new-object PdfSharp.Drawing.XRect(0, 0, $page.Width, $page.Height) ),
   [PdfSharp.Drawing.XStringFormats]::Center)

#  Save the document...
$document.Save( $filename )


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

All times are UTC


Who is online

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