Positioning of text in PDF is slightly off

1/15/2019 3:12 PM


When I convert the attached DWG to PDF, the position of some of the text is slightly off. Not by much, mind you, but enough that some of our customers are complaining. To illustrate the problem areas I've included cropped screenshots from both the Cadlib-generated PDF and from Autocad 2018. I hope these will make it clear what I mean.

I've using Cadlib and the code below to generate the PDF.

Best regards
Tomas Emilsson

C# Code:
namespace CadlibTest
    using System;
    using System.Diagnostics;
    using System.Drawing.Printing;
    using System.IO;
    using WW.Cad.Base;
    using WW.Cad.Drawing;
    using WW.Cad.IO;
    using WW.Cad.Model;
    using WW.Math;
    using Color = System.Drawing.Color;

    class Program
        static void Main(string[] args)
            const float Margin = .1f;
            string dwgPath = @"C:\Temp\Test.dwg";
            string pdfPath = dwgPath + ".pdf";

            DxfModel.AddShxLookupDirectories(@"C:\Program Files\Autodesk\AutoCAD 2018\Fonts");

            DxfModel model = DwgReader.Read(dwgPath);

            using (FileStream outStream = new FileStream(pdfPath, FileMode.Create))
                PdfExporter pdfExporter = new PdfExporter(outStream);

                BoundsCalculator boundsCalculator = new BoundsCalculator();
                Bounds3D bounds = boundsCalculator.Bounds;
                PaperSize paperSize = PaperSizes.GetPaperSize(PaperKind.A4);

                // "Stretch" paper if necessary
                paperSize.Width = Math.Max(paperSize.Width, (int)(bounds.Delta.X / bounds.Delta.Y * paperSize.Height));

                // Length in inches (PaperSize.Width is in 100ths of an inch).
                float pageWidth = paperSize.Width / 100f;
                float pageHeight = paperSize.Height / 100f;

                // Scale and transform to fit PDF page
                double scaling;
                Matrix4D to2DTransform = DxfUtil.GetScaleTransform(
                    new Point3D(bounds.Center.X, bounds.Corner2.Y, 0d),
                    new Point3D(new Vector3D(Margin, Margin, 0d) * PdfExporter.InchToPixel),
                    new Point3D(new Vector3D(pageWidth - Margin, pageHeight - Margin, 0d) * PdfExporter.InchToPixel),
                    new Point3D(new Vector3D(pageWidth / 2d, pageHeight - Margin, 0d) * PdfExporter.InchToPixel),
                    out scaling);

                GraphicsConfig graphicsConfig = (GraphicsConfig) GraphicsConfig.AcadLikeWithBlackBackground.Clone();

                pdfExporter.DrawPage(model, graphicsConfig, to2DTransform, scaling, null, null, paperSize);

1/16/2019 11:29 AM


Can you try with the latest CadLib version? I can't reproduce the problem with the current version. See screenshot on my side. Which version were you using?

- Wout

1/16/2019 11:30 AM

Hang on, I didn't test the PDF yet.

- Wout

1/16/2019 11:33 AM

PDF looks OK too I think, see attachment.

- Wout

1/16/2019 3:49 PM

> PDF looks OK too I think, see attachment.

Which attachment do you mean? I can only see the screenshot attachment.

> Which version were you using?

As I said, we used in the test. We've now upgraded to, and it looks clearly better. The first sample looks perfect. The second one (the vertical text) is better, but the text still seems too close to the line below it, and the top zero is far from the text below it. I've included an image to show what I mean together with the pdf.

Also the diameter symbol looks very different in the Cadlib pdf, as if it doesn't use the same font?

1/18/2019 6:36 PM

The stacked text positioning and diameter symbol should be improved now. Please download the latest version from your resources in your profile.

Thank you for the report!

- Wout

1/24/2019 3:56 PM

Thank you Wout, that looks much better!