public bool WriteExportFile(string filePath, string fileExt) { try { // instantiate filter PicFilter filter = (_showCotationAuto ? PicFilter.FilterNone : !PicFilter.FilterCotation) & PicFilter.FilterNoZeroEntities; // get bounding box PicVisitorBoundingBox visitorBoundingBox = new PicVisitorBoundingBox(); Factory.ProcessVisitor(visitorBoundingBox, filter); Box2D box = visitorBoundingBox.Box; // add margins : 5 % of the smallest value among height box.AddMarginHorizontal(box.Width * 0.01); box.AddMarginVertical(box.Height * 0.01); string fileFormat = fileExt.TrimStart('.').ToLower(); byte[] byteArray; // get file content if (string.Equals("des", fileFormat)) { // DES using (PicVisitorDesOutput visitor = new PicVisitorDesOutput()) { visitor.Author = "treeDiM"; Factory.ProcessVisitor(visitor, filter); byteArray = visitor.GetResultByteArray(); } } else if (string.Equals("dxf", fileFormat)) { // DXF using (PicVisitorDxfOutput visitor = new PicVisitorDxfOutput()) { visitor.Author = "treeDiM"; Factory.ProcessVisitor(visitor, filter); byteArray = visitor.GetResultByteArray(); } } #if PDFSharp else if (string.Equals("pdf", fileFormat)) { // PDF using (PicGraphicsPdf graphics = new PicGraphicsPdf(box)) { graphics.Author = Application.ProductName + "(" + Application.CompanyName + ")"; graphics.Title = Path.GetFileNameWithoutExtension(filePath); Factory.Draw(graphics, filter); byteArray = graphics.GetResultByteArray(); } } #endif else if (string.Equals("ai", fileFormat) || string.Equals("cf2", fileFormat)) { // AI || CF2 using (PicVisitorDiecutOutput visitor = new PicVisitorDiecutOutput(fileExt)) { visitor.Author = Application.ProductName + "(" + Application.CompanyName + ")"; visitor.Title = Path.GetFileNameWithoutExtension(filePath); Factory.ProcessVisitor(visitor, filter); byteArray = visitor.GetResultByteArray(); } } else { throw new Exception("Invalid file format:" + fileFormat); } // write byte array to stream using (FileStream fstream = new FileStream(filePath, FileMode.Create)) fstream.Write(byteArray, 0, byteArray.GetLength(0)); return(true); } catch (Exception ex) { _log.Error(string.Format("Exception: {0}", ex.ToString())); return(false); } }
public byte[] GetExportFile(string fileExt, ParameterStack stack) { // build factory PicFactory factory = new PicFactory(); Component.CreateFactoryEntities(factory, stack); if (_reflectionX) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX)); } if (_reflectionY) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY)); } // remove existing quotations if (!_showCotationCode) { factory.Remove(PicFilter.FilterCotation); } // build auto quotations if (_showCotationAuto) { PicAutoQuotation.BuildQuotation(factory); } // instantiate filter PicFilter filter = !PicFilter.FilterCotation & !(new PicFilterLineType(PicGraphics.LT.LT_COTATION) | new PicFilterLineType(PicGraphics.LT.LT_AXIS)) & PicFilter.FilterNoZeroEntities; // get bounding box PicVisitorBoundingBox visitorBoundingBox = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitorBoundingBox, filter); Box2D box = visitorBoundingBox.Box; // add margins : 5 % of the smallest value among height box.AddMarginHorizontal(box.Width * 0.05); box.AddMarginVertical(box.Height * 0.05); string author = Application.ProductName + " (" + Application.CompanyName + ")"; string title = Application.ProductName + " export"; string fileFormat = fileExt.StartsWith(".") ? fileExt.Substring(1) : fileExt; fileFormat = fileFormat.ToLower(); // get file content if (string.Equals("des", fileFormat)) { PicVisitorDesOutput visitor = new PicVisitorDesOutput { Author = author }; factory.ProcessVisitor(visitor, filter); return(visitor.GetResultByteArray()); } else if (string.Equals("dxf", fileFormat)) { PicVisitorOutput visitor = new PicVisitorDxfOutput { Author = author }; factory.ProcessVisitor(visitor, filter); return(visitor.GetResultByteArray()); } #if PDFSharp else if (string.Equals("pdf", fileFormat)) { PicGraphicsPdf graphics = new PicGraphicsPdf(box) { Author = author, Title = title }; factory.Draw(graphics, filter); return(graphics.GetResultByteArray()); } #endif else if (string.Equals("ai", fileFormat) || string.Equals("cf2", fileFormat)) { PicVisitorDiecutOutput visitor = new PicVisitorDiecutOutput(fileFormat) { Author = author, Title = title }; factory.ProcessVisitor(visitor, filter); return(visitor.GetResultByteArray()); } else { throw new Exception("Invalid file format:" + fileFormat); } }