-
Notifications
You must be signed in to change notification settings - Fork 204
/
GettingStartedPDFViewer.cs
73 lines (70 loc) · 2.99 KB
/
GettingStartedPDFViewer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Syncfusion.SfPdfViewer.Android;
using System.IO;
using System.Reflection;
using Android.Views.InputMethods;
using System.Diagnostics;
using static Android.Views.ViewGroup;
using Android.Graphics;
namespace SampleBrowser
{
[Activity(ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
public class PdfViewerDemo : SamplePage
{
SfPdfViewer pdfViewerControl;
LinearLayout mainView;
public override View GetSampleContent(Context context)
{
LayoutInflater layoutInflater = LayoutInflater.From(context);
mainView = (LinearLayout)layoutInflater.Inflate(Resource.Layout.PDFViewer, null);
pdfViewerControl = (SfPdfViewer)mainView.FindViewById(Resource.Id.pdfviewercontrol);
Stream docStream = typeof(PdfViewerDemo).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDFViewer.Assets.GIS Succinctly.pdf");
pdfViewerControl.LoadDocument(docStream);
pdfViewerControl.DocumentSaveInitiated += PdfViewerControl_DocumentSaveInitiated;
pdfViewerControl.PreserveSignaturePadOrientation = true;
return mainView;
}
private void PdfViewerControl_DocumentSaveInitiated(object sender, DocumentSaveInitiatedEventArgs args)
{
MemoryStream stream = args.SavedStream as MemoryStream;
string root = null;
string fileName = "sample.pdf";
if (Android.OS.Environment.IsExternalStorageEmulated)
{
root = Android.OS.Environment.ExternalStorageDirectory.ToString();
}
else
root = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
Java.IO.File directory = new Java.IO.File(root + "/Syncfusion");
directory.Mkdir();
Java.IO.File file = new Java.IO.File(directory, fileName);
if (file.Exists()) file.Delete();
Java.IO.FileOutputStream outputStream = new Java.IO.FileOutputStream(file);
outputStream.Write(stream.ToArray());
outputStream.Flush();
outputStream.Close();
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mainView.Context);
alertDialog.SetTitle("Save");
alertDialog.SetMessage("The modified document is saved in the below location. " + "\n" + file.Path);
alertDialog.SetPositiveButton("OK", (senderAlert, e) => { });
Dialog dialog = alertDialog.Create();
dialog.Show();
}
public override void Destroy()
{
pdfViewerControl.Unload();
GC.Collect();
GC.WaitForPendingFinalizers();
base.Destroy();
}
}
}