public void homeBtn_Click(object sender, RoutedEventArgs e)
        {
            WindowScreen home = (WindowScreen)Window.GetWindow(this);

            zoomValue         = 0.8;
            zoomLabel.Content = $"{zoomValue * 100}%";
            PageImage.Source  = null;
            bottom            = 0;
            //hide TOC & bookmark
            bookmarkBorder.Visibility = Visibility.Collapsed;
            TOCBorder.Visibility      = Visibility.Collapsed;
            //clear TOC & bookmark
            bookmarkList.Clear();
            toc.Clear();
            file.Close();
            if (changeFile)
            {
                try
                {
                    pdfFileBookmark.Save();
                }
                catch (Exception)
                {
                    MessageBox.Show("Cannot save changes because the file is open in another program", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }

                changeFile = false;
            }
            if (pdfFileBookmark != null)
            {
                pdfFileBookmark.Close(true);
            }

            home.ReturnFromReadingScreen_Click(sender, e);
        }
        /// <summary>
        /// Splits and creates a new PDF document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSplit_Click(object sender, EventArgs e)
        {
            string dataPath1 = File1.ResolveClientUrl(File1.Value);

            if (System.IO.Path.GetExtension(dataPath1).Equals(".pdf"))
            {
                Stream stream1 = File1.PostedFile.InputStream;

                //Load a PDF document
                PdfLoadedDocument ldoc = new PdfLoadedDocument(stream1);

                //Get first page from document
                PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage;

                if (x.Text != "" && y.Text != "" && width.Text != "" && height.Text != "")
                {
                    float x1      = float.Parse(x.Text);
                    float y1      = float.Parse(y.Text);
                    float width1  = float.Parse(width.Text);
                    float height1 = float.Parse(height.Text);

                    //Create PDF redaction for the page
                    PdfRedaction redaction = new PdfRedaction(new RectangleF(x1, y1, width1, height1), Color.Black);

                    //Adds the redaction to loaded page
                    lpage.Redactions.Add(redaction);

                    //Save to disk
                    if (this.CheckBox1.Checked)
                    {
                        ldoc.Save("Document1.pdf", Response, HttpReadType.Open);
                    }
                    else
                    {
                        ldoc.Save("Document1.pdf", Response, HttpReadType.Save);
                    }
                }
                else
                {
                    lb_error.Visible = true;
                    lb_error.Text    = "Note: Fill all the fields then redact";
                }
            }
            else
            {
                lb_error.Visible = true;
                lb_error.Text    = "Invalid file type. Please select a PDF file";
            }
        }
示例#3
0
        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);
            }
        }
示例#4
0
        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);
            }
        }
示例#5
0
        public void Save(string filename)
        {
            MemoryStream stream = new MemoryStream();

            if (m_loadedDoc != null)
            {
                m_loadedDoc.Save(stream);
            }
            else
            {
                Init();
                m_document.Save(stream);
                m_document.Close(true);
            }
            stream.Position = 0;

#if __ANDROID__
            SaveAndroid.Save(filename, "application/pdf", stream, MainActivity.TheView);
#elif __IOS__
            PreviewController.Save(filename, "application/pdf", stream);
#endif
            m_document = null;

            Utils.SaveFile(filename, stream);
        }
示例#6
0
        private void MergePDF_Click(object sender, RoutedEventArgs e)
        {
            //Get template PDF file stream from assembly.
            if (firstDocumentStream == null)
            {
                firstDocumentStream = typeof(MergePDF).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.pdf_succinctly.pdf");
            }
            //Get template PDF file stream from assembly.
            if (secondDocumentStream == null)
            {
                secondDocumentStream = typeof(MergePDF).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.form_template.pdf");
            }

            //Load the PDF document from stream.
            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(firstDocumentStream);

            //Load and merge the pdf documents.
            PdfDocument.Merge(loadedDocument, new PdfLoadedDocument(secondDocumentStream));

            //Creating the stream object.
            using (MemoryStream stream = new MemoryStream())
            {
                //Save and close the document.
                loadedDocument.Save(stream);
                loadedDocument.Close();

                stream.Position = 0;
                //Save the output stream as a file using file picker.
                PdfUtil.Save("MergePDF.pdf", stream);
            }
            Dispose();
        }
        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);
            }
        }
示例#8
0
        //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;
            }
        }
示例#9
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Stream documentStream;
            string fileName = string.Empty;

            if ((bool)import.IsChecked)
            {
                //Get the import template PDF file stream from assembly.
                documentStream = typeof(ImportAndExport).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.form_template.pdf");
                fileName       = "ImportForm_Template.pdf";
            }
            else
            {
                //Get the export template PDF file stream from assembly.
                documentStream = typeof(ImportAndExport).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.export_template.pdf");
                fileName       = "ExportForm_Template.pdf";
            }
            //Load the PDF document from stream.
            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream);

            //Creating the stream object.
            using (MemoryStream stream = new MemoryStream())
            {
                //Save and close the document.
                loadedDocument.Save(stream);
                loadedDocument.Close();

                stream.Position = 0;

                //Save the output stream as a file using file picker.
                PdfUtil.Save(fileName, stream);
            }
        }
示例#10
0
        //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;
            }
        }
示例#11
0
        //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;
            }
        }
        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);
        }
示例#13
0
        public static bool MarkPdf(string inputFileName, string outputFileName, int jobNo, int jtsk, string userName, int qty = 0, string notes = "")
        {
            using (PdfLoadedDocument ldoc = new PdfLoadedDocument(inputFileName))
            {
                foreach (PdfPageBase page in ldoc.Pages)
                {
                    //PdfPageBase page = ldoc.Pages[0];
                    PdfGraphics gra = page.Graphics;

                    SizeF pgSize = page.Size;

                    string qtyText = "";
                    if (qty > 0)
                    {
                        qtyText = "- TOTAL QTY : {qty}   ";
                    }

                    gra.DrawString($"JOB :{jobNo} | JTSK : {jtsk}     ISSUED BY : {userName}", font, PdfBrushes.Blue, 10, pgSize.Height - 10, new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Bottom));
                    gra.DrawString($"ISSUE DATE :{DateTime.Now:d}   {qtyText}{notes}", font, PdfBrushes.Blue, 10, pgSize.Height - 20, new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Bottom));
                }
                ldoc.Save(outputFileName);
                ldoc.Close(true);
                return(true);
            }
        }
示例#14
0
        /// <summary>
        /// Creates PDF
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //Load a PDF document.
            PdfLoadedDocument document = new PdfLoadedDocument(GetFullTemplatePath("EmpDetails.pdf", false));

            //Get first page from document
            PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;

            //Create PDF redaction for the page to redact text
            PdfRedaction textRedaction = new PdfRedaction(new RectangleF(343, 147, 60, 17), System.Drawing.Color.Black);
            //Create PDF redaction for the page to redact image
            PdfRedaction imageRedaction = new PdfRedaction(new RectangleF(67, 372, 178, 158), System.Drawing.Color.Black);

            //Adds the redactions to loaded page
            page.Redactions.Add(textRedaction);
            page.Redactions.Add(imageRedaction);

            //Save the PDF document
            document.Save("Redacted.pdf");

            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
                Process.Start("Redacted.pdf");
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
        }
示例#15
0
        private void FillAndFlatten_Click(object sender, RoutedEventArgs e)
        {
            //Get the template PDF form file stream from assembly.
            Stream documentStream = typeof(FormFilling).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.form_template.pdf");
            //Load the PDF document from stream.
            PdfLoadedDocument document = new PdfLoadedDocument(documentStream);

            //File the PDF form.
            FillDocument(document);

            //Flatten the form fields in a document.
            if (document.Form != null)
            {
                document.Form.Flatten = true;
            }

            //Creating the stream object.
            using (MemoryStream stream = new MemoryStream())
            {
                //Save and close the document.
                document.Save(stream);
                document.Close();

                stream.Position = 0;
                //Save the output stream as a file using file picker.
                PdfUtil.Save("FormFillAndFlatten.pdf", stream);
            }
        }
