public InstantDocumentViewController(InstantDocumentInfo docInfo) : base(document: null) { //Create the Instant objects with the information from the web-preview server. //The `PSPDFDocument` you get from Instant does not retain the objects that create it, //so we need to keep references to the client and document descriptor otherwise with no //strong references they would deallocate and syncing would stop. client = new PSPDFInstantClient(NSUrl.FromString(docInfo.ServerUrl), out var err); // Remove local storage before downloading in case the app crashed and we didn't remove it `ViewDidDisappear`. client.RemoveLocalStorage(out var localStorageError); documentDescriptor = client.GetDocumentDescriptor(docInfo.Jwt, out var error); // Store document code and URL (which also contains the code) for sharing later. documentCode = docInfo.EncodedDocumentId; webUrl = NSUrl.FromString(docInfo.Url); // Tell Instant to download the document from web-preview’s PSPDFKit Server instance. documentDescriptor.Download(docInfo.Jwt, out var _); // Get the `PSPDFDocument` from Instant. Document = documentDescriptor.EditableDocument; var collaborateItem = new UIBarButtonItem("Collaborate", UIBarButtonItemStyle.Plain, ShowCollaborationOptions); var barButtonItems = new [] { collaborateItem, AnnotationButtonItem }; NavigationItem.SetRightBarButtonItems(barButtonItems, PSPDFViewMode.Document, false); }
void ShowInstantDocument(InstantDocumentInfo documentInfo) { InstantClient.Create(this, documentInfo.ServerUrl).RemoveLocalStorage(); var builder = InstantPdfActivityIntentBuilder.FromInstantDocument(this, documentInfo.ServerUrl, documentInfo.Jwt); var intent = builder .Configuration(configuration) .ActivityClass(Java.Lang.Class.FromType(typeof(InstantExampleActivity))) .Build(); intent.PutExtra(InstantExampleActivity.DocumentDescriptor, documentInfo.ToJson()); StartActivity(intent); Finish(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); documentInfo = InstantDocumentInfo.FromJson(Intent.GetStringExtra(DocumentDescriptor)); if (documentInfo is null) { throw new InvalidOperationException("InstantExampleActivity was not initialized with proper arguments: Missing document descriptor extra!"); } var a = Theme.ObtainStyledAttributes(null, Resource.Styleable.pspdf__ActionBarIcons, Resource.Attribute.pspdf__actionBarIconsStyle, Resource.Style.PSPDFKit_ActionBarIcons); mainToolbarIconsColor = a.GetColor(Resource.Styleable.pspdf__ActionBarIcons_pspdf__iconsColor, ContextCompat.GetColor(this, Resource.Color.pspdf__color_white)); a.Recycle(); InitCollaborateMenu(); }
public async Task <InstantDocumentInfo> ResolveDocument(string code) { try { var response = await httpClient.GetAsync($"{instantCodeEndpointUrl}/instant/{WebUtility.UrlEncode (code)}"); response.EnsureSuccessStatusCode(); // Do not allocate a string for the json reponse, read directly from the stream using (var stream = await response.Content.ReadAsStreamAsync()) using (var reader = new StreamReader(stream)) using (var json = new JsonTextReader(reader)) { return(InstantDocumentInfo.FromJson(json)); } } catch (HttpRequestException ex) { Console.WriteLine(ex.Message); return(null); } }
public async Task <InstantDocumentInfo> CreateNewDocument() { try { var response = await httpClient.PostAsync($"{instantCodeEndpointUrl}/instant-landing-page", null); response.EnsureSuccessStatusCode(); // Do not allocate a string for the json reponse, read directly from the stream using (var stream = await response.Content.ReadAsStreamAsync()) using (var reader = new StreamReader(stream)) using (var json = new JsonTextReader(reader)) { return(InstantDocumentInfo.FromJson(json)); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } }
public async Task <InstantDocumentInfo> ResolveDocument(Uri uri) { try { var msg = new HttpRequestMessage(); msg.Headers.Add("Accept", "application/vnd.instant-example+json"); msg.RequestUri = uri; var response = await httpClient.SendAsync(msg); response.EnsureSuccessStatusCode(); // Do not allocate a string for the json reponse, read directly from the stream using (var stream = await response.Content.ReadAsStreamAsync()) using (var reader = new StreamReader(stream)) using (var json = new JsonTextReader(reader)) { return(InstantDocumentInfo.FromJson(json)); } } catch (HttpRequestException ex) { Console.WriteLine(ex.Message); return(null); } }
public static void ToJson(this InstantDocumentInfo self, JsonTextWriter jsontw) => InstantDocumentInfo.serializer.Serialize(jsontw, self, typeof(InstantDocumentInfo));
public static string ToJson(this InstantDocumentInfo self) => JsonConvert.SerializeObject(self, Converter.Settings);