PDFsharp & MigraDoc Foundation http://forum.pdfsharp.com/ |
|
Problems with taming PDFSharp and MigraDoc (VB.NET2017)... http://forum.pdfsharp.com/viewtopic.php?f=2&t=3814 |
Page 1 of 1 |
Author: | WarFred [ Mon Jul 23, 2018 10:00 am ] |
Post subject: | Problems with taming PDFSharp and MigraDoc (VB.NET2017)... |
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. |
Author: | TH-Soft [ Mon Jul 23, 2018 11:57 am ] |
Post subject: | Re: Problems with taming PDFSharp and MigraDoc (VB.NET2017). |
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. |
Author: | WarFred [ Mon Jul 23, 2018 6:16 pm ] |
Post subject: | Re: Problems with taming PDFSharp and MigraDoc (VB.NET2017). |
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. |
Author: | Thomas Hoevel [ Tue Jul 24, 2018 7:47 am ] |
Post subject: | Re: Problems with taming PDFSharp and MigraDoc (VB.NET2017). |
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. |
Author: | WarFred [ Tue Jul 24, 2018 8:42 am ] |
Post subject: | Re: Problems with taming PDFSharp and MigraDoc (VB.NET2017). |
Hi Thomas, I misunderstood your Advice, sorry. Now I changed the Coding and it works! Thx for Help. Michael |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |