private void button1_Click(object sender, EventArgs e)
        {
            DrawingHandler MyDrawingHandler = new DrawingHandler();

            PrintAttributes printAttributes = new PrintAttributes();

            printAttributes.Scale = 1.0;
            printAttributes.PrintToMultipleSheet = false;
            printAttributes.NumberOfCopies       = 1;
            printAttributes.Orientation          = DotPrintOrientationType.Auto;
            printAttributes.PrintArea            = DotPrintAreaType.EntireDrawing;
            printAttributes.PrinterInstance      = "PDF_594x420";

            if (MyDrawingHandler.GetConnectionStatus())
            {
                DrawingEnumerator SelectedDrawings = MyDrawingHandler.GetDrawingSelector().GetSelected();
                while (SelectedDrawings.MoveNext())
                {
                    Drawing currentDrawing = SelectedDrawings.Current;

                    //Get print attributes: we need only PrinterInstance
                    MyDrawingHandler.PrintDrawing(currentDrawing, printAttributes);
                }
            }
        }
 public static dynamic GetTSObject(PrintAttributes dynObject)
 {
     if (dynObject is null)
     {
         return(null);
     }
     return(dynObject.teklaObject);
 }
Esempio n. 3
0
                public MyOnLayoutAsyncTask(MyPrintDocumentAdapter self, PrintAttributes newAttributes,
                                           CancellationSignal cancellationSignal, LayoutResultCallback callback)
                {
                    this.self               = self;
                    this.newAttributes      = newAttributes;
                    this.cancellationSignal = cancellationSignal;
                    this.callback           = callback;

                    items = ((MotoGpStatAdapter)self.pcc.ListAdapter).CloneItems();
                }
Esempio n. 4
0
 public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
 {
     if (cancellationSignal.IsCanceled)
     {
         callback.OnLayoutCancelled();
         return;
     }
     callback.OnLayoutFinished(new PrintDocumentInfo.Builder(path)
                               .SetContentType(PrintContentType.Document)
                               .Build(), true);
 }
        public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, Android.OS.CancellationSignal cancellationSignal, LayoutResultCallback callback, Android.OS.Bundle extras)
        {
            if (cancellationSignal.IsCanceled)
            {
                callback.OnLayoutCancelled();
                return;
            }

            using var builder = new PrintDocumentInfo.Builder(_fileName);
            callback.OnLayoutFinished(builder
                                      .SetContentType(PrintContentType.Document)
                                      .Build(), true);
        }
 public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
 {
     if (cancellationSignal.IsCanceled)
     {
         callback.OnLayoutCancelled();
     }
     else
     {
         PrintDocumentInfo.Builder builder = new PrintDocumentInfo.Builder(StatsActivity.filename);
         builder.SetContentType(PrintContentType.Document).SetPageCount(PrintDocumentInfo.PageCountUnknown).Build();
         callback.OnLayoutFinished(builder.Build(), !newAttributes.Equals(oldAttributes));
     }
 }
Esempio n. 7
0
            private int computePageCount(PrintAttributes printAttributes)
            {
                int itemsPerPage = 4;

                MediaSize pageSize = printAttributes.GetMediaSize();

                if (!pageSize.IsPortrait)
                {
                    itemsPerPage = 6;
                }
                int printItemCount = 6;

                return((int)Math.Ceiling((double)(printItemCount / itemsPerPage)));
            }
        void CalculateScale(PrintAttributes newAttributes)
        {
            int dpi = Math.Max(newAttributes.GetResolution().HorizontalDpi, newAttributes.GetResolution().VerticalDpi);

            int leftMargin   = (int)(dpi * (float)newAttributes.MinMargins.LeftMils / 1000);
            int rightMargin  = (int)(dpi * (float)newAttributes.MinMargins.RightMils / 1000);
            int topMargin    = (int)(dpi * (float)newAttributes.MinMargins.TopMils / 1000);
            int bottomMargin = (int)(dpi * (float)newAttributes.MinMargins.BottomMils / 1000);

            int w = (int)(dpi * (float)newAttributes.GetMediaSize().WidthMils / 1000) - leftMargin - rightMargin;
            int h = (int)(dpi * (float)newAttributes.GetMediaSize().HeightMils / 1000) - topMargin - bottomMargin;

            scale = Math.Min((float)document.PageContentRect.Width() / w, (float)document.PageContentRect.Height() / h);
        }
