PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Nov 09, 2024 12:02 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
 Post subject: PDFSharp and Migradoc
PostPosted: Fri Apr 12, 2024 1:55 pm 
Offline

Joined: Fri Apr 12, 2024 1:37 pm
Posts: 3
Hi,

I'm new to PDFSharp and Migradoc. I'm trying to print a simple report to get the feel of it. I'm using VB.Net in Visual Studio 2022.

I'm getting an error that says that MUH and MFEH are not members of gfx. Any guidance would be appreciated !! Thanks !!

Coding below


Private Sub ClientsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClientsToolStripMenuItem.Click


Dim Document As New PdfDocument
Dim oProcess As New Process

Document.Info.Title = "Client Inventory Listing"

Dim Page As PdfPage = Document.AddPage
Dim gfx As XGraphics = XGraphics.FromPdfPage(Page)

GlobalFontSettings.FontResolver = New FailsafeFontResolver

Dim pen As New XPen(XColor.FromArgb(255, 0, 0))
Dim Font As New XFont("Verdana", 20, XFontStyleEx.Bold)
gfx.DrawString("This is test of the Client List", Font, XBrushes.Black, New XRect(0, 0, Page.Width.Point, Page.Height.Point), XStringFormats.Center)

If Not System.IO.Directory.Exists("C:\ClientReports") Then
System.IO.Directory.CreateDirectory("C:\ClientReports")
End If

Dim filename As String = "C:\ClientReports\Clients.PDF"
Document.Save(filename)

PDFPage(Document)

With oProcess
.StartInfo.UseShellExecute = True
.StartInfo.Arguments = filename
.StartInfo.FileName = "Acrobat.exe"
.StartInfo.Verb = "Open"
.Start()
.WaitForExit()
.Close()
End With


End Sub


Private Sub PDFPage(document As PdfDocument)


Dim page As PdfPage
page = document.AddPage()
Dim gfx As XGraphics
gfx = XGraphics.FromPdfPage(page)

' HACK²
gfx.MUH = PdfFontEncoding.Unicode
gfx.MFEH = PdfFontEmbedding.Always
Dim font As XFont = New XFont("Verdana", 13, XFontStyleEx.Bold)

gfx.DrawString("The following paragraph was rendered using MigraDoc:", font, XBrushes.Black,
New XRect(100, 100, page.Width.Point - 200, 300), XStringFormats.Center)


' You always need a MigraDoc document for rendering.
Dim doc As New MigraDoc.DocumentObjectModel.Document
Dim sec As Section = doc.AddSection()

' Add a single paragraph with some text and format information.
Dim para As Paragraph = sec.AddParagraph()
para.Format.Alignment = ParagraphAlignment.Justify
para.Format.Font.Name = "Times New Roman"
para.Format.Font.Size = 12
para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray
para.AddText("Duisism odigna acipsum delesenisl ")
para.AddFormattedText("ullum in velenit", TextFormat.Bold)
para.AddText(" ipit iurero dolum zzriliquisis nit wis dolore vel et nonsequipit, velendigna " &
"auguercilit lor se dipisl duismod tatem zzrit at laore magna feummod oloborting ea con vel " &
"essit augiati onsequat luptat nos diatum vel ullum illummy nonsent nit ipis et nonsequis " &
"niation utpat. Odolobor augait et non etueril landre min ut ulla feugiam commodo lortie ex " &
"essent augait el ing eumsan hendre feugait prat augiatem amconul laoreet. ≤≥≈≠")
para.Format.Borders.Distance = "5pt"
para.Format.Borders.Color = Colors.Gold

' Create a renderer and prepare (=layout) the document
Dim docRenderer As MigraDoc.Rendering.DocumentRenderer = New DocumentRenderer(doc)
docRenderer.PrepareDocument()

' Render the paragraph. You can render tables or shapes the same way.
docRenderer.RenderObject(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(10), "12cm", para)
End Sub


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 12, 2024 2:16 pm 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1007
Location: CCAA
MUH and MFEH are old hacks that have been removed from PDFsharp 6.0. Just take those lines out.

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 12, 2024 3:24 pm 
Offline

Joined: Fri Apr 12, 2024 1:37 pm
Posts: 3
Thank you. I will try that


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 12, 2024 3:37 pm 
Offline

Joined: Fri Apr 12, 2024 1:37 pm
Posts: 3
Thank you for the previous reply, however I'm now getting a similar run time error when this code is executed:

docRenderer.PrepareDocument()

I will attach a copy of the error


Attachments:
Error.JPG
Error.JPG [ 24.85 KiB | Viewed 20008 times ]
Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 14, 2024 12:46 pm 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1007
Location: CCAA
A screenshot of the exception without the details (left button) is pretty useless.

You probably still have code that references the old library.

See also:
https://docs.pdfsharp.net/General/Issue-Reporting.html

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


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 8 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