Section.PdfExport - Font scaling

Posted by: p.feenstra on 21 May 2024, 8:22 am EST

    • Post Options:
    • Link

    Posted 21 May 2024, 8:22 am EST

    Using ActiveReports 15.3

    A large part of our sectionReport consists of an EMF file.

    This image is drawn on the SectionReport by the page DrawImage function.

    The image is always scaled down to 100% due to possible use of high-resolution monitors.

    Everything is correctly sized in the print preview.

    But after exporting to PDF on a high-resolution monitor (i.e. 200%), the fonts (image part) are very small and unreadable.

    When exporting to PDF on a monitor at 100% scale, all fonts appear to be the correct size.

    Any idea what’s going wrong here and how to solve this?

    Thanks in advance.

    Regards Piet

  • Posted 22 May 2024, 3:56 am EST

    Hi Piet,

    Please refer to the attached sample that we tested. We couldn’t observe any font-related issues using both 100% and 200% scaling of a 1920 x 1080 display resolution.

    If the issue persists at your end, you may edit the attached sample so that it reproduces the issue and provide us with the steps to replicate the issue or a screenshare video where the issue can be seen being reproduced.

    Attachment:EMFImageSample.zip

  • Posted 22 May 2024, 5:26 am EST

    Hi Katyayny,

    Thanks for your quick response.

    Your project does not run on my system, sorry. (missing files).

    But it looks like you’re using a company logo that doesn’t have real fonts.

    First you should create an EMF image (by code) and draw some text on it.

    Then draw this image on the report and after that export it to a PDF.

    Regards Piet

  • Posted 23 May 2024, 4:59 am EST

    Hi Piet,

    >> Your project does not run on my system, sorry. (missing files).

    We apologize for the same. Could you let us know which files are missing at your end that are causing errors so that we could guide you with the same? If the issue is related to ActiveReports packages, you can use the ActiveReports File Converter tool to remove any inconsistency between dependencies.

    >> First you should create an EMF image (by code) and draw some text on it.

    Then draw this image on the report and after that export it to a PDF.

    We followed your steps and created an EMF image via code. After that, drew that saved emf image into the report and exported the report to PDF. Still, we could not observe any font scaling issues using both 100% and 200% scaling on a 1920 x 1080 display resolution.

    Unzip the attached sample, open it in Visual Studio 2015, 2017, 2019, or 2022 and press F5 to run it. It should run the sample and open the exported PDF that we tested with. If issue persists, please provide us with the steps to replicate the issue or a screenshare video where the issue can be seen being reproduced.

    Attachment: EMFImageSample_Updated.zip

  • Posted 23 May 2024, 10:14 am EST

    Hi Katyayny,

    Your project still does not run on my system (missing - nuget.org/v3/index.json).

    Here are some code snippets I use.

    The attachments contains 2 pdf files which shows the issue. There is also an image from a print preview included.

    // create metafile C#

    Graphics g = CreateGraphics();

    IntPtr hdc = g.GetHdc();

    MemoryStream ms = new MemoryStream();

    Metafile mf = new Metafile(ms, hdc, EmfType.EmfPlusOnly);

    g.ReleaseHdc(hdc);

    g = Graphics.FromImage(mf);

    g.CompositingMode = CompositingMode.SourceOver;

    g.SmoothingMode = SmoothingMode.HighQuality;

    g.InterpolationMode = InterpolationMode.HighQualityBicubic;

    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

    Font fnt = new Font(“Microsoft Sans Serif”, 9f, FontStyle.Regular);

    using (SolidBrush sb = new SolidBrush(ForeColor))

    {

    StringFormat stringFormat = new StringFormat()

    {

    Alignment = StringAlignment.Center,

    LineAlignment = StringAlignment.Center

    };

    g.DrawString(“Please add a some text”, fnt, sb, new Rectangle(0, 0, 100, 100), stringFormat);

    stringFormat.Dispose();

    }

    g.Dispose();

    ms.Close();

    ms.Flush();

    ms.Dispose();

    // create report (VB)

    Dim rpt As New SectionReport

    rpt.Document.Printer.PrinterName = e.DefaultPageSettings.PrinterSettings.PrinterName

    rpt.Document.Printer.PrinterSettings = e.DefaultPageSettings.PrinterSettings

    rpt.Document.Printer.DefaultPageSettings = e.DefaultPageSettings

    rpt.PageSettings.Margins.Left = 0

    rpt.PageSettings.Margins.Right = 0

    rpt.PageSettings.Margins.Top = 0

    rpt.PageSettings.Margins.Bottom = 0

    Dim tmpPage As New Page()

    Dim destRect As RectangleF

    With destRect

    .X = MmToInch(info.MmMargins.Left)

    .Y = MmToInch(info.MmMargins.Top)

    .Width = tmpPage.Width - MmToInch(info.MmMargins.Left + info.MmMargins.Right)

    .Height = img.Height * .Width / img.Width

    End With

    tmpPage.DrawImage(img, destRect.X, destRect.Y, destRect.Width, destRect.Height)

    rpt.Document.Pages.Add(tmpPage)

    ‘’ create preview

    arvMain.Document = rpt.Document

    ‘’ create pdf

    Dim pe As New Export.Pdf.Section.PdfExport

    pe.Version = Export.Pdf.Section.PdfVersion.Pdf17

    pe.ImageQuality = Export.Pdf.Section.ImageQuality.Highest

    pe.NeverEmbedFonts = “” '“Times New Roman;Verdana”

    pe.FontFallback = “Microsoft Sans Serif”

    pe.Export(_rpt.Document, newname)

    issues.zip

  • Posted 24 May 2024, 9:02 am EST

    Hi Piet,

    It appears that you are drawing directly onto a metafile using the Graphics object obtained from the form. While this approach may work in some cases, it can lead to inconsistent output due to variations in system scaling settings. Please refer to the CustomerCode_PDFs generated using your code in different scale resolutions.

    As a workaround, instead of drawing directly onto the metafile, consider creating a bitmap first and then converting it to a metafile before adding it to the report. This approach will allow for better control over the drawing quality and resolution will be independent of system scaling settings. Please refer to the UpdatedCode_PDFs using the suggested workaround in different Scale resolutions.

    Please refer to the attached sample link where we’ve added the dlls to the project instead of adding NuGet Package references. Let us know if you still face any issues in running it. In case you still face issues building the sample, you may also refer to the following code that we used:

    Using bitmap As New Bitmap(600, 300)
        Using graphics As Graphics = Graphics.FromImage(bitmap)
            graphics.SmoothingMode = SmoothingMode.AntiAlias
            graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit
            Dim text As String = "Please add some text"
            Using font As New Font("Microsoft Sans Serif", 9.0F, FontStyle.Regular)
                Using brush As New SolidBrush(Color.Black)
                    graphics.DrawString(text, font, brush, New PointF(0, 0))
                End Using
            End Using
        End Using
        Using ms As New MemoryStream()
            Using g As Graphics = Graphics.FromImage(bitmap)
                Dim hdc As IntPtr = g.GetHdc()
                Dim mf As New Metafile(ms, hdc, EmfType.EmfPlusOnly)
                g.ReleaseHdc(hdc)
                Using metafileGraphics As Graphics = Graphics.FromImage(mf)
                    metafileGraphics.DrawImage(bitmap, New Rectangle(0, 0, bitmap.Width, bitmap.Height))
                End Using
                Dim rpt As New SectionReport1()
                Dim tmpPage As New Page()
                Dim destRect As New RectangleF()
                destRect.X = 0
                destRect.Y = 0
                destRect.Width = rpt.PageSettings.PaperWidth
                destRect.Height = rpt.PageSettings.PaperHeight
                tmpPage.DrawImage(mf, destRect.X, destRect.Y, destRect.Width, destRect.Height)
                rpt.Document.Pages.Add(tmpPage)
                Viewer1.Document = rpt.Document
                Dim pe As New PdfExport()
                pe.Version = GrapeCity.ActiveReports.Export.Pdf.Section.PdfVersion.Pdf17
                pe.ImageQuality = GrapeCity.ActiveReports.Export.Pdf.Section.ImageQuality.Highest
                pe.NeverEmbedFonts = ""
                pe.FontFallback = "Microsoft Sans Serif"
                pe.Export(rpt.Document, Application.StartupPath & "\MyPDF15_200.pdf")
                Process.Start(Application.StartupPath & "\MyPDF15_200.pdf")
                mf.Dispose()
            End Using
        End Using
    End Using
    

    If the issue persists, please provide us with the following information so that we may also try replicating the issue at our end with your system settings:

    • Operating System version
    • .NET Framework version
    • Visual Studio Version
    • Display Resolution
    • Monitor Display Information
    • Laptop Model (if using it)

    Attachments:

    https://we.tl/t-eOfV98CJnG

    UpdatedCode_PDFs.zip

    CustomerCode_PDFs.zip

  • Posted 27 May 2024, 3:46 am EST

    Hi Katyayny,

    If I read it correctly you are trying to create a bitmap drawing here to get rid of the emf.

    But the emf is needed to create vector info instead of bitmap info (due to the large paper sizes)

    What could be a workaround is printing to a pdf-printer, for example, “pdf995” or “Bluebeam Revu”.

    This way the font sizes remain correct.

    The problem here is that we have to compromise a bit on quality. (but it’s still much better than using a bitmap)

    So in the end we still prefer AR but…

    Regards Piet

  • Posted 29 May 2024, 3:41 am EST

    Hi Piet,

    We understand your concern and have escalated the same to our development team to get their insights into the same [AR-33546]. We’ll get back to you as soon as we receive any updates from their end.

    Thanks for your patience!

  • Posted 30 May 2024, 12:27 am EST

    Hi Piet,

    Thanks for your patience!

    Currently, we don’t have our own complete EMF parser and cannot use the standard one from .NET because of the problems with high DPI, so we introduced the support of SVG. As per our development team, it is suggested that you consider using SVG images instead. SVG images can be used in both GDI and cross-platform compatibility modes in ActiveReports 18.

    Though we are planning to add a feature to support EMF images in exported PDFs in the future, we currently have no ETA available for the same.

  • Posted 30 May 2024, 2:49 am EST

    Hi Katyayny,

    Although SVG is a very good idea, I would take a closer look at EMF. It already works perfectly now. Only at high DPI and scaled back to 100% there are some problems with the font sizes. And that only when exporting to PDF.

    Imho, your team should be able to solve that effortlessly.

    Regards Piet

  • Posted 31 May 2024, 1:38 am EST

    Hi Piet,

    As mentioned in our previous comment, our development team is planning to add a feature to support EMF images in exported PDFs in the future, but we currently do not have any ETA available for the same.

    We will let you know as soon as we get any updates regarding the same. We appreciate your patience in the meantime.

Need extra support?

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

Learn More

Forum Channels