示例#16
0
        private bool EncryptDocument(IFormFile uploadedFile, FileDetail fileDetail, ProcessResult processResult)
        {
            try
            {
                PdfLoadedDocument document = new PdfLoadedDocument(uploadedFile.OpenReadStream());
                //Create a document security.
                PdfSecurity security = document.Security;
                //Set user password for the document.
                security.UserPassword = fileDetail.FilePassword;
                //Set encryption algorithm.
                security.Algorithm = PdfEncryptionAlgorithm.AES;
                //Set key size.
                security.KeySize = PdfEncryptionKeySize.Key256Bit;

                using (FileStream outputFileStream = new FileStream($"{fileDetail.FilePath}{fileDetail.FileName}", FileMode.Create))
                {
                    document.Save(outputFileStream);
                    document.Close(true);
                }

                processResult.processResults.Add(
                    new ProcessResult {
                    IsSuccess = true, Message = "File Successfully saved to local filesystem"
                });
                return(true);
            }
            catch (Exception ex)
            {
                processResult.processResults.Add(
                    new ProcessResult {
                    IsSuccess = false, Message = ex.Message
                });
                return(false);
            }
        }
        /// <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");
        }
        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");
        }
示例#19
0
        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);
            }
        }
        private void btnSplitPDF_Click(object sender, System.EventArgs e)
        {
            PdfImageInfo[] imagesInfo = ldoc.Pages[0].ImagesInfo;

            foreach (PdfImageInfo imgInfo in imagesInfo)
            {
                //Removing Image
                ldoc.Pages[0].RemoveImage(imgInfo);
            }
            ldoc.Save("RemoveImage.pdf");
            ldoc.Close();
            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
#if NETCORE
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo("RemoveImage.pdf")
                {
                    UseShellExecute = true
                };
                process.Start();
#else
                System.Diagnostics.Process.Start("RemoveImage.pdf");
#endif
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
        }
        private async void StampingSample()
        {
            //Load PDF document to stream.
            Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Syncfusion_Windows8_whitepaper.pdf");

            MemoryStream stream = new MemoryStream();

            //Load the PDF document into the loaded document object.
            using (PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream))
            {
                //Create font object.
                PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 100f, PdfFontStyle.Regular);

                //Stamp or watermark on all the pages.
                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);
                }

                //Save the PDF document
                ldoc.Save(stream);
            }

            stream.Position = 0;

            if (IsToggled)
            {
                //Open in Essential PDF viewer.
                PdfViewerUI pdfViewer = new SampleBrowser.PdfViewerUI();
                pdfViewer.PdfDocumentStream = stream;
                if (Device.Idiom != TargetIdiom.Phone && Device.OS == TargetPlatform.Windows)
                {
                    await PDFViewModel.Navigation.PushModalAsync(new NavigationPage(pdfViewer));
                }
                else
                {
                    await PDFViewModel.Navigation.PushAsync(pdfViewer);
                }
            }
            else
            {
                //Open in default system viewer.
                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);
                }
            }
        }
