GrapeCity.Documents.Pdf -> Add elements throw exceptions

Posted by: gerd.greiner on 4 May 2018, 7:40 am EST

  • Posted 4 May 2018, 7:40 am EST

    Hi Guys,

    I'm using the brand new GrapeCity.Documents.Pdf (V. 1.0.0.105) nuget package in my
    .Net Standard 2.0 project.
    I have problems with adding elements to the document (see code below g.DrawString(..)).
    I always get following exception:
    "An unhandled exception of type 'System.AccessViolationException' occurred in Grapecity.Documents.Common.dll. Attempted to read or write protected memory. This is often indication that other memory is corrupt."

    I have also downloaded the Visual Studio sample project but there the same exception occurs.
    (http://demos.componentone.com/DocumentServices/GcPdfWeb/Samples/List#QuickStart/undefined).

    Example Code: The exception occurs at g.DrawString

    // Create a new PDF document:
    GcPdfDocument doc = new GcPdfDocument();
    // Add a page, get its graphics:
    GcPdfGraphics g = doc.NewPage().Graphics;
    // Render a string into the page:
    g.DrawString("Hello, World!",
    // Use a standard font (the 14 standard PDF fonts are built into GcPdf
    // and are always available):
    new TextFormat() { Font = StandardFonts.Times, FontSize = 12 },
    // GcPdf page coordinates start at top left corner, using 72 dpi by default:
    new PointF(72, 72));
    // Save the PDF:
    doc.Save(stream);


    Kind regards,
    Gerd
  • Replied 7 May 2018, 3:18 am EST

    Hello Gerd,

    Thank you for choosing GrapeCity Documents for PDF.
    We tried the same code snippet but could not replicate the error at our end.
    Please try using the latest packages from nuget.org (https://www.nuget.org/packages/GrapeCity.Documents.Pdf/) with the attached sample and inform if the issue persists.
    If you still observe the issue, please share the modified sample for us to assist you further.

    Thanks,
    Esha
    prj_DemoPdf.zip
  • Replied 7 May 2018, 8:03 am EST

    Hi,

    I can confirm the problem described above. I tried the attached zip without modification and got the System.AccessViolationException error. I also tried changing the version of the package to 1.0.0.105 after the first try failed with the same result.

    I'm using Windows 10 and also tried to execute the program in Admin Mode. If you need further system information or anything please ask.

    Thanks and best regards
  • Replied 7 May 2018, 11:37 am EST

    Guys, could you please build and run this small utility:

    https://github.com/grapecity/GcPdf/tree/master/Util/EnumFonts

    and let us know what happens. On initialization GcPdf tries to build the system font collection, and currently the only idea we have is that maybe there is some font in your systems that breaks our font parser. This utility will list system fonts using the same logic as GcPdf, and if it breaks on some font(s) we should be able to find the problem.

    Thanks.
  • Replied 8 May 2018, 3:50 am EST

    Hi,

    I had run the 'EnumFonts' test application. The program breaks at a specific font.

    It breaks at 'Parsing C:\Windows\Fonts\arimon__.ttf'. The Exception is "An unhandled exception of type 'System.AccessViolationException' occurred in GrapeCity.Documents.Common.dll'
    Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

    The Error occurs at method 'QuickParseFontFile' Font.From(path, true). The exception is not handled in the catch block. Afterwards the program stops.

    Kind regards,
    Gerd

    Listing:
    Enumerating System Fonts (quick check)
    parsing C:\WINDOWS\Fonts\3OF9_NEW.TTF (done)
    parsing C:\WINDOWS\Fonts\AGENCYB.TTF (done)
    parsing C:\WINDOWS\Fonts\AGENCYR.TTF (done)
    parsing C:\WINDOWS\Fonts\ahronbd.ttf (done)
    parsing C:\WINDOWS\Fonts\ALGER.TTF (done)
    parsing C:\WINDOWS\Fonts\andlso.ttf (done)
    parsing C:\WINDOWS\Fonts\angsa.ttf (done)
    parsing C:\WINDOWS\Fonts\angsab.ttf (done)
    parsing C:\WINDOWS\Fonts\angsai.ttf (done)
    parsing C:\WINDOWS\Fonts\angsau.ttf (done)
    parsing C:\WINDOWS\Fonts\angsaub.ttf (done)
    parsing C:\WINDOWS\Fonts\angsaui.ttf (done)
    parsing C:\WINDOWS\Fonts\angsauz.ttf (done)
    parsing C:\WINDOWS\Fonts\angsaz.ttf (done)
    parsing C:\WINDOWS\Fonts\ANTQUAB.TTF (done)
    parsing C:\WINDOWS\Fonts\ANTQUABI.TTF (done)
    parsing C:\WINDOWS\Fonts\ANTQUAI.TTF (done)
    parsing C:\WINDOWS\Fonts\aparaj.ttf (done)
    parsing C:\WINDOWS\Fonts\aparajb.ttf (done)
    parsing C:\WINDOWS\Fonts\aparajbi.ttf (done)
    parsing C:\WINDOWS\Fonts\aparaji.ttf (done)
    parsing C:\WINDOWS\Fonts\arabtype.ttf (done)
    parsing C:\WINDOWS\Fonts\arial.ttf (done)
    parsing C:\WINDOWS\Fonts\arialbd.ttf (done)
    parsing C:\WINDOWS\Fonts\arialbi.ttf (done)
    parsing C:\WINDOWS\Fonts\ariali.ttf (done)
    parsing C:\WINDOWS\Fonts\ARIALN.TTF (done)
    parsing C:\WINDOWS\Fonts\ARIALNB.TTF (done)
    parsing C:\WINDOWS\Fonts\ARIALNBI.TTF (done)
    parsing C:\WINDOWS\Fonts\ARIALNI.TTF (done)
    parsing C:\WINDOWS\Fonts\ARIALUNI.TTF (done)
    parsing C:\WINDOWS\Fonts\ariblk.ttf (done)
    parsing C:\WINDOWS\Fonts\arimonbd.ttf (done)
    parsing C:\WINDOWS\Fonts\arimon__.ttf
  • Replied 8 May 2018, 8:00 am EST

    Hi Gerd,

    Many thanks for your reply/info. Could you please do the following: send me the arimon__.ttf that you have (we tried it with a arimon__.ttf that we found, but it doesn't crash, so possibly you have a different version), and remove the font from the system (copy the physical file somewhere first of course so that you can reinstall it afterwards) and see if that helps?

    My email is dmitry.yaitskov@grapecity.com

    Your help with this issue is very much appreciated!

    Cheers,
    Dmitry.
  • Replied 9 May 2018, 1:51 pm EST

    Update: we found a version of arimon__.ttf which triggered this error. In that particular file, the post table contained invalid data, which caused the crash. We changed our code to deal with such situations, as soon as the update is available on NuGet I'll post a note here. The temporary workaround for anybody experiencing this problem is to run the EnumFonts test app, and uninstall the font at which it stops (so far I'm not aware of any other fonts besides certain arimon__.ttf's that cause this).

    Cheers,
    Dmitry.
  • Replied 15 May 2018, 6:25 am EST

    Hi,

    I can confirm that it works once I remove the arimon_.ttf font so thanks for providing this workaround.
    Another question:
    How does the licensing work? We have a ComponentOne Ultimate subscription so I'm thinking this includes the Documents library. I found the statement in the documentation that I can pass the key in the constructor like this:
    var doc = new GcPdfDocument(key)

    So I tried creating an App key for an ASP .NET Core app and set it as the key but I got an invalid license key error for that. So how do I get a valid license key?

    Thanks and best regards
  • Marked as Answer

    Replied 15 May 2018, 12:52 pm EST

    Hi,

    The access violation has been fixed in the new build which is now available on NuGet:

    https://www.nuget.org/packages/GrapeCity.Documents.Pdf/1.0.0.107

    As for licensing: you're right that in order to have a licensed GcPdf, you need to use the ctor that accepts a license key. Alternatively, you can call the static method GcPdfDocument.SetLicenseKey(key) and all instances of GcPdfDocument will be licensed while the program runs. But, AFAIK, Documents for PDF is not included in the current subscriptions. Please contact our sales mailto:us.sales@grapecity.com for details.

    Cheers,
    Dmitry.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels