Search code examples
c#pdfpdf-generationabcpdf

ABCpdf AddImageHtml text stretches without administrator rights


Problem:
When I run the same program admin vs. non-admin they produce different results.

Example:

PDF problem

As you can see without administrator rights the text gets stretched vertically.

Code to reproduce:

var html = File.ReadAllText( "htmldata.txt" );
using( var doc = new Doc() )
{
    doc.HtmlOptions.Engine = EngineType.Chrome;
    doc.Page = doc.AddPage();
    doc.AddImageHtml( html );
    doc.Save( "testPDF.pdf" );
    Console.WriteLine( $"DPI: {doc.Rendering.DotsPerInch}" );
    Console.WriteLine( $"LOG: {doc.Rendering.Log}" );
    Console.WriteLine( $"OPTIONS: {string.Join(Environment.NewLine, doc.Options)}" );
    float dpiX, dpiY;
    using( Graphics graphics = Graphics.FromHwnd( IntPtr.Zero ) )
    {
        dpiX = graphics.DpiX;
        dpiY = graphics.DpiY;
    }
    Console.WriteLine( $"Transform: {doc.Transform.String}" );
    Console.WriteLine($"DPI X:{dpiX}{Environment.NewLine}DPI Y:{dpiY}");
}
Process.Start( "testPDF.pdf" );
Console.ReadKey();

The contents of htmldata.txt is:

<body style='font-family:"Source Sans Pro"'>
    some text on the page
</body>

Note
I have done this without the style and it gives the same issue


What I've already tried:

  1. Spotting differences in events (between Admin vs. Non-Admin) using: Process monitor, I could not spot an obvious difference besides paths.

  2. Checking if the correct DLL is being used using: listDLLs, the correct DLL's are being used.

  3. Checking the access to the %temp% directory as the docs indicate that AddImageHtml uses it to store HTML renders

  4. As can be seen in the code I've tried comparing DPI and certain settings but they are all the same.

Note
The reason I'm using AddImageHtml instead of AddTextStyled is because it supports more HTML (tables and such), so I can't use a different method (if it doesn't support most HTML). The users that use this can't get administrator rights either, this would compromise the system.


Solution

  • I know that this is an old question but I've had a similar stretching issue using AbcPdf11 with Chrome Engine on some Windows 2012 R2 systems (under VMWARE) and I've fixed it by disabling Javascript:

    doc.HtmlOptions.UseScript = false;

    I think that with JS enabled it tries to calculate automatically the BrowserWidth based on some system settings.