示例#22
0
        public ActionResult RearrangePages(string Browser, string submit1)
        {
            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;

            dataPath = basePath + @"/PDF/";
            if (submit1 == "View Template")
            {
                Stream file2 = new FileStream(dataPath + "SyncfusionBrochure.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);

                //Load the template document
                PdfLoadedDocument loadedDocument = new PdfLoadedDocument(file2);

                //Save the PDF to the MemoryStream
                MemoryStream ms = new MemoryStream();

                loadedDocument.Save(ms);

                //If the position is not set to '0' then the PDF will be empty.
                ms.Position = 0;

                //Close the PDF document.
                loadedDocument.Close(true);

                //Download the PDF document in the browser.
                FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
                fileStreamResult.FileDownloadName = "InputTemplate.pdf";
                return(fileStreamResult);
            }
            else
            {
                //Read the file
                FileStream file = new FileStream(dataPath + "SyncfusionBrochure.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                //Load the input PDF document
                PdfLoadedDocument ldoc = new PdfLoadedDocument(file);

                //Rearrange the page by index
                ldoc.Pages.ReArrange(new int[] { 2, 0, 1 });

                //Save the PDF to the MemoryStream
                MemoryStream ms = new MemoryStream();

                ldoc.Save(ms);

                //If the position is not set to '0' then the PDF will be empty.
                ms.Position = 0;

                //Close the PDF document.
                ldoc.Close(true);

                //Download the PDF document in the browser.
                FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
                fileStreamResult.FileDownloadName = "RearrangedPages.pdf";
                return(fileStreamResult);
            }
        }
示例#23
0
        private void btnImport_Click(object sender, System.EventArgs e)
        {
            PdfLoadedDocument lDoc = new PdfLoadedDocument(txtUrl.Tag.ToString());
            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(txtStamp.Text, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450));
                g.Restore(state);

                if (chbWatermark.Checked)
                {
                    g.Save();
#if NETCORE
                    PdfImage image = new PdfBitmap(@"..\..\..\..\..\..\..\..\Common\Images\PDF\Ani.gif");
#else
                    PdfImage image = new PdfBitmap(@"..\..\..\..\..\..\..\Common\Images\PDF\Ani.gif");
#endif
                    g.SetTransparency(0.25f);
                    g.DrawImage(image, 0, 0, lPage.Graphics.ClientSize.Width, lPage.Graphics.ClientSize.Height);
                    g.Restore();
                }
            }


            lDoc.Save("Sample.pdf");

            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
#if NETCORE
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                {
                    UseShellExecute = true
                };
                process.Start();
#else
                System.Diagnostics.Process.Start("Sample.pdf");
#endif
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
        }
示例#24
0
        public static void AssinarDocumento()
        {
            var    arquivoEnt = $"d:\\temp\\modelo.pdf";
            var    pdf        = DSHelper.ReadContent(arquivoEnt);
            var    arquivo    = $"d:\\temp\\modeloOut.pdf";
            float  x;
            float  y;
            Stream pfxStream = File.OpenRead("MRV ENGENHARIA E PARTICIPAÇÕES S.A..pfx");
            //Creates a certificate instance from PFX file with private key.
            PdfCertificate pdfCert = new PdfCertificate(pfxStream, "zzzzz");

            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(pdf);

            var lista = new Dictionary <int, List <Syncfusion.Drawing.RectangleF> >();

            loadedDocument.FindText("Assinado:", out lista);

            foreach (var item in lista)
            {
                x = item.Value[0].X + 100;
                y = item.Value[0].Y;
                var page = loadedDocument.Pages[item.Key] as PdfLoadedPage;

                //aplica logo da assinatura em todas as paginas
                if (page != null)
                {
                    Stream      seloStream     = File.OpenRead("SeloMrv.jpg");
                    PdfBitmap   signatureImage = new PdfBitmap(seloStream);
                    PdfGraphics gfx            = page.Graphics;
                    gfx.DrawImage(signatureImage, x, y, 90, 80);
                }

                //Applica o certificado somente na ultima pagina
                if (item.Value == lista[lista.Keys.Count - 1])
                {
                    //Creates a signature field.
                    PdfSignatureField signatureField = new PdfSignatureField(page, "AssinaturaMRV");
                    signatureField.Bounds    = new Syncfusion.Drawing.RectangleF(x, item.Value[0].Y, 50, 50);
                    signatureField.Signature = new PdfSignature(page, "MRV Engenharia");
                    //Adds certificate to the signature field.
                    signatureField.Signature.Certificate = pdfCert;
                    signatureField.Signature.Reason      = "Assinado pela MRV Engenharia";

                    //Adds the field.
                    loadedDocument.Form.Fields.Add(signatureField);
                }
            }
            //Saves the certified PDF document.
            using (FileStream fileOut = new FileStream(arquivo, FileMode.Create))
            {
                loadedDocument.Save(fileOut);
                loadedDocument.Close(true);
            }
            //return arquivo;
        }
示例#25
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            fileStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream(path);
            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream);
            MemoryStream      stream         = new MemoryStream();

            loadedDocument.Save(stream);
            loadedDocument.Close(true);
            await DependencyService.Get <ISave>().SaveAndView(name, "application/pdf", stream);

            await Navigation.PushModalAsync(new ThankPage());
        }
