PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 4:29 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: Hello World freezing
PostPosted: Tue Aug 09, 2016 7:40 am 
Offline

Joined: Tue Aug 09, 2016 7:34 am
Posts: 6
I'm having some trouble getting started with the Hello World sample.

I have this code (from HelloWorld):

Code:
#I "../../packages/PDFSharp-MigraDoc/lib/net20/"
#r "PdfSharp.dll"
#r "MigraDoc.Rendering.dll"
#r "MigraDoc.DocumentObjectModel.dll"
open PdfSharp
open PdfSharp.Pdf
open PdfSharp.Drawing
open System.IO

let generate () =
    let d = new PdfDocument()
    let p = d.AddPage()
    let gfx = XGraphics.FromPdfPage p
    let font = XFont("Arial", 15., XFontStyle.Regular)
    let topLeft = XPoint (0., 0.)
    gfx.DrawString("Hello, World!",
                   font, XBrushes.Black,
                   XRect(topLeft, XSize(100., 20.)),
                   XStringFormats.Center)
    use fs = File.OpenWrite("./HelloWorld.pdf")
    d.Save(fs)

Generation.generate ()


But it just hangs on DrawString with one core pegged at 100%.

Packages in use:

Code:
NUGET
  remote: https://www.nuget.org/api/v2
    FSharp.Core (4.0.0.1)
    PDFsharp-MigraDoc (1.50.4000-beta3b)


Runtime version:

Code:
$ mono --version
Mono JIT compiler version 4.4.2 (mono-4.4.0-branch-c7sr1/f72fe45 Wed Jul 27 16:20:13 EDT 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
   TLS:           normal
   SIGSEGV:       altstack
   Notification:  kqueue
   Architecture:  x86
   Disabled:      none
   Misc:          softdebug
   LLVM:          yes(3.6.0svn-mono-master/a173357)
   GC:            sgen


Same for nuget PdfSharp (1.32.3057)


Top
 Profile  
Reply with quote  
 Post subject: Re: Hello World freezing
PostPosted: Tue Aug 09, 2016 11:51 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 339
Hi!

Things you can try:
  • Add a Font Resolver (implement IFontResolver) and use a private font (your framework could be unable to read the font Arial from the operating system - it should not hang and it does not hang under Windows, but things could be different with Mono)
  • Use the source code package - this allows you to step through DrawString to see where it hangs
  • Try if the C# Hello World sample works
  • Try the F# sample under Windows

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
 Post subject: Re: Hello World freezing
PostPosted: Wed Aug 10, 2016 5:54 pm 
Offline

Joined: Tue Aug 09, 2016 7:34 am
Posts: 6
Hi there,

Sure I can try that; but to "implement your own font resolver" is a high threshold to cross as a beginning user of a library.

How about I send a PR to integration-test on Travis CI, if you point me to the github repository I can do it for? That way, perhaps you could have a look at testing your project and I'll can focus on what I'm good at?


Top
 Profile  
Reply with quote  
 Post subject: Re: Hello World freezing
PostPosted: Wed Aug 10, 2016 9:28 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 339
haf wrote:
Sure I can try that; but to "implement your own font resolver" is a high threshold to cross as a beginning user of a library.
Using a font resolver is rather simple IMHO.
You can use this implementation:
viewtopic.php?p=9576#p9576

haf wrote:
How about I send a PR to integration-test on Travis CI, if you point me to the github repository I can do it for?
Which GitHub repository?
PDFsharp can be found here: https://github.com/empira/PDFsharp

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
 Post subject: Re: Hello World freezing
PostPosted: Thu Aug 11, 2016 8:48 pm 
Offline

Joined: Tue Aug 09, 2016 7:34 am
Posts: 6
It would seem this is the culprit:

Quote:
System.DllNotFoundException: user32.dll
at (wrapper managed-to-native) PdfSharp.Internal.NativeMethods:GetDC (intptr)
at PdfSharp.Drawing.XFontSource.ReadFontBytesFromGdi (System.Drawing.Font gdiFont) <0x7d2e210 + 0x00037> in <filename unknown>:0
at PdfSharp.Drawing.XFontSource.GetOrCreateFromGdi (System.String typefaceKey, System.Drawing.Font gdiFont) <0x7d2e1d0 + 0x00013> in <filename unknown>:0
at PdfSharp.Fonts.PlatformFontResolver.CreateFontSource (System.String familyName, PdfSharp.Fonts.FontResolvingOptions fontResolvingOptions, System.Drawing.Font& font, System.String typefaceKey) <0x6ac3310 + 0x0011b> in <filename unknown>:0
at PdfSharp.Fonts.PlatformFontResolver.ResolveTypeface (System.String familyName, PdfSharp.Fonts.FontResolvingOptions fontResolvingOptions, System.String typefaceKey) <0x6ac3038 + 0x0009b> in <filename unknown>:0
at PdfSharp.Fonts.FontFactory.ResolveTypeface (System.String familyName, PdfSharp.Fonts.FontResolvingOptions fontResolvingOptions, System.String typefaceKey) <0x6ac2c00 + 0x0039f> in <filename unknown>:0
at PdfSharp.Drawing.XGlyphTypeface.GetOrCreateFrom (System.String familyName, PdfSharp.Fonts.FontResolvingOptions fontResolvingOptions) <0x6ac24a0 + 0x0005f> in <filename unknown>:0
at PdfSharp.Drawing.XFont.Initialize () <0x6ac2330 + 0x00113> in <filename unknown>:0
at PdfSharp.Drawing.XFont..ctor (System.String familyName, Double emSize, XFontStyle style, PdfSharp.Drawing.XPdfFontOptions pdfOptions) <0x6ac22b0 + 0x00067> in <filename unknown>:0
at PdfSharp.Drawing.XFont..ctor (System.String familyName, Double emSize, XFontStyle style) <0x6ac2048 + 0x00057> in <filename unknown>:0
at FSI_0001+Generation.generate () <0x72d24b0 + 0x000af> in <filename unknown>:0
at <StartupCode$FSI_0001>.$FSI_0001.main@ () <0x6abe540 + 0x00013> in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x1a7ea40 + 0x000a1> in <filename unknown>:0


Top
 Profile  
Reply with quote  
 Post subject: Re: Hello World freezing
PostPosted: Fri Aug 12, 2016 6:08 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 339
So the problem is with "ReadFontBytesFromGdi" - it seems the functions called by this method are not supported on your system.
Try IFontResolver or EZFontResolver and this method should no longer be called.

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


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: Google [Bot] and 154 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