void OnButtonClicked(object sender, EventArgs e) { //Load PDF document to stream. #if COMMONSB Stream docStream = typeof(Booklet).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Samples.Assets.JavaScript Succinctly.pdf"); #else Stream docStream = typeof(Booklet).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.JavaScript Succinctly.pdf"); #endif //Load the PDF document into the loaded document object. PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream); float width = 1224; float height = 792; //Create a booklet form exisitng PDF document PdfDocument document = PdfBookletCreator.CreateBooklet(ldoc, new SizeF(width, height), true); MemoryStream stream = new MemoryStream(); //Save the PDF document document.Save(stream); //Close the PDF document document.Close(true); if (Device.RuntimePlatform == Device.WinPhone || Device.RuntimePlatform == Device.UWP) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("Booklet.pdf", "application/pdf", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("Booklet.pdf", "application/pdf", stream); } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> //protected override void OnNavigatedTo(NavigationEventArgs e) //{ //} private async void Button_Click_1(object sender, RoutedEventArgs e) { Stream docStream = typeof(Template).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Syncfusion_Windows8_whitepaper.pdf"); PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream); float width = 0f; float height = 0f; //Create booklet with two sides float.TryParse(txtPageWidth.Text, out width); float.TryParse(txtPageheight.Text, out height); PdfDocument document = PdfBookletCreator.CreateBooklet(ldoc, new SizeF(width, height), (bool)rdbtnDoubleSide.IsChecked); MemoryStream stream = new MemoryStream(); await document.SaveAsync(stream); document.Close(true); Save(stream, "Booklet.pdf"); }
public ActionResult Booklet(string PageHeight, string PageWidth, string CheckBoxDoubleSide, string InsideBrowser) { try { if (String.IsNullOrEmpty(PageWidth) || String.IsNullOrEmpty(PageHeight)) { ViewData["Error"] = "Please ensure the width and height for the page to be updated."; } else { string basePath = _hostingEnvironment.WebRootPath; string dataPath = string.Empty; dataPath = basePath + @"/PDF/"; //Read the file as stream FileStream file = new FileStream(dataPath + "Essential_Pdf.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Load a PDF document PdfLoadedDocument ldoc = new PdfLoadedDocument(file); //Create booklet with two sides PdfDocument pdf = PdfBookletCreator.CreateBooklet(ldoc, new SizeF(float.Parse(PageWidth), float.Parse(PageHeight)), (CheckBoxDoubleSide == "DoubleSide") ? true : false); //Save the PDF to the MemoryStream MemoryStream ms = new MemoryStream(); pdf.Save(ms); //If the position is not set to '0' then the PDF will be empty. ms.Position = 0; //Close the PDF document. pdf.Close(true); ldoc.Close(true); //Download the PDF document in the browser. FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf"); fileStreamResult.FileDownloadName = "Booklet.pdf"; return(fileStreamResult); } } catch (Exception ex) { ViewData["Error"] = ex.ToString(); } return(View()); }
void OnButtonClicked(object sender, EventArgs e) { Stream docStream = typeof(Booklet).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.JavaScript Succinctly.pdf"); PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream); float width = 1224; float height = 792; PdfDocument document = PdfBookletCreator.CreateBooklet(ldoc, new Syncfusion.Drawing.SizeF(width, height), true); MemoryStream stream = new MemoryStream(); document.Save(stream); document.Close(true); if (stream != null) { SaveiOS iosSave = new SaveiOS(); iosSave.Save("Booklet.pdf", "application/pdf", stream); } }
void OnButtonClicked(object sender, EventArgs e) { Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Syncfusion_Windows8_whitepaper.pdf"); PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream); float width = 1224; float height = 792; PdfDocument document = PdfBookletCreator.CreateBooklet(ldoc, new SizeF(width, height), true); MemoryStream stream = new MemoryStream(); document.Save(stream); document.Close(true); if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("Booklet.pdf", "application/pdf", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("Booklet.pdf", "application/pdf", stream); } }
public ActionResult Booklet(string PageHeight, string PageWidth, string CheckBoxDoubleSide, string InsideBrowser) { try { if (PageWidth == String.Empty || PageHeight == String.Empty) { ViewData["Error"] = "Please ensure the width and height for the page to be updated."; } else { //Read the file as stream Stream file = new FileStream(ResolveApplicationDataPath("Essential_Pdf.pdf"), FileMode.Open, FileAccess.Read); //Load a PDF document PdfLoadedDocument ldoc = new PdfLoadedDocument(file); //Create booklet with two sides PdfDocument pdf = PdfBookletCreator.CreateBooklet(ldoc, new SizeF(float.Parse(PageWidth), float.Parse(PageHeight)), (CheckBoxDoubleSide == "DoubleSide") ? true : false); //Save the document if (InsideBrowser == "Browser") { return(pdf.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(pdf.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } } } catch (Exception ex) { ViewData["Error"] = ex.ToString(); } return(View()); }