示例#26
0
        public static void SaveFile(PdfLoadedDocument loadedDocument, string folderName, string subFolder, string pubName)
        {
            Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), folderName, subFolder));

            var fs = File.Create($"{folderName}\\{subFolder}\\{pubName}.pdf");

            // Save the document
            loadedDocument.Save(fs);
            // Close the document
            loadedDocument.Close(true);
            // This will open the PDF file so, the result will be seen in default PDF viewer
            // Process.Start("Form.pdf");
        }
示例#27
0
        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            string text = textbox.Text;

            // Get the template PDF file stream from assembly.
            Stream documentStream = typeof(FindText).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.pdf_succinctly.pdf");

            //Load the PDF document from stream.
            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream);

            TextSearchResultCollection results;

            //Create list and add a string text to find from PDF document.
            List <string> searchItem = new List <string>();

            searchItem.Add(text);

            //Find text from PDF document and get the result collection.
            loadedDocument.FindText(searchItem, out results);

            //Iterate over the result collection.
            foreach (var result in results)
            {
                //Get the PDF page using the result.
                PdfLoadedPage page = loadedDocument.Pages[result.Key] as PdfLoadedPage;
                //Save the current graphics state.
                page.Graphics.Save();
                //Set transparency to the page graphics.
                page.Graphics.SetTransparency(0.5F);

                foreach (var matchedItem in result.Value)
                {
                    //Draw rectangle to highlight the text in PDF page.
                    page.Graphics.DrawRectangle(PdfBrushes.Yellow, matchedItem.Bounds);
                }
                //Restore the graphics state.
                page.Graphics.Restore();
            }

            //Creating the stream object.
            using (MemoryStream stream = new MemoryStream())
            {
                //Save and close the document.
                loadedDocument.Save(stream);
                loadedDocument.Close();

                stream.Position = 0;
                //Save the output stream as a file using file picker.
                PdfUtil.Save("FindText.pdf", stream);
            }
        }
        private async void MergeSample()
        {
            //Load PDF document to stream.
            Stream docStream1 = typeof(MergePDF).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Essential_Pdf.pdf");
            Stream docStream2 = typeof(MergePDF).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Essential_XlsIO.pdf");

            MemoryStream stream = new MemoryStream();

            //Load the existing documents
            using (PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream1))
            {
                using (PdfLoadedDocument ldoc1 = new PdfLoadedDocument(docStream2))
                {
                    //Merge the PDF documents
                    PdfDocument.Merge(ldoc, ldoc1);

                    //Save the document
                    ldoc.Save(stream);
                }
            }

            stream.Position = 0;

            if (IsToggled)
            {
                //Open in Essential PDF viewer.
                PdfViewerUI pdfViewer = new SampleBrowser.PdfViewerUI();
                pdfViewer.PdfDocumentStream = stream;
                if (Device.Idiom != TargetIdiom.Phone && Device.OS == TargetPlatform.Windows)
                {
                    await PDFViewModel.Navigation.PushModalAsync(new NavigationPage(pdfViewer));
                }
                else
                {
                    await PDFViewModel.Navigation.PushAsync(pdfViewer);
                }
            }
            else
            {
                //Open in default system viewer.
                if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
                {
                    Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("MergePDF.pdf", "application/pdf", stream);
                }
                else
                {
                    Xamarin.Forms.DependencyService.Get <ISave>().Save("MergePDF.pdf", "application/pdf", stream);
                }
            }
        }
