PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 11:47 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Jul 23, 2018 10:00 am 
Offline

Joined: Mon Jul 23, 2018 9:45 am
Posts: 3
Hi,

these are my first Steps in Creating an PDF with VB.NET. I think I have some Problems with Understanding the whole Thing, so please be patient. ;)

I have an PDF, which is an Template (only 1 Image as a Background) "back.pdf". I open this as a new pdfDocument and "select" Page(0). Now I try to write something at a specific point of the Document.
But nearly all Tries failed.

So, I copied a snipet from the PDFSharp-Wiki (Under First Page) and I get an Error "the --Operator is not defined for XUnit and Integer" (I have the german Version, so I have to translate - I hope I got it!).

Here is my Code:

Code:
    Private Sub PdfFuellen()
        Dim pdf As PdfDocument = New PdfDocument()
        Dim Ausgabe As String = ""

        pdf = PdfReader.Open("Gfx\back.pdf")
        Dim pdfPage As PdfPage = pdf.Pages(0)
        Dim graph As XGraphics = XGraphics.FromPdfPage(pdfPage)
        Dim font As XFont = New XFont("Andalus", 30, XFontStyle.Regular)
        Ausgabe = "something"
       
        graph.DrawString(Ausgabe, font, XBrushes.Black, New XRect((100, 100, --> pdfPage.Width - 200 <--, 300), XStringFormats.Center)
        Dim pdfFilename As String = "firstpage.pdf"
        pdf.Save(pdfFilename)
        Process.Start(pdfFilename)

    End Sub


I marked the Error with "--> <--".

Could you please help me? What went wrong?

Thx in advance
Michael

[EDIT] The PageSize of this Document is A5 and Landscape. And I use the newest Version of PDFSharp 1.50.4845-rc2a (from nuget.org) - yesterday downloaded and installed.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 23, 2018 11:57 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
Hi!

The error message says it all: pdfpage.Width is type "XUnit", but a double is expected.
Maybe try pdfpage.Width.Point (if that's what you want). This will return a double. I guess this is what C# does implicitly.

Edit: Point is Double, not Integer. XRect expects four Double values. Points are not Pixel, so fractions make sense.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 23, 2018 6:16 pm 
Offline

Joined: Mon Jul 23, 2018 9:45 am
Posts: 3
Nope, that's unfortunately not the Solution:

Code:
        Dim posY As Integer
        -->posY = pdfPage.Width - 200<--


throws the same Error! And the Error-Message seem to me like the "-" is not an valid Operator.
Strange is, that I just copied the Wiki-Entry and the Error appears.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 24, 2018 7:47 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Hi!
WarFred wrote:
Nope, that's unfortunately not the Solution
You are not trying the suggested solution, instead you repeat the same error.

To use the suggested solution, you could write:
Code:
graph.DrawString(Ausgabe, font, XBrushes.Black, New XRect((100, 100, --> pdfPage.Width.Point - 200 <--, 300), XStringFormats.Center)

You do not need a variable of type Integer (actually you get a Double, not an Integer), you just have to add ".Point" to obtain a numerical value from the XUnit object.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 24, 2018 8:42 am 
Offline

Joined: Mon Jul 23, 2018 9:45 am
Posts: 3
Hi Thomas,

I misunderstood your Advice, sorry.

Now I changed the Coding and it works!

Thx for Help.
Michael


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

All times are UTC


Who is online

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