PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 19, 2018 9:14 pm

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Mon Aug 25, 2014 3:01 pm 

Joined: Mon Aug 25, 2014 2:35 pm
Posts: 1
first: thanks for this nice tool. very userfull and for me (i'm not a pro-coder) good/easy to use.

i want to implement a PDF-creating-routine into a posh-script.
My promblem at the moment: i can't get the "gfx.drawstring" to work in a function.
Without the "fill"-function (see the code) it works, so i thought it was a scope-problem, but "global/script"-Variable doesn't work either.

EDIT: the error is written below the code

Can someone help me, please. I'm thankfull for hints or solutions

EDIT: sorry, i forgot: its about PDFSharp / Ver 1.32.2608.0 / GDI+

(it's not the final script, just testing at the moment)

[reflection.assembly]::loadfrom("c:\pdfSharp.dll") | out-null

$text= "TEST test TEST test"

$options = new-object PdfSharp.Drawing.XPdfFontOptions([PdfSharp.Pdf.PdfFontEncoding]"Unicode", [PdfSharp.Pdf.PdfFontEmbedding]"Always")
$font = new-object PdfSharp.Drawing.XFont("Arial", 12, [PdfSharp.Drawing.XFontStyle]"regular", $options)
$PdfReader = [PdfSharp.Pdf.IO.PdfReader]           
$PdfDocumentOpenMode = [PdfSharp.Pdf.IO.PdfDocumentOpenMode] 
$input2=new-object pdfsharp.pdf.pdfdocument
# use existing pdf:
# $input2=$PdfReader::Open("c:\test.pdf", $PdfCodumentOpenMode::import)
# $page=$input2.pages[0]

$gfx = [PdfSharp.Drawing.XGraphics]::FromPdfPage($page)

function fill ($text="bla",[int]$x=20,[int]$y=20){

$script:gfx.DrawString($text,$script:font,[PdfSharp.Drawing.XBrushes]::Black,(new-object PdfSharp.Drawing.XRect( $x, $y, $script:page.Width, $script:page.Height) ),[PdfSharp.Drawing.XStringFormats]::Center)


$input2.Save($filename )

   . fill -text $env:computername -x "-130" -y "-315"
   . fill -text $((gp HKLM:\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters).srvcomment) -x "-130" -y "-310"


Ausnahme beim Aufrufen von "DrawString" mit 5 Argument(en):  "Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt."
Bei P:\cod\func\pdf_create.ps1:54 Zeichen:23
+ $script:gfx.DrawString <<<< ($text,$script:font,[PdfSharp.Drawing.XBrushes]::Black,(new-object PdfSharp.Drawing.XRect( $x, $y, $script:page.Width, $script:page.Height) ),[PdfSharp.Drawing.XStringFormats]::Center)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

in english sth. like:
Exception when calling "DrawString" with 5 Arguments:  Object reference not set to an instance of an object.

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: Google [Bot] and 9 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