public override void Init(object initData) { base.Init(initData); if (initData is byte[]) { PdfDocumentStream = new MemoryStream(initData as byte[]); } else if (initData is Tuple <byte[], int> ) { PdfLoadedDocument loadedDocument = new PdfLoadedDocument(((Tuple <byte[], int>)initData).Item1); PdfDocument document = new PdfDocument(); int startIndex = 0; int endIndex = ((Tuple <byte[], int>)initData).Item2 - 1; endIndex = Math.Min(loadedDocument.Pages.Count, endIndex); //Import all the pages to the new PDF document. document.ImportPageRange(loadedDocument, startIndex, endIndex); var _stream = new MemoryStream(); document.Save(_stream); loadedDocument.Close(); document.Close(); PdfDocumentStream = _stream; } }
public ActionResult PdfA1bConverter(string Browser, HttpPostedFileBase file = null) { if (file != null && file.ContentLength > 0) { //Load an existing PDF. PdfLoadedDocument doc = new PdfLoadedDocument(file.InputStream); //Set the conformance for PDF/A-1b conversion. doc.Conformance = PdfConformanceLevel.Pdf_A1B; string[] fileName = file.FileName.Split(new string[] { ".pdf" }, StringSplitOptions.RemoveEmptyEntries); //Stream the output to the browser. if (Browser == "Browser") { return(doc.ExportAsActionResult(fileName[0] + "_A1b.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(doc.ExportAsActionResult(fileName[0] + "_A1b.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } } else { ViewBag.lab = "Choose a valid PDF file."; return(View()); } }
private void button1_Click(object sender, EventArgs e) { string location = "../../Data/CustomInvoice.pdf"; //Load the PDF document PdfLoadedDocument page1Document = new PdfLoadedDocument(location); //Created new Pdf Document PdfDocument doc = new PdfDocument(); //Gets the form from Loaded document PdfLoadedForm form = page1Document.Form; //Gets the Form fields PdfLoadedFormFieldCollection field = form.Fields; // fill the form fields. for (int i = 0; i < field.Count; i++) { string name = (form.Fields[i].Name); (form.Fields[name]).Flatten = true; (form.Fields[name]).ToolTip = "sample"; } //flattens the whole form. form.Flatten = true; //Append the loaded document doc.Append(page1Document); //Save the document and dispose it doc.Save("Converted-" + DateTime.Now.ToString("mmssddMMyyyy") + ".pdf"); doc.Close(); label1.Text = "Done. Please check Bin folder."; }
public MemoryStream GetPdf(string html) { HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = @"../../QtBinariesDotNetCore/"; settings.Margin = new Syncfusion.Pdf.Graphics.PdfMargins { All = 30 }; settings.PdfPageSize = new SizeF(512, 692); settings.WebKitViewPort = new Size(800, 0); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert(html, ""); string filePath = "D:\\DemoProjects\\Movers\\MoversApi\\temp\\RevisedEstimate_back.pdf"; FileStream fileStream = new FileStream(filePath, FileMode.Open); PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream); //Save and close the PDF document MemoryStream stream = new MemoryStream(); PdfDocumentBase.Merge(document, loadedDocument); document.Save(stream); document.Close(true); return(stream); }
public ActionResult ImportAndStamp(string Browser, string Stamptext, HttpPostedFileBase file) { PdfLoadedDocument ldoc = null; if (file != null && file.ContentLength > 0) { ldoc = new PdfLoadedDocument(file.InputStream); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36f); foreach (PdfPageBase lPage in ldoc.Pages) { PdfGraphics graphics = lPage.Graphics; PdfGraphicsState state = graphics.Save(); graphics.SetTransparency(0.25f); graphics.RotateTransform(-40); graphics.DrawString(Stamptext, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); graphics.Restore(state); } } else { ViewBag.lab = "NOTE: Please select PDF document."; return(View()); } //Stream the output to the browser. if (Browser == "Browser") { return(ldoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(ldoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }
public ActionResult RearrangePages(string Browser, string submit1) { if (submit1 == "View Template") { string dataPath = ResolveApplicationDataPath("SyncfusionBrochure.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument loadedDocument = new PdfLoadedDocument(file2); return(loadedDocument.ExportAsActionResult("InputTemplate.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } //Load the input PDF document PdfLoadedDocument ldoc = new PdfLoadedDocument(ResolveApplicationDataPath("SyncfusionBrochure.pdf")); //Rearrange the page by index ldoc.Pages.ReArrange(new int[] { 2, 0, 1 }); //Stream the output to the browser. if (Browser == "Browser") { return(ldoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(ldoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }
//加载Pdf到View public async void ViewPdf(string folderName, string pdfName) { pdfFolderName = folderName; pdfFileName = pdfName; StorageFolder applicationFolder = ApplicationData.Current.LocalFolder; StorageFolder methodFolder; if (ClickStatus == 0) { methodFolder = await applicationFolder.CreateFolderAsync("runTest", CreationCollisionOption.OpenIfExists); } else { methodFolder = await applicationFolder.CreateFolderAsync("calibrate", CreationCollisionOption.OpenIfExists); } StorageFolder pdfFolder = await methodFolder.CreateFolderAsync(folderName, CreationCollisionOption.OpenIfExists); StorageFile pdfFile = await pdfFolder.GetFileAsync(pdfName); using (var stream = await pdfFile.OpenReadAsync()) { Stream fileStream = stream.AsStreamForRead(); byte[] buffer = new byte[fileStream.Length]; fileStream.Read(buffer, 0, buffer.Length); //Loads the PDF document. PdfLoadedDocument ldoc = new PdfLoadedDocument(buffer); pdfViewer.LoadDocument(ldoc); pdfViewer.PdfProgressRing.Visibility = Visibility.Collapsed; } }
void OnButtonClicked(object sender, EventArgs e) { Stream docStream = typeof(Booklet).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.SalesOrderDetail.pdf"); //Load the PDF document into the loaded document object. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); //Get the certificate stream from .pfx file. Stream certificateStream = typeof(DigitalSignature).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.PDF.pfx"); //Create PdfCertificate using certificate stream and password. PdfCertificate pdfCert = new PdfCertificate(certificateStream, "password123"); //Add certificate to document first page. PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], pdfCert, "Signature"); signature.Bounds = new Syncfusion.Drawing.RectangleF(5, 5, 300, 300); MemoryStream stream = new MemoryStream(); //Save the PDF document loadedDocument.Save(stream); //Close the PDF document loadedDocument.Close(true); if (stream != null) { stream.Position = 0; ComposeMail("DigitalSignature.pdf", null, "Signing the document", "Syncfusion", 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); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 100f, PdfFontStyle.Regular); foreach (PdfPageBase lPage in ldoc.Pages) { PdfGraphics g = lPage.Graphics; PdfGraphicsState state = g.Save(); g.SetTransparency(0.25f); g.TranslateTransform(50, lPage.Size.Height / 2 ); g.RotateTransform(-40); g.DrawString("Syncfusion", font, PdfPens.Red, PdfBrushes.Red, new PointF(0,0)); } MemoryStream stream = new MemoryStream(); ldoc.Save(stream); ldoc.Close(true); if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) Xamarin.Forms.DependencyService.Get<ISaveWindowsPhone>().Save("Stamping.pdf", "application/pdf", stream); else Xamarin.Forms.DependencyService.Get<ISave>().Save("Stamping.pdf", "application/pdf", stream); }
public async Task LoadPdfAsync(string fileName) { var cached = _cache.FirstOrDefault(c => c.FileName == fileName); if (cached != null) { _extractedText = cached.Text; return; } _extractedText = await Task.Factory.StartNew(() => { var ldoc = new PdfLoadedDocument(fileName); var loadedPages = ldoc.Pages; var parsedTextBuilder = new StringBuilder(); foreach (PdfLoadedPage lpage in loadedPages) { parsedTextBuilder.Append(lpage.ExtractText()); } return(parsedTextBuilder.ToString()); }); _cache.Add(new CachedText { FileName = fileName, Text = _extractedText }); }
static void Main(string[] args) { //Load the PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../../../../../Data/Invoice.pdf"); // Get the first page of the loaded PDF document PdfPageBase page = loadedDocument.Pages[0]; TextLines lineCollection = new TextLines(); // Extract text from the first page with bounds page.ExtractText(out lineCollection); RectangleF textBounds = new RectangleF(474, 161, 50, 9); string invoiceNumer = ""; //Get the text provided in the bounds foreach (TextLine txtLine in lineCollection) { foreach (TextWord word in txtLine.WordCollection) { if (textBounds.IntersectsWith(word.Bounds)) { invoiceNumer = word.Text; break; } } } //Close the PDF document loadedDocument.Close(true); File.WriteAllText("data.txt", invoiceNumer); }
private void button3_Click(object sender, RoutedEventArgs e) { if (documentStream == null) { documentStream = typeof(DigitalSignature).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Essential_Studio.pdf"); } //Load the selected PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); //Get the .pfx certificate file stream. if (certificateStream == null) { certificateStream = typeof(DigitalSignature).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.PDF.pfx"); } //Create PdfCertificate using certificate stream and password. PdfCertificate pdfCert = new PdfCertificate(certificateStream, txtOwnerPassword.Password); //Add certificate to document first page. PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], pdfCert, "Signature"); signature.Bounds = new System.Drawing.RectangleF(5, 5, 300, 300); MemoryStream stream = new MemoryStream(); loadedDocument.Save(stream); loadedDocument.Close(true); SaveFile(stream, "output.PDF"); }
public ActionResult ImageExtraction(string Browser, string submit1) { if (submit1 == "View Template") { string dataPath = ResolveApplicationDataPath("Brochure.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument ldoc = new PdfLoadedDocument(file2); return(ldoc.ExportAsActionResult("InputTemplate.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } //Load an existing PDF. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(ResolveApplicationDataPath("Brochure.pdf")); //Load first page. PdfPageBase pageBase = loadedDocument.Pages[0]; //Extract images from first page. System.Drawing.Image[] extractedImages = pageBase.ExtractImages(); //Stream the output to the browser. if (Browser == "Browser") { ExportAsImage(extractedImages[0], "sample.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg, HttpContext.ApplicationInstance.Response, HttpReadType.Open); } else { ExportAsImage(extractedImages[0], "sample.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg, HttpContext.ApplicationInstance.Response, HttpReadType.Save); } return(View()); }
private static void OnExecutePrintTreeGrid(object sender, ExecutedRoutedEventArgs args) { var treeGrid = args.Source as SfTreeGrid; if (treeGrid == null) { return; } try { var options = new TreeGridPdfExportingOptions(); options.AllowIndentColumn = true; options.FitAllColumnsInOnePage = true; var document = treeGrid.ExportToPdf(options, true); PdfViewerControl pdfViewer = new PdfViewerControl(); MemoryStream stream = new MemoryStream(); document.Save(stream); PdfLoadedDocument ldoc = new PdfLoadedDocument(stream); pdfViewer.Load(ldoc); // if you want to show the pdf viewer window. Please enable the below line, //MainWindow pdfPage = new MainWindow(); //pdfPage.Content = pdfViewer; //pdfPage.Show(); pdfViewer.Print(true); } catch (Exception) { } }
public void OnTemplateButtonClicked(object sender, EventArgs e) { #if COMMONSB Stream docStream = typeof(MailAttachment).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Samples.Assets.FormFillingDocument.pdf"); #else Stream docStream = typeof(MailAttachment).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.FormFillingDocument.pdf"); #endif MemoryStream stream = new MemoryStream(); //Load the template document using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream)) { //Save the document loadedDocument.Save(stream); } if (Device.RuntimePlatform == Device.UWP) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("MailAttachmentTemplate.pdf", "application/pdf", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("MailAttachmentTemplate.pdf", "application/pdf", stream); } }
//Set password for a PDF document public static void SetDocumentPassword(string inputFilePath, string password) { try { Console.WriteLine("Setting password..."); var loadedDocument = new PdfLoadedDocument(inputFilePath); var security = loadedDocument.Security; security.KeySize = Syncfusion.Pdf.Security.PdfEncryptionKeySize.Key256Bit; security.Algorithm = Syncfusion.Pdf.Security.PdfEncryptionAlgorithm.AES; security.UserPassword = password; var inputFileName = Path.GetFileNameWithoutExtension(inputFilePath); var targetFilePath = Path.GetDirectoryName(inputFilePath) + @"\" + inputFileName + "-WithPassword.pdf"; loadedDocument.Save(targetFilePath); loadedDocument.Close(true); Console.WriteLine("Password set and document saved"); } catch { throw; } }
public void MergePDF() { //Loads document PdfLoadedDocument combinePDF = new PdfLoadedDocument(workPath + pdfFileName); PdfDocument newPDF = new PdfDocument(); //Imports the page at 1 from the lDoc foreach (int pageNum in pages) { newPDF.ImportPage(combinePDF, pageNum - 1); } //Saves the document newPDF.Save("new.pdf"); //Closes the document newPDF.Close(true); combinePDF.Close(true); }
public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); this.MinimizeBox = true; #if NETCORE txtSplitDoc.Tag = @"..\..\..\..\..\..\..\Common\Data\PDF\Essential_Studio.pdf"; #else txtSplitDoc.Tag = @"..\..\..\..\..\..\Common\Data\PDF\Essential_Studio.pdf"; #endif txtSplitDoc.Text = "Essential_Studio.pdf"; ldoc = new PdfLoadedDocument(txtSplitDoc.Tag.ToString()); // To load a existing document which has to be split nudSplitPage.Maximum = ldoc.Pages.Count; txtSplitDoc.Validating += new CancelEventHandler(txtSplitDoc_Validating); nudSplitPage.Validating += new CancelEventHandler(nudSplitPage_Validating); // // TODO: Add any constructor code after InitializeComponent call // }
private async void Button_Click_1(object sender, RoutedEventArgs e) { Stream docStream = typeof(StampDocument).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Essential_Studio.pdf"); PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36f); foreach (PdfPageBase lPage in ldoc.Pages) { PdfGraphics g = lPage.Graphics; PdfGraphicsState state = g.Save(); g.SetTransparency(0.25f); g.RotateTransform(-40); g.DrawString(stampText.Text, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); if (imagewatermark.IsChecked.Value) { Stream imagestream = typeof(StampDocument).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Ani.gif"); PdfImage image = new PdfBitmap(imagestream); g.Restore(state); g.SetTransparency(0.25f); g.DrawImage(image, 0, 0, lPage.Graphics.ClientSize.Width, lPage.Graphics.ClientSize.Height); imagestream.Dispose(); } } MemoryStream stream = new MemoryStream(); await ldoc.SaveAsync(stream); ldoc.Close(true); Save(stream, "StampDocument.pdf"); docStream.Dispose(); }
public ActionResult ReplaceFonts(string Browser, string submit1) { if (submit1 == "View Template") { string dataPath = ResolveApplicationDataPath("ReplaceFont.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument ldoc = new PdfLoadedDocument(file2); return(ldoc.ExportAsActionResult("InputTemplate.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } //Load an existing PDF. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(ResolveApplicationDataPath("ReplaceFont.pdf")); //Replace font loadedDocument.UsedFonts[0].Replace(new PdfTrueTypeFont(new Font("Monotype Corsiva", 12, FontStyle.Regular), false)); //Stream the output to the browser. if (Browser == "Browser") { return(loadedDocument.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(loadedDocument.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }
private void PrintExecute(object obj) { var treeGrid = obj as SfTreeGrid; if (treeGrid == null) { return; } try { var options = new TreeGridPdfExportingOptions(); options.AllowIndentColumn = true; options.FitAllColumnsInOnePage = true; var document = treeGrid.ExportToPdf(options); PdfViewerControl pdfViewer = new PdfViewerControl(); MemoryStream stream = new MemoryStream(); document.Save(stream); PdfLoadedDocument ldoc = new PdfLoadedDocument(stream); pdfViewer.Load(ldoc); pdfViewer.Print(true); } catch (Exception) { } }
public IActionResult ExtractText(string ViewTemplate, string Extract) { string basePath = _hostingEnvironment.WebRootPath; FileStream fileStreamInput = new FileStream(basePath + @"/PDF/HTTP Succinctly.pdf", FileMode.Open, FileAccess.Read); if (!string.IsNullOrEmpty(ViewTemplate)) { FileStreamResult fileStreamResult = new FileStreamResult(fileStreamInput, "application/pdf"); fileStreamResult.FileDownloadName = "HTTP Succinctly.pdf"; return(fileStreamResult); } else if (!string.IsNullOrEmpty(Extract)) { PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStreamInput); string extractedText = string.Empty; for (var i = 0; i < loadedDocument.Pages.Count; i++) { extractedText += loadedDocument.Pages[i].ExtractText(true); } byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(extractedText); MemoryStream stream = new MemoryStream(byteArray); FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/txt"); fileStreamResult.FileDownloadName = "Sample.txt"; return(fileStreamResult); } return(View()); }
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); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 100f, PdfFontStyle.Regular); foreach (PdfPageBase lPage in ldoc.Pages) { PdfGraphics g = lPage.Graphics; PdfGraphicsState state = g.Save(); g.SetTransparency(0.25f); g.TranslateTransform(50, lPage.Size.Height / 2); g.RotateTransform(-40); g.DrawString("Syncfusion", font, PdfPens.Red, PdfBrushes.Red, new PointF(0, 0)); g.Restore(state); } MemoryStream stream = new MemoryStream(); ldoc.Save(stream); ldoc.Close(true); if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("Stamping.pdf", "application/pdf", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("Stamping.pdf", "application/pdf", stream); } }
void OnButtonClicked(object sender, EventArgs e) { Stream docStream = typeof(Stamping).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Product Catalog.pdf"); PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 100f, PdfFontStyle.Regular); foreach (PdfPageBase lPage in ldoc.Pages) { PdfGraphics g = lPage.Graphics; PdfGraphicsState state = g.Save(); g.TranslateTransform(ldoc.Pages[0].Size.Width / 2, ldoc.Pages[0].Size.Height / 2); g.SetTransparency(0.25f); SizeF waterMarkSize = font.MeasureString("Sample"); g.RotateTransform(-40); g.DrawString("Sample", font, PdfPens.Red, PdfBrushes.Red, new PointF(-waterMarkSize.Width / 2, -waterMarkSize.Height / 2)); g.Restore(state); } MemoryStream stream = new MemoryStream(); ldoc.Save(stream); ldoc.Close(true); if (stream != null) { SaveAndroid androidSave = new SaveAndroid(); androidSave.Save("Stamping.pdf", "application/pdf", stream, m_context); } }
private async void Button_Click(object sender, RoutedEventArgs e) { //Opens a file picker. var picker = new FileOpenPicker(); picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; picker.ViewMode = PickerViewMode.List; //Filters PDF files in the documents library. picker.FileTypeFilter.Add(".pdf"); var file = await picker.PickSingleFileAsync(); if (file == null) { return; } //Reads the stream of the loaded PDF document. var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); Stream fileStream = stream.AsStreamForRead(); byte[] buffer = new byte[fileStream.Length]; fileStream.Read(buffer, 0, buffer.Length); //Loads the PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(buffer); pdfViewer.LoadDocument(loadedDocument); }
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.UWP) { 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 SplitPDF(string Browser, string pageIndex, HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); int splitAtPage = int.Parse(pageIndex.ToString()); PdfLoadedDocument ldoc = new PdfLoadedDocument(file.InputStream); if (splitAtPage <= ldoc.Pages.Count && splitAtPage != 0) { //Create PDF documents. PdfDocument doc1 = new PdfDocument(); //Import PDF document into splitAtPage index. doc1.ImportPage(ldoc, splitAtPage - 1); //Save to disk if (Browser == "Browser") { return(doc1.ExportAsActionResult("Document1.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(doc1.ExportAsActionResult("Document1.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } } else { ViewBag.lab = "Invalid Page no"; } } return(View()); }
//Remove password from password protected PDF file public static void RemoveDocumentPassword(string inputFilePath, string password) { try { Console.WriteLine("Removing password..."); var loadedDocument = new PdfLoadedDocument(inputFilePath, password); loadedDocument.Security.UserPassword = string.Empty; var inputFileName = Path.GetFileNameWithoutExtension(inputFilePath); var targetFilePath = Path.GetDirectoryName(inputFilePath) + @"\" + inputFileName + "-WithoutPassword.pdf"; loadedDocument.Save(targetFilePath); loadedDocument.Close(true); Console.WriteLine("Password removed and document saved"); } catch (PdfDocumentException) { throw; } catch (Exception) { throw; } }
static void Main(string[] args) { //Initialize OCR processor OCRProcessor processor = new OCRProcessor(@"../../../../../../Data/TesseractBinaries/3.02/"); //Load a PDF document PdfLoadedDocument lDoc = new PdfLoadedDocument("../../../../../../Data/Invoice_scanned.pdf"); //Set OCR language to process processor.Settings.Language = Languages.English; OCRLayoutResult hocrBounds; processor.PerformOCR(lDoc, @"../../../../../../Data/Tessdata/", out hocrBounds); StreamWriter writer = new StreamWriter("data.txt"); foreach (Page pages in hocrBounds.Pages) { foreach (Line line in pages.Lines) { writer.WriteLine(line.Text); } } writer.Close(); lDoc.Close(true); processor.Dispose(); }
//Change password for a PDF document public static void ChangeDocumentPassword(string inputFilePath, string existingPassword, string newPassword) { try { Console.WriteLine("Changing document password..."); var loadedDocument = new PdfLoadedDocument(inputFilePath, existingPassword); loadedDocument.Security.UserPassword = newPassword; var inputFileName = Path.GetFileNameWithoutExtension(inputFilePath); var targetFilePath = Path.GetDirectoryName(inputFilePath) + @"\" + inputFileName + "-WithNewPassword.pdf"; loadedDocument.Save(targetFilePath); loadedDocument.Close(true); Console.WriteLine("Password changed and document saved"); } catch (PdfDocumentException) { throw; } catch (Exception) { throw; } }
/// <summary> /// Export to PDF on Button click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Exportbutton_Click(object sender, EventArgs e) { var converter = new GridPDFConverter(); var lowest = 0; //Adding PageBreaks to a list. var rows = new List <int> { 30, 63, 90, 130, 150 }; var pdfDocument = new PdfDocument(); pdfDocument.Save("Sample.pdf"); foreach (var rownumber in rows) { var pdf = new PdfDocument(); var maximumRow = rownumber; converter.ExportToPdf(pdf, gridControl1, GridRangeInfo.Rows(lowest, maximumRow)); var stream = new MemoryStream(); pdf.Save(stream); var loadedDocument = new PdfLoadedDocument("Sample.pdf"); loadedDocument = PdfDocumentBase.Merge(loadedDocument, new PdfLoadedDocument(stream)) as PdfLoadedDocument; loadedDocument.Save("Sample.pdf"); loadedDocument.Close(true); stream.Dispose(); lowest = maximumRow + 1; } var loadedDocument1 = new PdfLoadedDocument("Sample.pdf"); loadedDocument1.Pages.RemoveAt(0); loadedDocument1.Save("Sample.pdf"); Process.Start("Sample.pdf"); }
public async Task<string> Extract(StorageFile file, int pageNumber) { var doc = new PdfLoadedDocument(); await doc.OpenAsync(file); var page = doc.Pages[pageNumber]; var extractedText = page.ExtractText(); return extractedText; }
public async Task<string> Extract(StorageFile file, int startPageNumber, int endPageNumber) { var doc = new PdfLoadedDocument(); await doc.OpenAsync(file); var sb = new StringBuilder(); for (var i = startPageNumber; i <= endPageNumber; i++) { var page = doc.Pages[i]; sb.Append(page.ExtractText()); } return sb.ToString(); }
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 async void LoadDefaultFile() { if (ShellViewModel.SelectedBook == null) return; var storageFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(ShellViewModel.SelectedBook.Source.Token); var file = await storageFolder.GetFileAsync(ShellViewModel.SelectedBook.FileName); _loadedFile = file; LoadPdf(_loadedFile); if (file != null) { var stream = await file.OpenAsync(FileAccessMode.Read); var fileStream = stream.AsStreamForRead(); var buffer = new byte[fileStream.Length]; fileStream.Read(buffer, 0, buffer.Length); doc = new PdfLoadedDocument(buffer); } }