cart: empty [ Login ]

Positioning of text in PDF is slightly off

1 
Emilsson
1/15/2019 3:12 PM
Hi 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 4.0.38.70 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(); boundsCalculator.GetBounds(model); 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( bounds.Corner1, bounds.Corner2, 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); pdfExporter.EndDocument(); } } } }
Sample 1 - Autocad.png
Sample 1 - Cadlib.png
Sample 2 - Autocad.png
Sample 2 - Cadlib.png
Wout
1/16/2019 11:29 AM
Hi, 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
cadlib4.0.38.136.png
Wout
1/16/2019 11:30 AM
Hang on, I didn't test the PDF yet. - Wout
Wout
1/16/2019 11:33 AM
PDF looks OK too I think, see attachment. - Wout
Emilsson
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 4.0.38.70 in the test. We've now upgraded to 4.0.38.136, 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?
Comparison.png
Wout
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
Emilsson
1/24/2019 3:56 PM
Thank you Wout, that looks much better!
1