static void Main(string[] args) { // Load a document with an interactive form. PdfDocumentProcessor processor = new PdfDocumentProcessor(); processor.LoadDocument(@"DocumentToFill.pdf"); // Retrieve the form field facade: PdfDocumentFacade documentFacade = processor.DocumentFacade; PdfAcroFormFacade acroFormFacade = documentFacade.AcroForm; // Specify a checked appearance name for the Female radio button: PdfRadioGroupFormFieldFacade genderField = acroFormFacade.GetRadioGroupFormField("Gender"); foreach (PdfFormFieldItem item in genderField.Field.Items) { if (item.Value == "Female") { genderField.Value = item.Value; } } // Save the modified document. processor.SaveDocument("..\\..\\Result.pdf"); }
private void fillDocsGrid() { using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor()) { pdfDocumentProcessor.CreateEmptyDocument(); DataSet ds = ProjectFunctions.GetDataSet("Select * from ImagesData Where DocNo='" + DocNo + "' And DocType= '" + DocType + "' And DocDate='" + DocDate.Date.ToString("yyyy-MM-dd") + "' order by transid desc"); if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { if (dr["DocPDF"].ToString().Trim().Length > 0) { Byte[] MyData = new byte[0]; MyData = (Byte[])dr["DocPDF"]; MemoryStream stream = new MemoryStream(MyData); stream.Position = 0; pdfDocumentProcessor.AppendDocument(stream); } } } pdfDocumentProcessor.SaveDocument("C:\\Temp\\abc.pdf"); pdfDocumentProcessor.CloseDocument(); pdfViewer1.LoadDocument("C:\\Temp\\abc.pdf"); } }
static void Main(string[] args) { // Create a PDF Document Processor. using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) { // Load a document. processor.LoadDocument("..\\..\\Document.pdf"); // Add a text markup annotation to the first page for a text corresponding to the specified page area. PdfTextMarkupAnnotationData annot = processor.AddTextMarkupAnnotation(1, new PdfRectangle(90, 100, 240, 230), PdfTextMarkupAnnotationType.Highlight); if (annot != null) { // Specify the annotation properties. annot.Author = "Bill Smith"; annot.Contents = "Note"; annot.Color = new PdfRGBColor(0.8, 0.2, 0.1); // Save the result document. processor.SaveDocument("..\\..\\Result.pdf"); } else { Console.WriteLine("The annotation cannot be added to a page. Make sure, a specified page area corresponds to a text on the page."); } } }
public Task <ParsingResult> Parse(ParsingRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } logger.LogDebug("Parsing [{0}]", request.File.FullName); var document = new RawDocument(); using (var documentProcessor = new PdfDocumentProcessor()) { documentProcessor.LoadDocument(request.File.FullName); var pages = request.MaxPages > documentProcessor.Document.Pages.Count ? documentProcessor.Document.Pages.Count : request.MaxPages; var pagesList = new List <RawPage>(); document.Pages = new RawPage[pages]; for (var i = 1; i <= pages; i++) { var page = new RawPage(); var data = GetImage(request, documentProcessor, i); page.Blocks = ocrImageParser.Parse(data).ToArray(); document.Pages[i - 1] = page; } } return(Task.FromResult(new ParsingResult(document, request, ParsingType.OCR))); }
static void Main(string[] args) { using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) { // Load a document. processor.LoadDocument("..\\..\\Document.pdf"); // Create bookmarks and add them to the PDF document. PdfDestination destination1 = processor.CreateDestination(1, 180, 150); PdfDestination destination2 = processor.CreateDestination(1, 168, 230); PdfDestination destination3 = processor.CreateDestination(1, 20, 350); processor.Document.Bookmarks.Add(new PdfBookmark() { Title = "PDF Document Processor", Destination = destination1 }); processor.Document.Bookmarks.Add(new PdfBookmark() { Title = "Display, Print and Export PDF Documents", Destination = destination2 }); processor.Document.Bookmarks.Add(new PdfBookmark() { Title = "Learn More", Destination = destination3 }); // Save the result document. processor.SaveDocument("..\\..\\Result.pdf"); } }
static void Main(string[] args) { using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor()) { // Load a PDF document. pdfDocumentProcessor.LoadDocument("..\\..\\Demo.pdf"); // Specify printing, data extraction, modification, and interactivity permissions. PdfEncryptionOptions encryptionOptions = new PdfEncryptionOptions(); encryptionOptions.PrintingPermissions = PdfDocumentPrintingPermissions.Allowed; encryptionOptions.DataExtractionPermissions = PdfDocumentDataExtractionPermissions.NotAllowed; encryptionOptions.ModificationPermissions = PdfDocumentModificationPermissions.DocumentAssembling; encryptionOptions.InteractivityPermissions = PdfDocumentInteractivityPermissions.Allowed; // Specify the owner and user passwords for the document. encryptionOptions.OwnerPasswordString = "OwnerPassword"; encryptionOptions.UserPasswordString = "UserPassword"; // Specify the 256-bit AES encryption algorithm. encryptionOptions.Algorithm = PdfEncryptionAlgorithm.AES256; // Save the protected document with encryption settings. pdfDocumentProcessor.SaveDocument("..\\..\\ProtectedDocument.pdf", new PdfSaveOptions() { EncryptionOptions = encryptionOptions }); } }
public void Coordenadas(string path) { try { List <Tuple <string, PdfOrientedRectangle> > WordCoordinates = new List <Tuple <string, PdfOrientedRectangle> >(); using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) { processor.LoadDocument(path); PdfWord currentWord = processor.NextWord(); while (currentWord != null) { for (int i = 0; i < currentWord.Rectangles.Count; i++) { //Retrieve the rectangle encompassing the word var wordRectangle = currentWord.Rectangles[i]; //Add the segment's content and its coordinates to the list WordCoordinates.Add(new Tuple <string, PdfOrientedRectangle>(currentWord.Segments[i].Text, wordRectangle)); } //Switch to the next word currentWord = processor.NextWord(); } } Console.WriteLine(); } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Dispose() { if (processor != null) { processor = null; } }
protected override void EndProcessing() { var book = new SCBookContext(); if (!string.IsNullOrWhiteSpace(FileName)) { var fileName = Project.Current.MapPath(FileName); var ext = Path.GetExtension(fileName)?.ToLower(); if (string.Compare(ext, ".pdf", true) == 0) //When loading PDF - extract text. { string documentText; using (var documentProcessor = new PdfDocumentProcessor()) { ExecuteLocked(() => documentProcessor.LoadDocument(fileName), LockFiles ? LockObject : null); documentText = documentProcessor.Text; } book.Document.AppendText(documentText); } else { ExecuteLocked(() => book.Document.LoadDocument(fileName), LockFiles ? LockObject : null); } } WriteObject(book); }
private static void EditAnnotations(PdfDocumentProcessor processor) { //Retrieve annotations made by the specified author: var textMarkups = processor.GetMarkupAnnotationData(1).Where(annotation => annotation.Author.Contains("Cardle Anita L")); foreach (PdfMarkupAnnotationData markup in textMarkups) { //Get all text markup annotations from the retrieved list: PdfTextMarkupAnnotationData pdfTextMarkup = markup.AsTextMarkupAnnotation(); if (pdfTextMarkup != null) { //Change the annotation's markup type: pdfTextMarkup.MarkupType = PdfTextMarkupAnnotationType.Squiggly; } } var annotations = processor.GetMarkupAnnotationData(1); foreach (PdfMarkupAnnotationData annotation in annotations) { //Get all text annotations: PdfTextAnnotationData textAnnotation = annotation.AsTextAnnotation(); if (textAnnotation != null) { //Change the annotation icon: textAnnotation.IconName = PdfTextAnnotationIconName.Note; } } annotations[0].AddReview("Borman Aaron Lewis", PdfAnnotationReviewStatus.Completed); }
static void Main(string[] args) { // Create a PDF document processor. using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor()) { // Load a PDF document. documentProcessor.LoadDocument(@"..\..\Demo.pdf"); // Load a certificate from a file. X509Certificate2 cert = new X509Certificate2(@"..\..\SignDemo.pfx", "dxdemo"); // Create a PDF signature and specify signing location, contact info and reason. PdfSignature signature = new PdfSignature(cert) { Location = "Location", ContactInfo = "ContactInfo", Reason = "Reason" }; // Save the signed document. documentProcessor.SaveDocument(@"..\..\SignedDocument.pdf", new PdfSaveOptions() { Signature = signature }); } }
//, DrawText waterMark, DrawText numberDowload, QR qr public void AddGraphicJoin(PdfDocumentProcessor processor, Object data, EPDFFile pdfFile) { IList <PdfPage> Pages = processor.Document.Pages; for (int i = 0; i < Pages.Count; i++) { PdfPage Page = Pages[i]; using (PdfGraphics graphics = processor.CreateGraphics()) { SizeF actualPageSize = PrepareGraphics.PrepareGraphicsSizeF(Page, graphics, DrawIngDpi, DrawIngDpi); switch (pdfFile) { case EPDFFile.SolicitudLinea4: SolicitudCreditoL4 SolicitudL4 = (SolicitudCreditoL4)data; SolicitudCreditoContent.NPageContent(graphics, i, actualPageSize.Width, actualPageSize.Height, SolicitudL4); break; case EPDFFile.Presupuesto: PresupuestoInfonavit Presupuesto = (PresupuestoInfonavit)data; PresupuestoInfonavitContent.NPageContent(graphics, i, actualPageSize.Width, actualPageSize.Height, Presupuesto); break; case EPDFFile.PresupuestoDesglose: PresupuestoDInfonavit PresupuestoDesglose = (PresupuestoDInfonavit)data; PresupuestoDInfonavitContent.NPageContent(graphics, i, actualPageSize.Width, actualPageSize.Height, PresupuestoDesglose); break; } graphics.AddToPageForeground(Page, DrawIngDpi, DrawIngDpi); } } }
static void Main(string[] args) { using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) { // Load a document with an interactive form. processor.LoadDocument("..\\..\\Document.pdf"); // Flatten a form field by its name if (processor.FlattenFormField("Nationality")) { // Save a document with the flattened form field. processor.SaveDocument("..\\..\\Result1.pdf"); } // Show a message if the form field was not found in a document. else { Console.WriteLine("A document does not contain a form field with the specified name to be flattened."); } // Flatten a whole interactive form. if (processor.FlattenForm()) { // Save a document with the flattened form. processor.SaveDocument("..\\..\\Result2.pdf"); } // Show a message if the interactive was not found in a document. else { Console.WriteLine("A document does not contain an interactive form to be flattened."); } } }
public ActionResult PdfViewer(string filename) { MemoryStream stream = null;// if (!string.IsNullOrEmpty(filename)) { stream = GetStream(filename); } else if (Session[SESSION_KEY] != null) { stream = new MemoryStream((byte[])Session[SESSION_KEY]); } List <PdfPageViewModel> model = new List <PdfPageViewModel>(); if (stream != null) { PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor(); documentProcessor.LoadDocument(stream); for (int pageNumber = 1; pageNumber < documentProcessor.Document.Pages.Count; pageNumber++) { model.Add(new PdfPageViewModel(documentProcessor) { PageNumber = pageNumber }); } } return(PartialView("_DocumentViewPartial", model)); }
public void DrawImage(Bitmap image, string noi_luu) { using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor()) { documentProcessor.LoadDocument(fileName); DevExpress.Pdf.PdfPage page = documentProcessor.Document.Pages[pdfViewer1.CurrentPageNumber - 1]; using (PdfGraphics graphics = documentProcessor.CreateGraphics()) { float width = (float)Math.Abs(startPosition.Point.X - endPosition.Point.X); float height = (float)Math.Abs(startPosition.Point.Y - endPosition.Point.Y); PdfRectangle cropbox = page.CropBox; // MessageBox.Show(cropbox.Height.ToString()); float Y = (float)(cropbox.Height - startPosition.Point.Y); RectangleF rec = new RectangleF((float)startPosition.Point.X, Y, width, height); // RectangleF test = new RectangleF(10, 30, width, height); graphics.DrawImage(image, rec); graphics.AddToPageForeground(page, 72, 72); } documentProcessor.SaveDocument(noi_luu); LoadPDFFile(noi_luu); } }
static void Main(string[] args) { // Create a PDF Document Processor instance and load a PDF into it. using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor()) { documentProcessor.LoadDocument(@"..\..\Demo.pdf"); // Declare the PDF printer settings. PdfPrinterSettings settings = new PdfPrinterSettings(); // Specify the page numbers to be printed. settings.PageNumbers = new int[] { 1, 2, 3, 4, 5, 6 }; // Handle the PrintPage event to specify print output. documentProcessor.PrintPage += OnPrintPage; // Handle the QueryPageSettings event to customize settings for a page to be printed. documentProcessor.QueryPageSettings += OnQueryPageSettings; // Print the document using the specified printer settings. documentProcessor.Print(settings); // Unsubscribe from PrintPage and QueryPageSettings events. documentProcessor.PrintPage -= OnPrintPage; documentProcessor.QueryPageSettings -= OnQueryPageSettings; } }
static void Main(string[] args) { using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) { // Load a document with an interactive form. processor.LoadDocument("..\\..\\InteractiveForm.pdf"); // Remove a form field by its name. if (processor.RemoveFormField("FirstName")) { // Save the modified document. processor.SaveDocument("..\\..\\Result1.pdf"); } else { // Show a message if the form field was not found in a document. Console.WriteLine("The form field was not removed from a document. Make sure, the form field exists in the document."); } // Remove the whole interactive form. if (processor.RemoveForm()) { // Save the modified document. processor.SaveDocument("..\\..\\Result2.pdf"); } else { // Show a message if the interactive form was not found in a document. Console.WriteLine("The interactive form was not removed from a document. Make sure the interactive form exists in the document."); } } }
private byte[] GetImage(ParsingRequest request, PdfDocumentProcessor documentProcessor, int i) { using (var memory = new MemoryStream()) { documentProcessor.CreateTiff(memory, 1024 * 5, new[] { i }); using (var image = Image.FromStream(memory)) { #if DEBUG image.Save($"{request.File.Name}.jpeg", ImageFormat.Jpeg); #endif if (request.BwThreshold == null) { return(memory.ToArray()); } using (var bwImage = image.GetBlackAndWhiteImage(request.BwThreshold.Value)) { #if DEBUG bwImage.Save($"{request.File.Name}_BW.jpeg", ImageFormat.Jpeg); #endif using (var bwStream = new MemoryStream()) { bwImage.Save(bwStream, ImageFormat.Tiff); return(bwStream.ToArray()); } } } } }
private static void CreateAnnotations(PdfDocumentProcessor processor) { //Add a text markup annotation at the first page: PdfDocumentPosition startPosition = new PdfDocumentPosition(1, new PdfPoint(113, 224)); PdfDocumentPosition endPosition = new PdfDocumentPosition(1, new PdfPoint(272, 207)); PdfTextMarkupAnnotationData textMarkupAnnotation = processor.AddTextMarkupAnnotation(startPosition, endPosition, PdfTextMarkupAnnotationType.Highlight); if (textMarkupAnnotation != null) { //Specify the annotation properties: textMarkupAnnotation.Author = "Bill Smith"; textMarkupAnnotation.Subject = "Important!"; textMarkupAnnotation.Contents = "Please, fact-check this diagram"; textMarkupAnnotation.Color = new PdfRGBColor(0.10, 0.85, 1.00); AddAnnotationComments(textMarkupAnnotation); } //Add a sticky note at the first page: PdfTextAnnotationData textAnnotation = processor.AddTextAnnotation(1, new PdfPoint(64, 65)); //Specify the annotation parameters: textAnnotation.Author = "Nancy Davolio"; textAnnotation.Color = new PdfRGBColor(0.8, 0.2, 0.1); textAnnotation.Contents = "Please proofread this document"; textAnnotation.IconName = PdfTextAnnotationIconName.Check; AddAnnotationComments(textAnnotation); }
static void AddWatermark(PdfDocumentProcessor processor, string watermark) { var pages = processor.Document.Pages; for (int i = 0; i < pages.Count; i++) { using (var graphics = processor.CreateGraphics()) { using (Font font = new Font("Segoe UI", 48, FontStyle.Regular)) { RectangleF pageLayout = new RectangleF( -(float)pages[i].CropBox.Width * 0.35f, (float)pages[i].CropBox.Height * 0.1f, (float)pages[i].CropBox.Width * 1.25f, (float)pages[i].CropBox.Height); // Transformation var angle = Math.Asin((double)pageLayout.Width / (double)pageLayout.Height) * 180.0 / Math.PI; graphics.TranslateTransform(-pageLayout.X, -pageLayout.Y); graphics.RotateTransform((float)angle); using (SolidBrush textBrush = new SolidBrush(Color.FromArgb(100, Color.Red))) graphics.DrawString(watermark, font, textBrush, new PointF(50, 50)); } graphics.AddToPageForeground(pages[i]); } } }
static void Main(string[] args) { PdfDocumentProcessor processor = new PdfDocumentProcessor(); processor.LoadDocument(@"..\\..\\Demo.pdf"); int xCount = 8; int yCount = 2; double cardWidth = 150.5; // Measured in points (equals 2.09 inches). double cardHeight = 442; // Measured in points (equals 6.138 inches). double xMargin = 122; // Measured in points (equals 1.694 inches). double yMargin = 77; // Measured in points (equals 1.069 inches). double yCoord = yMargin; for (int y = 0; y < yCount; y++, yCoord += cardHeight) { double xCoord = xMargin; for (int x = 0; x < xCount; x++, xCoord += cardWidth) { PdfDocumentArea area = new PdfDocumentArea(1, new PdfRectangle(xCoord, yCoord, xCoord + cardWidth, yCoord + cardHeight)); IList <Bitmap> bitmaps = processor.GetImages(area); if (bitmaps.Count != 0) { bitmaps[0].Save(String.Format(@"{0}_{1}.bmp", x, y)); bitmaps[0].Dispose(); } Console.WriteLine(bitmaps.Count.ToString()); } } }
static void Main(string[] args) { using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor()) { documentProcessor.LoadDocument(@"..\..\Document.pdf"); X509Certificate2 certificate = new X509Certificate2(@"..\..\SignDemo.pfx", "dxdemo"); byte[] imageData = File.ReadAllBytes("..\\..\\image.emf"); int pageNumber = 1; int angleInDegrees = 45; double angleInRadians = angleInDegrees * (Math.PI / 180); PdfOrientedRectangle signatureBounds = new PdfOrientedRectangle(new PdfPoint(620, 210), 250, 90, angleInRadians); PdfSignature signature = new PdfSignature(certificate, imageData, pageNumber, signatureBounds); signature.Location = "USA"; signature.ContactInfo = "*****@*****.**"; signature.Reason = "Approved"; documentProcessor.SaveDocument(@"..\..\SignedDocument.pdf", new PdfSaveOptions() { Signature = signature }); } }
public static Bitmap GenerateImageFromPDF(string fileName, int largestEdgeLength) { using (PdfDocumentProcessor pdfDocumentAPI = new PdfDocumentProcessor()) { pdfDocumentAPI.LoadDocument(fileName); return(pdfDocumentAPI.CreateBitmap(1, largestEdgeLength)); } }
private static void addPage(PdfDocumentProcessor processor, int newPage) { for (int i = 1; i < newPage; i++) { PdfGraphics graph = processor.CreateGraphics(); processor.RenderNewPage(PdfPaperSize.Legal, graph); } }
static void Main(string[] args) { using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) { processor.LoadDocument("..\\..\\RotatedDocument.pdf"); using (SolidBrush textBrush = new SolidBrush(Color.FromArgb(100, Color.Blue))) AddGraphics(processor, "text", textBrush); processor.SaveDocument("..\\..\\RotatedDocumentWithGraphics.pdf"); } }
private static void DeleteAnnotations(PdfDocumentProcessor processor) { for (int i = 0; i <= processor.Document.Pages.Count; i++) { //Borman Aaron Lewis's markup annotations from a page. processor.DeleteMarkupAnnotations(processor.GetMarkupAnnotationData(i) .Where(annotation => annotation.Author.Contains("Borman Aaron Lewis"))); } }
static void Main(string[] args) { PdfDocumentProcessor processor = new PdfDocumentProcessor(); processor.LoadDocument("test.pdf"); FindWord("glad to go back home to my mother; give me my wages.\" The master answered, \"You have served me faithfully and honestly;", processor, new SolidBrush(Color.FromArgb(100, 255, 255, 0))); FindWord("seven", processor, new SolidBrush(Color.FromArgb(100, 255, 255, 0))); }
static void Main(string[] args) { using (PdfDocumentProcessor pdfProcessor = new PdfDocumentProcessor()) { pdfProcessor.LoadDocument("PageDeletion.pdf"); ModifyCustomProperties(pdfProcessor.Document); pdfProcessor.SaveDocument("Result.pdf"); Process.Start("Result.pdf"); } }
static void Main(string[] args) { using (PdfDocumentProcessor source = new PdfDocumentProcessor()) { source.LoadDocument("..\\..\\Document.pdf"); using (PdfDocumentProcessor target = new PdfDocumentProcessor()) { target.CreateEmptyDocument("..\\..\\ExtractedFirstPage.pdf"); target.Document.Pages.Add(source.Document.Pages[0]); } } }
static void Main(string[] args) { using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) { // Load a PDF document with AcroForm data. processor.LoadDocument("..\\..\\InteractiveForm.pdf"); // Export AcroForm data to XML format. processor.Export("..\\..\\InteractiveForm.xml", PdfFormDataFormat.Xml); } }
public ActionResult ExecutiveSummary(string[] ExSumParams) { string filename = string.Empty; int pageNumber = 3; if (ExSumParams != null && ExSumParams.Count() > 0) { filename = ExSumParams[0]; pageNumber = int.Parse(ExSumParams[1]); } MemoryStream stream = null;// if (!string.IsNullOrEmpty(filename)) { stream = GetStream(filename); } else if (Session[SESSION_KEY] != null) { stream = new MemoryStream((byte[])Session[SESSION_KEY]); } List<PdfPageViewModel> model = new List<PdfPageViewModel>(); if (stream != null) { PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor(); documentProcessor.LoadDocument(stream); model.Add(new PdfPageViewModel(documentProcessor) { PageNumber = pageNumber }); } return PartialView("_DocumentViewPartial", model); }
public PdfPageViewModel(PdfDocumentProcessor documentProcessor) { this._documentProcessor = documentProcessor; }
public ActionResult PdfViewer(string filename) { MemoryStream stream = null;// if (!string.IsNullOrEmpty(filename)) { stream = GetStream(filename); } else if (Session[SESSION_KEY] != null) { stream = new MemoryStream((byte[])Session[SESSION_KEY]); } List<PdfPageViewModel> model = new List<PdfPageViewModel>(); if (stream != null) { PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor(); documentProcessor.LoadDocument(stream); for (int pageNumber = 1; pageNumber < documentProcessor.Document.Pages.Count; pageNumber++) { model.Add(new PdfPageViewModel(documentProcessor) { PageNumber = pageNumber }); } } return PartialView("_DocumentViewPartial", model); }