/// <summary> /// Note: Not stable. /// </summary> /// <param name="webview"></param> private async void CreatePDF1(Android.Webkit.WebView webview) { //var pageCount = await GetPDFPageCount(webview); PdfDocument document = new PdfDocument(); PdfDocument.Page page = document.StartPage(new PdfDocument.PageInfo.Builder(2120, 3000, 1).Create()); await Task.Delay(34); webview.Draw(page.Canvas); document.FinishPage(page); Stream filestream = null; FileOutputStream fos = null; try { filestream = new MemoryStream(); fos = new Java.IO.FileOutputStream(fileNameWithPath, false); document.WriteTo(filestream); fos.Write(((MemoryStream)filestream).ToArray(), 0, (int)filestream.Length); } catch (Java.Lang.Exception e) { System.Console.WriteLine(e.Message); } finally { filestream?.Close(); fos?.Close(); } document.Close(); OnPageLoadFinished?.Invoke(this, new EventArgs()); }
private void PlayRecording(object sender, EventArgs e) { Label l = (Label)sender; Java.IO.File tempFile = Java.IO.File.CreateTempFile($"{l.Text}", ".mp3"); Models.AudioRecord ar = (Models.AudioRecord)l.BindingContext; if (!mp.IsPlaying) { FileOutputStream fos = new Java.IO.FileOutputStream(tempFile); fos.Write(ar.AudioClip); fos.Close(); mp.Reset(); //string path = $"{Android.OS.Environment.ExternalStorageDirectory.AbsolutePath}/{l.Text}.mp3"; Java.IO.FileInputStream fis = new Java.IO.FileInputStream(tempFile); mp.SetDataSource(fis.FD); mp.Prepare(); mp.Start(); } else { mp.Stop(); mp.Release(); tempFile.Delete(); } }
private void openRenderer(Context context) { // In this sample, we read a PDF from the assets directory. File file = new File(context.CacheDir, FILENAME); if (!file.Exists()) { // Since PdfRenderer cannot handle the compressed asset file directly, we copy it into // the cache directory. System.IO.Stream input = context.Assets.Open(FILENAME); Java.IO.FileOutputStream output = new Java.IO.FileOutputStream(file); byte[] buffer = new byte[1024]; int size; while ((size = input.Read(buffer, 0, buffer.Length)) > 0) { output.Write(buffer, 0, size); } input.Close(); output.Close(); } parcelFileDescriptor = ParcelFileDescriptor.Open(file, ParcelFileMode.ReadOnly); // This is the PdfRenderer we use to render the PDF. if (parcelFileDescriptor != null) { pdfRenderer = new PdfRenderer(parcelFileDescriptor); } }
public bool Paste(Template template) { string path = Path + "/" + Move_copy_file.Name; if (Move_copy_file.IsFile) { try { javaIO.InputStream source = new javaIO.FileInputStream(Move_copy_file.AbsolutePath); javaIO.OutputStream dest = new javaIO.FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = source.Read(buffer)) > 0) { dest.Write(buffer, 0, length); } source.Close(); dest.Close(); } catch (Exception e) { return(false); } if (move) { Delete(template); move = false; } } else if (Move_copy_file.IsDirectory) { new DirectoryInfo(template.Getfile.AbsolutePath).CreateSubdirectory(Move_copy_file.Name); File newDirectory = new File(path); if (newDirectory.Exists()) { } CopyDirectory(template); } template.Getfile = new File(path); Initialization(); Update(); Move_copy_file = null; return(true); }
public bool UnzipFiles(string path, string zipname) { var f = new Java.IO.File(path); if (!f.Exists()) { f.Mkdir(); } try { String filename; var inputstream = System.IO.File.Open(Path.Combine(path, zipname + ".zip"), FileMode.Open); var zis = new Java.Util.Zip.ZipInputStream(inputstream); Java.Util.Zip.ZipEntry ze; byte[] buffer = new byte[1024]; int count; while ((ze = zis.NextEntry) != null) { filename = ze.Name; // Need to create directories if not exists, or // it will generate an Exception... if (ze.IsDirectory) { Java.IO.File fmd = new Java.IO.File(Path.Combine(Path.Combine(path, zipname), filename)); fmd.Mkdirs(); continue; } var fout = new Java.IO.FileOutputStream(Path.Combine(Path.Combine(path, zipname), filename)); while ((count = zis.Read(buffer)) != -1) { fout.Write(buffer, 0, count); } fout.Close(); zis.CloseEntry(); } zis.Close(); } catch (Java.IO.IOException iox) { System.Console.WriteLine(iox.Message); return(false); } return(true); }
private void CopyApkToAppFolder() { var inputStream = Assets.Open("app.apk"); var outPath = FilesDir.AbsolutePath + "/app.apk"; var outputStream = new Java.IO.FileOutputStream(outPath); byte[] buffer = new byte[1024]; int n; while ((n = inputStream.Read(buffer, 0, buffer.Length)) > 0) { outputStream.Write(buffer, 0, n); } inputStream.Close(); outputStream.Close(); }
public override void OnPageFinished(Android.Webkit.WebView myWebview, string url) { PdfDocument document = new PdfDocument(); PdfDocument.Page page = document.StartPage(new PdfDocument.PageInfo.Builder(2120, 3000, 1).Create()); myWebview.Draw(page.Canvas); document.FinishPage(page); Stream filestream = new MemoryStream(); FileOutputStream fos = new Java.IO.FileOutputStream(fileNameWithPath, false);; try { document.WriteTo(filestream); fos.Write(((MemoryStream)filestream).ToArray(), 0, (int)filestream.Length); fos.Close(); } catch { } }