Export to PDF Lineweight

1 2    next >
Bogdan Eremia
2/15/2019 2:59 PM

Hello,

I have 2 text objects in a dwg that I print as pdf. They have different layers and one of the layer differences is the Lineweight on the. When printing they are printed with the same thickness (it should be different).
Please see attached dwg and the sample code an let me know if there's something I'm missing:
Btw I'm using version 4.0.38.143 of cadlib

C# Code:
           DxfModel model = DwgReader.Read(@"C:\Test.dwg");
           var paperSize = PaperSizes.GetPaperSize(PaperKind.A4Rotated);
           var layout = model.Layouts["ESPrintPareLayout"];

            BoundsCalculator boundsCalculator = new BoundsCalculator();
            boundsCalculator.GetBounds(model, layout);
            Bounds3D bounds = boundsCalculator.Bounds;
            float pageWidth = (float)paperSize.Width / 100f;
            float pageHeight = (float)paperSize.Height / 100f;
            float margin = 0.0f;

            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);

            using (Stream stream = File.Create(@"C:\1.PDF")))
            {
                GraphicsConfig grfCnfg = GraphicsConfig.AcadLikeWithWhiteBackground.Clone() as GraphicsConfig;
                grfCnfg.DefaultLineWeight = 1;
                grfCnfg.ApplyLineType = true;                
                grfCnfg.TryDrawingTextAsText = true;
                grfCnfg.DrawImages = true;
                grfCnfg.DisplayLineTypeElementShapes = true;
                grfCnfg.Plot = true;
                

                PdfExporter pdfGraphics = new PdfExporter(stream);
                pdfGraphics.ExportLayers = true;
                pdfGraphics.EmbedFonts = true;


                pdfGraphics.DrawPage(
                    model,
                    grfCnfg,
                    to2DTransform,
                    scaling,
                    layout,
                    layout.Viewports,
                    paperSize);
                pdfGraphics.EndDocument();
            }
            model.Dispose();

Wout
2/18/2019 2:15 PM

Hi Bogdan,

As this is not a CadLib bug I'll have to request you to order a support ticket here to look into this: https://www.woutware.com/support.

Thank you for understanding.

- Wout

Bogdan Eremia
2/18/2019 2:24 PM

Hello,
Just to get this right, are you saying the API is capable of doing what I described but I'm not using it correctly?

Wout
2/18/2019 2:29 PM

All I can say right now that nothing is wrong.

- Wout

Wout
2/19/2019 9:46 AM

Thank you for ordering the support ticket. I debugged the issue yesterday, and the drawing has setting LWDISPLAY (see property DxfHeader.DisplayLineWeight) set to off, which means that lineweights in model space are not displayed.

When I set LWDISPLAY to on, the exported PDF displays the different lineweights, although they are quite close so you have to look closely.

- Wout

Bogdan Eremia
2/19/2019 10:19 AM

Hello,

I had tried that before and it did not work. I tried it again (and also set the property from code on the mode header) - it does not work correctly.
Please see updated dwg (I added a new text with a bigger thickness - so it's easier to see; I also enabled the line weight display). I also updated the resulting pdfs (from ACAD and CAD lib). I also added 2 lines 1 on each of the used layers - they seem to print out ok.
Also I updated the code to enable DisplayLineWeight on the Graphics config (please see code below). All of this does not help.

C# Code:
        DxfModel model = DwgReader.Read(exldDwg);                           
            PaperSize paperSize = PaperSizes.GetPaperSize(PaperKind.A4Rotated);

            model.Header.DisplayLineWeight = true;            
            var layout = model.Layouts["ESPrintPareLayout"];            

            BoundsCalculator boundsCalculator = new BoundsCalculator();
            boundsCalculator.GetBounds(model, layout);
            Bounds3D bounds = boundsCalculator.Bounds;            
            float pageWidth = (float)paperSize.Width / 100f;
            float pageHeight = (float)paperSize.Height / 100f;
            float margin = 0.1f;

            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);

            using (Stream stream = File.Create(Path.Combine(folder, "1.PDF")))
            {
                GraphicsConfig grfCnfg = GraphicsConfig.WhiteBackgroundCorrectForBackColor.Clone() as GraphicsConfig;
                grfCnfg.DefaultLineWeight = 1;
                grfCnfg.ApplyLineType = true;
                grfCnfg.TryDrawingTextAsText = true;
                grfCnfg.DrawImages = true;
                grfCnfg.DisplayLineTypeElementShapes = true;
                grfCnfg.DisplayLineWeight = true;
                grfCnfg.Plot = true;                

                PdfExporter pdfGraphics = new PdfExporter(stream);
                pdfGraphics.ExportLayers = true;                
                pdfGraphics.EmbedFonts = true;                




                pdfGraphics.DrawPage(
                    model,
                    grfCnfg,
                    to2DTransform,
                    scaling,
                    layout,
                    layout.Viewports,
                    paperSize);
                pdfGraphics.EndDocument();
            }

            DwgWriter.Write(Path.Combine(folder, "1_LAY.DWG"), model);
            model.Dispose();

Wout
2/19/2019 10:28 AM

Hi,

I'm afraid you're making incorrect statements.

Firstly: the original Test.dwg you attached had LWDISPLAY off, which caused the text with SHX font to have the same line width. So my analysis of your original post is 100% correct.

Secondly: the PDF created by CadLib that you now attached has true type text, which means they are filled shapes, and not lines. As such line weight does not affect it. If you want the line weight to be correct for SHX fonts, you will have to make sure that CadLib can find the associated SHX fonts, otherwise it will substitute a true type font instead. You can call method DxfModel.AddShxLookupDirectories() to specify these directories.

As I already stated above, I have tested and produced correct PDF's when I turned LWDISPLAY on.

- Wout

Bogdan Eremia
2/19/2019 10:36 AM

Hi,
I just said I had tried with the setting on , not that the DWG I sent you had it on. It did not.

If you look in the DWGs I sent you'll see the texts use the same font (both in the original and one I just updated)I did not change the used font - the font is ISOCP2 from isocp2.shx - is it not a SHX font? (I know about the true font issue - that is why I used this font)

Is what I just said not correct? Am I missing something?

Bogdan Eremia
2/19/2019 10:44 AM

The problem is the lookup for SHX - it does not find the font and I believe it default to a true font.
I just added the directory with all the SHX fonts. It's Ok now.

Wout
2/19/2019 10:46 AM

You're saying "All of this does not help.", while your initial problem was obviously the LWDISPLAY setting, how is providing you this information not helpful???

Your second problem is your application not using the SHX font, but a true type font because CadLib cannot find the SHX font as I've stated. Again, this is 100% the problem you are having, and I am providing you this information. How is it not helpful?

I have analyzed your problem correctly in both cases, and I find your lack of appreciation disrespectful to be honest.

- Wout

1 2    next >