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);
        }
        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);
        }
			public override void OnLayout (PrintAttributes oldAttributes, PrintAttributes newAttributes, 
				CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
			{
				mWrappedInstance.OnLayout(oldAttributes, newAttributes,
					cancellationSignal, callback, extras);
			}
Exemple #4
0
		public override void OnLayout (PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, Android.Print.PrintDocumentAdapter.LayoutResultCallback callback, Bundle extras)
		{

			if (cancellationSignal.IsCanceled) {
				callback.OnLayoutCancelled ();
				return;
			}

			PrintDocumentInfo pdi = new PrintDocumentInfo.Builder (PrintService.pdfName).SetContentType (Android.Print.PrintContentType.Document).Build ();

			callback.OnLayoutFinished (pdi, true);
		}