Esempio n. 1
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, 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));
     }
 }
        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);
        }
Esempio n. 4
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));
     }
 }
        /// <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);
                }
            }
        }
Esempio n. 6
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. 7
0
 protected override void OnCancelled()
 {
     // Task was cancelled, report that.
     callback.OnLayoutCancelled();
 }
Esempio n. 8
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);
            }