Esempio n. 9
0
 public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
 {
     if (cancellationSignal.IsCanceled)
     {
         callback?.OnLayoutCancelled();
     }
     else
     {
         var builder = new PrintDocumentInfo.Builder("filename.pdf");
         builder.SetContentType(PrintContentType.Document)
         .SetPageCount(PrintDocumentInfo.PageCountUnknown);
         callback.OnLayoutFinished(builder.Build(), !(newAttributes == oldAttributes));
     }
 }
        public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
                                      CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
        {
            document = new PrintedPdfDocument(context, newAttributes);

            CalculateScale(newAttributes);

            var printInfo = new PrintDocumentInfo
                            .Builder("pdf-test.pdf")
                            .SetContentType(PrintContentType.Document)
                            .SetPageCount(1)
                            .Build();

            callback.OnLayoutFinished(printInfo, true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="oldAttributes"></param>
        /// <param name="newAttributes"></param>
        /// <param name="cancellationSignal"></param>
        /// <param name="callback"></param>
        /// <param name="extras"></param>
        public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
        {
            if (cancellationSignal.IsCanceled)
            {
                callback.OnLayoutCancelled();
                return;
            }

            using (PrintDocumentInfo.Builder builder = new PrintDocumentInfo.Builder(FileToPrint))
            {
                //using (
                PrintDocumentInfo pdi = builder.SetContentType(ContentType).Build(); //)
                {
                    callback.OnLayoutFinished(pdi, true);
                }
            }
        }
        private bool WriteCurrentDrawing(Drawing currentDrawing, string PrinterInstance)
        {
            bool            Result           = false;
            DrawingHandler  MyDrawingHandler = new DrawingHandler();
            PrintAttributes printAttributes  = new PrintAttributes();

            printAttributes.Scale = 1.0;
            printAttributes.PrintToMultipleSheet = false;
            printAttributes.NumberOfCopies       = 1;
            printAttributes.Orientation          = DotPrintOrientationType.Auto;
            printAttributes.PrintArea            = DotPrintAreaType.EntireDrawing;
            printAttributes.PrinterInstance      = PrinterInstance;

            Result = MyDrawingHandler.PrintDrawing(currentDrawing, printAttributes);

            return(Result);
        }
Esempio n. 13
0
            public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
            {
                mPdfDocument = new PrintedPdfDocument(CrossPrint.appcontext, newAttributes);

                if (cancellationSignal.IsCanceled)
                {
                    callback.OnLayoutCancelled();
                    return;
                }
                int pages = computePageCount(newAttributes);

                if (pages > 0)
                {
                    PrintDocumentInfo info = new PrintDocumentInfo
                                             .Builder("pdf.pdf")
                                             .SetContentType(PrintContentType.Document)
                                             .SetPageCount(pages).Build();
                    callback.OnLayoutFinished(info, true);
                }
                else
                {
                    callback.OnLayoutFailed("Page count calculation failed.");
                }
            }
Esempio n. 14
0
        private void button1_Click(object sender, EventArgs e)
        {
            DrawingHandler MyDrawingHandler = new DrawingHandler();

            PrintAttributes printAttributes = new PrintAttributes();
            printAttributes.Scale = 1.0;
            printAttributes.PrintToMultipleSheet = false;
            printAttributes.NumberOfCopies = 1;
            printAttributes.Orientation = DotPrintOrientationType.Auto;
            printAttributes.PrintArea = DotPrintAreaType.EntireDrawing;
            printAttributes.PrinterInstance = "PDF_594x420";

            if (MyDrawingHandler.GetConnectionStatus())
            {
                DrawingEnumerator SelectedDrawings = MyDrawingHandler.GetDrawingSelector().GetSelected();
                while (SelectedDrawings.MoveNext())
                {
                    Drawing currentDrawing = SelectedDrawings.Current;

                    //Get print attributes: we need only PrinterInstance
                    MyDrawingHandler.PrintDrawing(currentDrawing, printAttributes);
                }
            }
        }
Esempio n. 15
0
        private bool WriteCurrentDrawing(Drawing currentDrawing, string PrinterInstance)
        {
            bool Result = false;
            DrawingHandler MyDrawingHandler = new DrawingHandler();
            PrintAttributes printAttributes = new PrintAttributes();
            printAttributes.Scale = 1.0;
            printAttributes.PrintToMultipleSheet = false;
            printAttributes.NumberOfCopies = 1;
            printAttributes.Orientation = DotPrintOrientationType.Auto;
            printAttributes.PrintArea = DotPrintAreaType.EntireDrawing;
            printAttributes.PrinterInstance = PrinterInstance;

            Result = MyDrawingHandler.PrintDrawing(currentDrawing, printAttributes);

            return Result;
        }
Esempio n. 16
0
        private bool PrintToFile(Drawing currentDrawing)
        {
            bool Result = false;
            double scale = 1.0;

            if (rbtnSCALE.Checked)
            {
                //get scale of the first view
                //scale = GetScaleFromTheView();
            }

            DrawingHandler MyDrawingHandler = new DrawingHandler();
            PrintAttributes printAttributes = new PrintAttributes();
            printAttributes.Scale = scale;
            printAttributes.PrintToMultipleSheet = false;
            printAttributes.NumberOfCopies = 1;
            printAttributes.Orientation = DotPrintOrientationType.Auto;
            printAttributes.PrintArea = DotPrintAreaType.EntireDrawing;
            printAttributes.PrinterInstance = "DWG";

            string DrawingType = GetDrawingTypeCharacter(currentDrawing);

            /*
            set XS_DRAWING_PLOT_FILE_DIRECTORY=.\PlotFiles
            set XS_DRAWING_PLOT_FILE_NAME_A=%%UDA:PROJECT_USERFIELD_1%%-%%NAME.-%%%%REV_MARK?_Rev%%%%REV_MARK%%
            set XS_DRAWING_PLOT_FILE_NAME_W=%%UDA:PROJECT_USERFIELD_1%%-%%NAME.-%%%%REV_MARK?_Rev%%%%REV_MARK%%
            set XS_DRAWING_PLOT_FILE_NAME_C=%%UDA:PROJECT_USERFIELD_1%%-%%NAME.-%%%%REV_MARK?_Rev%%%%REV_MARK%%
            set XS_DRAWING_PLOT_FILE_NAME_G=%%UDA:PROJECT_USERFIELD_1%%-%%TITLE.-%%%%REV_MARK?_Rev%%%%REV_MARK%%
            set XS_DRAWING_PLOT_FILE_NAME_M=%%UDA:PROJECT_USERFIELD_1%%-%%TITLE.-%%%%REV_MARK?_Rev%%%%REV_MARK%%
             */

            //string output_path = Environment.GetEnvironmentVariable("XS_DRAWING_PLOT_FILE_DIRECTORY");
            string output_path = "c:\\pdf";
            string output_file = "out.dwg";

            Model CurrentModel = new Model();
            ProjectInfo ProjectInfo = CurrentModel.GetProjectInfo();
            if (CurrentModel.GetConnectionStatus())
            {
                output_file = ProjectInfo.ProjectNumber;
            }

            string DrawingName = "";

            //TSM.Operations.Operation.DisplayPrompt("DrawingType" + DrawingType);

            switch (DrawingType)
            {
                case "A":
                //output_file = Environment.GetEnvironmentVariable("XS_DRAWING_PLOT_FILE_NAME_A");
                case "W":
                //output_file = Environment.GetEnvironmentVariable("XS_DRAWING_PLOT_FILE_NAME_W");
                case "C":
                    //output_file = Environment.GetEnvironmentVariable("XS_DRAWING_PLOT_FILE_NAME_C");
                    DrawingName = currentDrawing.Mark;
                    DrawingName = RemoveBrackets(DrawingName);
                    break;
                case "G":
                //output_file = Environment.GetEnvironmentVariable("XS_DRAWING_PLOT_FILE_NAME_G");
                case "M":
                    //output_file = Environment.GetEnvironmentVariable("XS_DRAWING_PLOT_FILE_NAME_M");
                    DrawingName = currentDrawing.Name;
                    break;
                default:
                    goto case "A";
            }

            DrawingName = DrawingName.Replace('.', '-');
            output_file += "-" + DrawingName + ".dwg";

            if (!String.IsNullOrEmpty(output_path) && !String.IsNullOrEmpty(output_file))
                Result = MyDrawingHandler.PrintDrawing(currentDrawing, printAttributes, output_path + "\\" + output_file);

            return Result;
        }
Esempio n. 17
0
 public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
                               CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
 {
     mWrappedInstance.OnLayout(oldAttributes, newAttributes,
                               cancellationSignal, callback, extras);
 }
Esempio n. 18
0
 public PdfPrint(PrintAttributes printAttributes, PdfPrintListener Listener) : this(printAttributes)
 {
     mListener = Listener;
 }
Esempio n. 19
0
 public PdfPrint(PrintAttributes pAttributes)
 {
     printAttributes = pAttributes;
 }
Esempio n. 20
0
            public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
                                          CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
            {
                // If we are already cancelled, don't do any work.
                if (cancellationSignal.IsCanceled)
                {
                    callback.OnLayoutCancelled();
                    return;
                }

                // Now we determined if the print attributes changed in a way that
                // would change the layout and if so we will do a layout pass.
                bool layoutNeeded = false;

                int density = System.Math.Max(newAttributes.GetResolution().HorizontalDpi,
                                              newAttributes.GetResolution().VerticalDpi);

                // Note that we are using the PrintedPdfDocument class which creates
                // a PDF generating canvas whose size is in points (1/72") not screen
                // pixels. Hence, this canvas is pretty small compared to the screen.
                // The recommended way is to layout the content in the desired size,
                // in this case as large as the printer can do, and set a translation
                // to the PDF canvas to shrink in. Note that PDF is a vector format
                // and you will not lose data during the transformation.

                // The content width is equal to the page width minus the margins times
                // the horizontal printer density. This way we get the maximal number
                // of pixels the printer can put horizontally.
                int marginLeft   = (int)(density * (float)newAttributes.MinMargins.LeftMils / MILS_IN_INCH);
                int marginRight  = (int)(density * (float)newAttributes.MinMargins.RightMils / MILS_IN_INCH);
                int contentWidth = (int)(density * (float)newAttributes.GetMediaSize()
                                         .WidthMils / MILS_IN_INCH) - marginLeft - marginRight;

                if (mRenderPageWidth != contentWidth)
                {
                    mRenderPageWidth = contentWidth;
                    layoutNeeded     = true;
                }

                // The content height is equal to the page height minus the margins times
                // the vertical printer resolution. This way we get the maximal number
                // of pixels the printer can put vertically.
                int marginTop     = (int)(density * (float)newAttributes.MinMargins.TopMils / MILS_IN_INCH);
                int marginBottom  = (int)(density * (float)newAttributes.MinMargins.BottomMils / MILS_IN_INCH);
                int contentHeight = (int)(density * (float)newAttributes.GetMediaSize()
                                          .HeightMils / MILS_IN_INCH) - marginTop - marginBottom;

                if (mRenderPageHeight != contentHeight)
                {
                    mRenderPageHeight = contentHeight;
                    layoutNeeded      = true;
                }

                // Create a context for resources at printer density. We will
                // be inflating views to render them and would like them to use
                // resources for a density the printer supports.
                if (mPrintContext == null || mPrintContext.Resources.Configuration.DensityDpi != density)
                {
                    var configuration = new Configuration();
                    configuration.DensityDpi = density;
                    mPrintContext            = pcc.CreateConfigurationContext(configuration);
                    mPrintContext.SetTheme(Android.Resource.Style.ThemeHoloLight);
                }

                // If no layout is needed that we did a layout at least once and
                // the document info is not null, also the second argument is false
                // to notify the system that the content did not change. This is
                // important as if the system has some pages and the content didn't
                // change the system will ask, the application to write them again.
                if (!layoutNeeded)
                {
                    callback.OnLayoutFinished(mDocumentInfo, false);
                    return;
                }

                // For demonstration purposes we will do the layout off the main
                // thread but for small content sizes like this one it is OK to do
                // that on the main thread.
                var asyncTask = new MyOnLayoutAsyncTask(this, newAttributes, cancellationSignal, callback);

                asyncTask.ExecuteOnExecutor(AsyncTask.ThreadPoolExecutor, (Java.Lang.Void[])null);
            }
        private bool PrintToFile(Drawing currentDrawing)
        {
            bool   Result = false;
            double scale  = 1.0;

            if (rbtnSCALE.Checked)
            {
                //get scale of the first view
                //scale = GetScaleFromTheView();
            }

            DrawingHandler  MyDrawingHandler = new DrawingHandler();
            PrintAttributes printAttributes  = new PrintAttributes();

            printAttributes.Scale = scale;
            printAttributes.PrintToMultipleSheet = false;
            printAttributes.NumberOfCopies       = 1;
            printAttributes.Orientation          = DotPrintOrientationType.Auto;
            printAttributes.PrintArea            = DotPrintAreaType.EntireDrawing;
            printAttributes.PrinterInstance      = "DWG";

            string DrawingType = GetDrawingTypeCharacter(currentDrawing);

            /*
             * set XS_DRAWING_PLOT_FILE_DIRECTORY=.\PlotFiles
             * set XS_DRAWING_PLOT_FILE_NAME_A=%%UDA:PROJECT_USERFIELD_1%%-%%NAME.-%%%%REV_MARK?_Rev%%%%REV_MARK%%
             * set XS_DRAWING_PLOT_FILE_NAME_W=%%UDA:PROJECT_USERFIELD_1%%-%%NAME.-%%%%REV_MARK?_Rev%%%%REV_MARK%%
             * set XS_DRAWING_PLOT_FILE_NAME_C=%%UDA:PROJECT_USERFIELD_1%%-%%NAME.-%%%%REV_MARK?_Rev%%%%REV_MARK%%
             * set XS_DRAWING_PLOT_FILE_NAME_G=%%UDA:PROJECT_USERFIELD_1%%-%%TITLE.-%%%%REV_MARK?_Rev%%%%REV_MARK%%
             * set XS_DRAWING_PLOT_FILE_NAME_M=%%UDA:PROJECT_USERFIELD_1%%-%%TITLE.-%%%%REV_MARK?_Rev%%%%REV_MARK%%
             */

            //string output_path = Environment.GetEnvironmentVariable("XS_DRAWING_PLOT_FILE_DIRECTORY");
            string output_path = "c:\\pdf";
            string output_file = "out.dwg";

            Model       CurrentModel = new Model();
            ProjectInfo ProjectInfo  = CurrentModel.GetProjectInfo();

            if (CurrentModel.GetConnectionStatus())
            {
                output_file = ProjectInfo.ProjectNumber;
            }

            string DrawingName = "";

            //TSM.Operations.Operation.DisplayPrompt("DrawingType" + DrawingType);

            switch (DrawingType)
            {
            case "A":
            //output_file = Environment.GetEnvironmentVariable("XS_DRAWING_PLOT_FILE_NAME_A");
            case "W":
            //output_file = Environment.GetEnvironmentVariable("XS_DRAWING_PLOT_FILE_NAME_W");
            case "C":
                //output_file = Environment.GetEnvironmentVariable("XS_DRAWING_PLOT_FILE_NAME_C");
                DrawingName = currentDrawing.Mark;
                DrawingName = RemoveBrackets(DrawingName);
                break;

            case "G":
            //output_file = Environment.GetEnvironmentVariable("XS_DRAWING_PLOT_FILE_NAME_G");
            case "M":
                //output_file = Environment.GetEnvironmentVariable("XS_DRAWING_PLOT_FILE_NAME_M");
                DrawingName = currentDrawing.Name;
                break;

            default:
                goto case "A";
            }

            DrawingName  = DrawingName.Replace('.', '-');
            output_file += "-" + DrawingName + ".dwg";

            if (!String.IsNullOrEmpty(output_path) && !String.IsNullOrEmpty(output_file))
            {
                Result = MyDrawingHandler.PrintDrawing(currentDrawing, printAttributes, output_path + "\\" + output_file);
            }

            return(Result);
        }
Esempio n. 22
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string printer = cmbPrinter.Text;
                string size    = "";
                double scale   = 1;

                PrintAttributes printAttributes = new PrintAttributes();
                printAttributes.ScalingType          = DotPrintScalingType.Scale;
                printAttributes.PrintToMultipleSheet = false;
                printAttributes.NumberOfCopies       = 1;
                printAttributes.Orientation          = DotPrintOrientationType.Auto;
                printAttributes.PrintArea            = DotPrintAreaType.EntireDrawing;

                DrawingEnumerator drawingEnum = drawingHandler.GetDrawingSelector().GetSelected();
                while (drawingEnum.MoveNext())
                {
                    Drawing drawing = (Drawing)drawingEnum.Current;

                    for (int i = 0; i < printerNames.Count; i++)
                    {
                        string printerName = printerNames[i].ToString();
                        if (printerName == cmbPrinter.Text)
                        {
                            double printerScale;
                            bool   printerScaleBool = double.TryParse(printerScales[i].ToString(), out printerScale);

                            if (printerScaleBool)
                            {
                                for (int c = 0; c < papersizeDimensions.Count; c++)
                                {
                                    Tekla.Structures.Drawing.Size m = (Tekla.Structures.Drawing.Size)papersizeDimensions[c];
                                    if (drawing.Layout.SheetSize.Height == m.Height && drawing.Layout.SheetSize.Width == m.Width)
                                    {
                                        size = (string)papersizeNames[c];
                                    }
                                }

                                scale = printerScale;
                            }
                            else
                            {
                                if (cmbSize.Text != "Auto")
                                {
                                    for (int c = 0; c < printsizeNames.Count; c++)
                                    {
                                        if (cmbSize.Text == printsizeNames[c].ToString())
                                        {
                                            size = printsizeNames[c].ToString();
                                            Tekla.Structures.Drawing.Size n = (Tekla.Structures.Drawing.Size)printsizeDimensions[c];
                                            scale = n.Width / drawing.Layout.SheetSize.Width;
                                            scale = double.Parse(scale.ToString("F2"));
                                        }
                                    }
                                }

                                else if (cmbSize.Text == "Auto")
                                {
                                    for (int c = 0; c < papersizeNames.Count; c++)
                                    {
                                        Tekla.Structures.Drawing.Size m = (Tekla.Structures.Drawing.Size)papersizeDimensions[c];
                                        if (drawing.Layout.SheetSize.Height == m.Height && drawing.Layout.SheetSize.Width == m.Width)
                                        {
                                            size  = papersizeAutoPrintsizeNames[c].ToString();
                                            scale = double.Parse(papersizeAutoScales[c].ToString());
                                        }
                                    }
                                }
                            }
                        }
                    }

                    printAttributes.Scale           = scale;
                    printAttributes.PrinterInstance = printer + "-" + size;
                    drawingHandler.PrintDrawing(drawing, printAttributes);
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }