cart: empty [ Login ]

PDF clipped when exporting dwg

1 
Gabrielecocco1510
9/5/2018 6:32 PM
Hi, I'm using the latest version of CadLib (4.0.38.94) and I'm facing an issue when generating the PDF from an elevator blueprint that I draw within my software. The DWG is correctly produced and written to file. To the contrary, the PDF results clipped. I attach the DWG and the clipped PDF. The code I'm using to generate the PDF is the following.
C# Code:
public class PdfProjectExporter { public void ExportToFile(string path, string title, DxfModel model) { if (File.Exists(path)) File.Delete(path); FileStream s = File.Exists(path) ? new FileStream(path, FileMode.Truncate) : new FileStream(path, FileMode.CreateNew); WW.Cad.IO.PdfExporter exporter = new WW.Cad.IO.PdfExporter(s); exporter.Title = title; // Consider paperspace DxfLayout dxf = null; IEnumerable<DxfLayout> layouts = model.Layouts.Where(f => f.PaperSpace & f.Entities.Count > 0); // Take first layout in paperspace if (layouts.Count() > 0) { dxf = layouts.First(); } // Prendo le dimensioni del modello BoundsCalculator boundscalc = new BoundsCalculator(); if (dxf != null) boundscalc.GetBounds(dxf.Model, dxf); else boundscalc.GetBounds(model); // If I have no paperspace layout pick the model if (dxf == null) dxf = model.Layouts.Where(f => f.Name == "Model").First(); Bounds3D bounds = boundscalc.Bounds; // Size/ratio of pdf = size/ration of model PaperSize ps = new PaperSize(title, (int)Math.Round(bounds.Delta.X), (int)Math.Round(bounds.Delta.Y)); //PaperSizes.GetPaperSize(PaperKind.A4Rotated); float margin = 0;// 50f; float pageWidth = ps.Width / 100f; float pageHeight = ps.Height / 100f; // Scale and transform such that its fits max width/height // and the top middle of the cad drawing will match the // top middle of the pdf page. // The transform transforms to pdf pixels. double scaling; Matrix4D to2DTransform = DxfUtil.GetScaleTransform( bounds.Corner1, bounds.Corner2, new Point3D(bounds.Center.X, bounds.Center.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 / 2d, 0d) * PdfExporter.InchToPixel), out scaling); var config = GraphicsConfig.WhiteBackground.Clone() as GraphicsConfig; config.FixedForegroundColor = System.Drawing.Color.Black; exporter.DrawPage(model, config, to2DTransform, scaling, null, null, ps); s.Flush(); exporter.EndDocument(); } }
Hope that you can help me to sort out the issue. Thank you very much!
Gabrielecocco1510
9/5/2018 6:34 PM
Adding the zipped DWG cause the plain DWG is too big (4.4 mb) and the forum reports an error when trying to upload it.
Gabrielecocco1510
9/13/2018 9:13 AM
Nobody able to help me out?
Wout
9/13/2018 12:36 PM
The pdf is not clipped, it's fine. Firefox displays it ok. Microsoft Edge doesn't show it entirely due to the large size. Your using a very large size in inches: 247 inch, that's gigantic. I suspect Pdf viewers cannot handle this. Pdf is intended to represent paper sizes, so I recommend just sticking with normal paper sizes like A4, A3, etc. I would not use model space bounds as a paper size, as model space does not represent paper space. - Wout
Gabrielecocco1510
9/19/2018 5:51 PM
I'm using acrobat reader, so among all the viewers, it should look ok there. Anyway I see what you mean about sizes. Can you help me reshaping the code above in order to resize and fit on a A4 paper? Thanks!
Wout
9/19/2018 5:56 PM
Well apparently Acrobat does not support 247 inch paper sizes, I don't think it should. The original code was already correct, just use the bit that you commented out:
C# Code:
//PaperSizes.GetPaperSize(PaperKind.A4Rotated);
Choose A4 or A4Rotated based on if your width > height or not. - Wout
1