public override void LaunchExample(Context ctx, PdfActivityConfiguration.Builder configuration) { Task.Factory.StartNew(async() => { AndHUD.Shared.Show(ctx, $"Downloading file....", cancelCallback: client.CancelPendingRequests); PrepareConfiguration(configuration); var docUrl = "https://pspdfkit.com/downloads/case-study-box.pdf"; var docPath = Path.Combine(ctx.CacheDir.ToString(), AssetPath); using (var file = new FileStream(docPath, FileMode.Create, FileAccess.Write, FileShare.None)) await client.DownloadDataAsync(docUrl, file); AndHUD.Shared.Dismiss(ctx); var jfile = new Java.IO.File(docPath); var docUri = Android.Net.Uri.FromFile(jfile); // Start the PSPDFKitAppCompat activity by passing it the Uri of the file. if (PSPDFKitGlobal.IsOpenableUri(ctx, docUri)) { PdfActivity.ShowDocument(ctx, docUri, configuration.Build()); } else { AndHUD.Shared.ShowError(ctx, $"This document uri cannot be opened:\n{docUri}", MaskType.Black, TimeSpan.FromSeconds(2)); } }); }
public virtual void LaunchExample(Context ctx, PdfActivityConfiguration.Builder configuration) { // Extract the pdf from assets if not already extracted var docUri = Utils.ExtractAsset(ctx, AssetPath); PrepareConfiguration(configuration); // Start the PSPDFKitAppCompat activity by passing it the Uri of the file. if (PSPDFKitGlobal.IsOpenableUri(ctx, docUri)) { PdfActivity.ShowDocument(ctx, docUri, configuration.Build()); } else { AndHUD.Shared.ShowError(ctx, $"This document uri cannot be opened:\n{docUri}", MaskType.Black, TimeSpan.FromSeconds(2)); } }
void ShowPdfDocument(Android.Net.Uri docUri) { // Show Document using PSPDFKit activity var pspdfkitConfiguration = new PdfActivityConfiguration.Builder(ApplicationContext) .ScrollDirection(PageScrollDirection.Horizontal) .ShowPageNumberOverlay() .ShowThumbnailGrid() .FitMode(PageFitMode.FitToWidth) .Build(); if (!PSPDFKitGlobal.IsOpenableUri(this, docUri)) { ShowError("This document uri cannot be opened \n " + docUri.ToString()); } else { PdfActivity.ShowDocument(this, docUri, pspdfkitConfiguration); } }
// Opens a demo document from assets directory, called from Xamarin.Forms's DependencyService, see 'ShowPDF ()' method in XFSamplePage.xaml.cs public void ShowPdfActivity() { // Extract the pdf from assets if not already extracted var docUri = Utils.ExtractAsset(CrossCurrentActivity.Current.Activity, sampleDoc); // Show Document using PSPDFKit activity var pspdfkitConfiguration = new PdfActivityConfiguration.Builder(CrossCurrentActivity.Current.Activity) .ScrollDirection(PageScrollDirection.Horizontal) .ShowPageNumberOverlay() .ShowThumbnailGrid() .FitMode(PageFitMode.FitToWidth) .Build(); if (!PSPDFKitGlobal.IsOpenableUri(this, docUri)) { ShowError("This document uri cannot be opened \n " + docUri.ToString()); } else { PdfActivity.ShowDocument(CrossCurrentActivity.Current.Activity, docUri, pspdfkitConfiguration); } }