示例#29
0
        private void ImportData()
        {
            //Get the template PDF file stream from assembly.
            Stream documentStream = typeof(ImportAndExport).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.form_template.pdf");

            //Load the PDF document from stream.
            PdfLoadedDocument document = new PdfLoadedDocument(documentStream);

            //Initialize import form setting to import form data.
            ImportFormSettings settings = new ImportFormSettings();

            string fileName = string.Empty;

            if ((bool)fdf.IsChecked)
            {
                //Set data format to import form data from FDF format.
                settings.DataFormat = DataFormat.Fdf;
                fileName            = "import_data.fdf";
            }
            else if ((bool)xfdf.IsChecked)
            {
                //Set data format to import form data from XFDF format.
                settings.DataFormat = DataFormat.XFdf;
                fileName            = "import_data.xfdf";
            }
            else
            {
                //Set data format to import form data from XML format.
                settings.DataFormat = DataFormat.Xml;
                fileName            = "import_data.xml";
            }
            //Get the data file stream to import.
            Stream dataStream = typeof(ImportAndExport).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets." + fileName);

            //Import form data from stream
            document.Form.ImportData(dataStream, settings);

            //Creating the stream object.
            using (MemoryStream stream = new MemoryStream())
            {
                //Save and close the document.
                document.Save(stream);
                document.Close();

                stream.Position = 0;
                //Save the output stream as a file using file picker.
                PdfUtil.Save("ImportedDocument.pdf", stream);
            }
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            //Load an existing PDF.
            PdfLoadedDocument document = new PdfLoadedDocument(this.GetFullTemplatePath(@"Redaction.pdf", false));

            //Get first page from document
            PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;

            //Create PDF redaction for the page to redact text
            PdfRedaction textRedaction = new PdfRedaction(new RectangleF(86.998f, 39.565f, 62.709f, 20.802f), System.Drawing.Color.Black);
            //Create PDF redaction for the page to redact text
            PdfRedaction pathRedaction = new PdfRedaction(new RectangleF(83.7744f, 576.066f, 210.0746f, 104.155f), System.Drawing.Color.Black);
            //Create PDF redaction for the page to redact text
            PdfRedaction imageRedaction = new PdfRedaction(new RectangleF(327.848f, 63.97198f, 232.179f, 223.429f), System.Drawing.Color.Black);

            //Adds the redactions to loaded page
            page.Redactions.Add(textRedaction);
            page.Redactions.Add(pathRedaction);
            page.Redactions.Add(imageRedaction);

            //Save and close the PDF document
            document.Save("Redacted.pdf");
            document.Close(true);

            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
#if NETCORE
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Redacted.pdf")
                {
                    UseShellExecute = true
                };
                process.Start();
#else
                System.Diagnostics.Process.Start("Redacted.pdf");
#endif
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
        }
        private void CreateTxtFromPDF(string filename)
        {
            //ScanPageStatus scanPageStatus = new ScanPageStatus();

            string tesseractPath = Path.Combine(AssemblyDirectory(), GetConstants.TesseractBinaries());
            string tesseractData = Path.Combine(AssemblyDirectory(), GetConstants.TesseractData());

            try {
                using (OCRProcessor processor = new OCRProcessor(tesseractPath))
                {
                    //Stream pdfStream2 = filename; // FileUpload1.PostedFile.InputStream;

                    // Read in PDF image file, and convert to searchable TXT pdf file
                    PdfLoadedDocument IDoc = new PdfLoadedDocument(filename);
                    processor.Settings.Language    = Languages.English;
                    processor.Settings.Performance = Performance.Slow;
                    // var zz = processor.Settings.Performance;
                    //string tessdata = tesseractPath + @"\\Tessdata\\";
                    processor.PerformOCR(IDoc, tesseractData);
                    string outFileName = Path.GetFileName(filename) + "_OCR" + Path.GetExtension(filename);
                    string homePath    = Path.GetDirectoryName(Path.GetDirectoryName(filename));
                    string savePath    = Path.Combine(homePath, GetConstants.Directory("out"), outFileName);

                    // If file exists - delete it first.
                    if (File.Exists(savePath))
                    {
                        File.SetAttributes(savePath, FileAttributes.Normal);
                        File.Delete(savePath);
                    }

                    IDoc.Save(savePath);
                    IDoc.Close(true);
                    IDoc.Dispose();

                    scanPageStatus.scannedFileName = savePath;
                    scanPageStatus.rc            = 0;
                    scanPageStatus.statusMessage = String.Format("File {0} scanned and saved to {1}", filename, scanPageStatus.scannedFileName);
                }
            }
            catch (Exception ex)
            {
                scanPageStatus.scannedFileName = "";
                scanPageStatus.statusMessage   = String.Format("Error {0} when running OCR on source file {1}", ex, filename);
                scanPageStatus.rc = -1;
            }

            // return scanPageStatus;
        }