Exemplo n.º 1
0
        public static void Run()
        {
            // ExStart:CustomPropertiesUsingMeta
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create instance of PdfFileInfo object
            Aspose.Pdf.Facades.PdfFileInfo fInfo = new Aspose.Pdf.Facades.PdfFileInfo(dataDir + "inFile1.pdf");

            // Retrieve all existing custom attributes
            System.Collections.Hashtable hTable = new Hashtable(fInfo.Header);

            IDictionaryEnumerator enumerator = hTable.GetEnumerator();

            while (enumerator.MoveNext())
            {
                string output = enumerator.Key.ToString() + " " + enumerator.Value;
            }

            // Set new customer attribute as meta info
            fInfo.SetMetaInfo("CustomAttribute", "test value");

            // Get custom attribute from meta info by specifying attribute/property name
            string value = fInfo.GetMetaInfo("CustomAttribute");
            // ExEnd:CustomPropertiesUsingMeta
        }
Exemplo n.º 2
0
        public static void Run()
        {
            // ExStart:PageRotation
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create PdfPageEditor object
            PdfPageEditor pEdit = new PdfPageEditor();

            // Rotate odd pages at 180 degrees
            pEdit.BindPdf(dataDir + "inFile1.pdf");
            pEdit.ProcessPages = new int[] { 1 };
            pEdit.Rotation     = 180;
            pEdit.Save(dataDir + "Aspose.Pdf.Facades_rotate_180_out.pdf");

            // Rotate even pages at 270 degrees
            pEdit.BindPdf(dataDir + "inFile2.pdf");
            pEdit.ProcessPages = new int[] { 1 };
            pEdit.Rotation     = 270;
            pEdit.Save(dataDir + "Aspose.Pdf.Facades_rotate_270_out.pdf");

            // Find at what degrees a page was rotated
            pEdit.BindPdf(dataDir + "inFile.pdf");
            int degrees = pEdit.GetPageRotation(1);

            pEdit = null;
            // ExEnd:PageRotation
        }
        public static void Run()
        {
            // ExStart:DifferenceBetweenFile
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // First a input pdf file should be assigned
            Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form(dataDir + "FilledForm.pdf");
            // Get all field names
            String[] allfields = form.FieldNames;
            // Create an array which will hold the location coordinates of Form fields
            System.Drawing.Rectangle[] box = new System.Drawing.Rectangle[allfields.Length];
            for (int i = 0; i < allfields.Length; i++)
            {
                // Get the appearance attributes of each field, consequtively
                FormFieldFacade facade = form.GetFieldFacade(allfields[i]);
                // Box in FormFieldFacade class holds field's location.
                box[i] = facade.Box;
            }
            form.Save(dataDir + "DifferenceBetweenFile_out.pdf");

            Document document = new Document(dataDir + "FilledForm - 2.pdf");
            // Now we need to add a textfield just upon the original one
            FormEditor editor = new FormEditor(document);

            for (int i = 0; i < allfields.Length; i++)
            {
                // Add text field beneath every existing form field
                editor.AddField(FieldType.Text, "TextField" + i, allfields[i], 1, box[i].Left, box[i].Top, box[i].Left + 50, box[i].Top + 10);
            }
            // Close the document
            editor.Save(dataDir + "DifferenceBetweenFile_out.pdf");
            // ExEnd:DifferenceBetweenFile
        }
        public static void AddSignatureFields()
        {
            // ExStart:AddSignatureFields
            // The path to the documents directory.
            string   dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();
            Document doc     = new Document(dataDir + "inFile.pdf");
            // Create FormEditor object
            FormEditor editor = new FormEditor(doc);

            // Add signature fields
            editor.AddField(FieldType.Signature, "Signature from Alice", 1, 10, 10, 110, 110);
            editor.AddField(FieldType.Signature, "Signature from John", 1, 120, 150, 220, 250);
            editor.AddField(FieldType.Signature, "Signature from Smith", 1, 300, 200, 400, 300);
            // Save the form
            editor.Save(dataDir + "AddSignatureFields_1_out.pdf");

            Document doc2 = new Document(dataDir + "inFile2.pdf");
            // Add signature to any of the signature fields
            PdfFileSignature pdfSign = new PdfFileSignature(doc2);

            pdfSign.Sign("Signature from John", "Signature Reason", "John", "Kharkov", new PKCS1("inFile1.pdf", "password"));
            // Each time new signature is added you must save the document
            pdfSign.Save(dataDir + "AddSignatureFields_2_out.pdf");

            Document doc3 = new Document(dataDir + "FilledForm.pdf");
            // Add second signature
            PdfFileSignature pdfSign2 = new PdfFileSignature(doc3);

            pdfSign2.Sign("Signature from Alice", "Signature Reason", "Alice", "Odessa", new PKCS1(dataDir + "FilledForm - 2.pfx", "password"));
            // Each time new signature is added you must save the document
            pdfSign2.Save(dataDir + "AddSignatureFields_3_out.pdf");
            // ExEnd:AddSignatureFields
        }
Exemplo n.º 5
0
        public static void Run()
        {
            // ExStart:ChangePageSizes
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create PdfPageEditor object
            PdfPageEditor pEdit = new PdfPageEditor();

            // Bind pdf file
            pEdit.BindPdf(dataDir + "FilledForm.pdf");

            // Change page size of the selected pages
            pEdit.ProcessPages = new int[] { 1 };

            // Here we select a member named 'LETTER' from the list of members of PageSize class and assign it to PageSize property of the PdfPageEditor class
            pEdit.PageSize = PageSize.PageLetter;

            // Save the file
            pEdit.Save(dataDir + "ChangePageSizes_out_.pdf");

            // Find at what size a page has been assigned
            pEdit.BindPdf(dataDir + "FilledForm.pdf");
            PageSize size = pEdit.GetPageSize(1);

            pEdit = null;
            // ExEnd:ChangePageSizes
        }
        public static void Run()
        {
            // ExStart:PdfContainsTextOrImages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Instantiate a memoryStream object to hold the extracted text from Document
            MemoryStream ms = new MemoryStream();
            // Instantiate PdfExtractor object
            PdfExtractor extractor = new PdfExtractor();

            // Bind the input PDF document to extractor
            extractor.BindPdf(dataDir + "FilledForm.pdf");
            // Extract text from the input PDF document
            extractor.ExtractText();

            bool containsText  = false;
            bool containsImage = false;

            // Save the extracted text to a text file
            extractor.GetText(ms);
            // Check if the MemoryStream length is greater than or equal to 1
            if (ms.Length >= 1)
            {
                containsText = true;
            }

            // Extract images from the input PDF document
            extractor.ExtractImage();

            // Calling HasNextImage method in while loop. When images will finish, loop will exit
            if (extractor.HasNextImage())
            {
                containsImage = true;
            }

            // Now find out whether this PDF is text only or image only
            if (containsText == true && containsImage == false)
            {
                Console.WriteLine("PDF contains text only");
            }
            else if (containsText == false && containsImage == true)
            {
                Console.WriteLine("PDF contains image only");
            }
            else if (containsText == true && containsImage == true)
            {
                Console.WriteLine("PDF contains both text and image");
            }
            else if (containsText == false && containsImage == false)
            {
                Console.WriteLine("PDF contains neither text or nor image");
            }
            // ExEnd:PdfContainsTextOrImages
        }
        public static void Run()
        {
            // ExStart:FormEditorFeatures
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            Document doc = new Document(dataDir + "inFile.pdf");
            // Create instance of FormEditor
            FormEditor editor = new FormEditor(doc);

            // Add field in the PDF file
            editor.AddField(FieldType.Text, "field1", 1, 300, 500, 350, 525);

            // Add List field in PDF file
            editor.AddField(FieldType.ListBox, "field2", 1, 300, 200, 350, 225);

            // Add list items
            editor.AddListItem("field2", "item 1");
            editor.AddListItem("field2", "item 2");

            // Add submit button
            editor.AddSubmitBtn("submitbutton", 1, "Submit Form", "http:// Testwebsite.com/testpage", 200, 200, 250, 225);

            // Delete list item
            editor.DelListItem("field2", "item 1");

            // Move field to new position
            editor.MoveField("field1", 10, 10, 50, 50);

            // Remove existing field from the PDF
            editor.RemoveField("field1");

            // Rename an existing field
            editor.RenameField("field1", "newfieldname");

            // Reset all visual attributes to empty value
            editor.ResetFacade();

            // Set the alignment style of a text field
            editor.SetFieldAlignment("field1", FormFieldFacade.AlignLeft);

            // Set appearance of the field
            editor.SetFieldAppearance("field1", AnnotationFlags.NoRotate);

            // Set field attributes i.e. ReadOnly, Required
            editor.SetFieldAttribute("field1", PropertyFlag.ReadOnly);

            // Set field limit
            editor.SetFieldLimit("field1", 25);

            // Save modifications in the output file
            editor.Save(dataDir + "FormEditorFeatures2_out.pdf");
            // ExEnd:FormEditorFeatures
        }
Exemplo n.º 8
0
        public static void InsertBlankPage()
        {
            // ExStart:InsertBlankPage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Insert a blank page at the begining of concatenated file to display Table of Contents
            Aspose.Pdf.Document concatenated_pdfDocument = new Aspose.Pdf.Document(new FileStream(dataDir + "Concatenated_Table_Of_Contents.pdf", FileMode.Open));
            // Insert a empty page in a PDF
            concatenated_pdfDocument.Pages.Insert(1);
            // ExEnd:InsertBlankPage
        }
Exemplo n.º 9
0
        public static void Run()
        {
            // ExStart:ConcatenatePdfFilesAndCreateTOC
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create PdfFileEditor object
            PdfFileEditor pdfEditor = new PdfFileEditor();

            // Save concatenated output file
            pdfEditor.Concatenate(new FileStream(dataDir + "input1.pdf", FileMode.Open), new FileStream(dataDir + "input2.pdf", FileMode.Open), new FileStream(dataDir + "ConcatenatePdfFilesAndCreateTOC_out_.pdf", FileMode.Create));
            // ExEnd:ConcatenatePdfFilesAndCreateTOC
        }
Exemplo n.º 10
0
        public static void Run()
        {
            // ExStart:XMLToPdf
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            Stream src  = new FileStream(dataDir + "log.xml", FileMode.Open, FileAccess.Read);
            Stream dest = new FileStream(dataDir + "XMLToPdf_out.pdf", FileMode.Create, FileAccess.ReadWrite);

            FormDataConverter.ConvertXmlToFdf(src, dest);
            dest.Close();
            src.Close();
            // ExEnd:XMLToPdf
        }
Exemplo n.º 11
0
        public static void Run()
        {
            // ExStart:RotatingStamp
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Set path of the image to be set as watermark
            string imageFile = dataDir + "aspose-logo.jpg";

            // Set input file path
            string inFile = dataDir + "inFile.pdf";

            // Set output file path
            string outFile = dataDir + "RotatingStamp_out.pdf";

            // Create PdfFileInfo object to get height and width of the pages
            PdfFileInfo fileInfo = new PdfFileInfo(inFile);

            // Create Stamp object
            Aspose.Pdf.Facades.Stamp aStamp = new Aspose.Pdf.Facades.Stamp();

            // Bind image file with the Stamp object
            aStamp.BindImage(imageFile);

            // Specify whether the stamp will be added as a background or not
            aStamp.IsBackground = false;

            // Specifies at which pages to add the watermark
            aStamp.Pages = new int[] { 1 };

            // Specifies the watermark rotation - rotate at 90 degrees the stamp is rotated about the center point of the stamp object
            aStamp.Rotation = 90;

            // Specifies the position of stamp - lower left corner of the stamp
            aStamp.SetOrigin(fileInfo.GetPageWidth(1) / 2, fileInfo.GetPageHeight(1) / 2);

            // Set the size of the watermark
            aStamp.SetImageSize(100, 100);

            Document doc = new Document(inFile);
            // Create PdfFileStamp class to bind input and output files
            PdfFileStamp stamper = new PdfFileStamp(doc);

            // Add the stamp in the PDF file
            stamper.AddStamp(aStamp);

            // Close the PdfFileStamp object
            stamper.Close();
            // ExEnd:RotatingStamp
        }
        public static void Run()
        {
            // ExStart:ConvertPdfToXML
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create a file stream for FDF file - input file
            System.IO.FileStream fdfInputStream = new FileStream(dataDir + "inFile.pdf", FileMode.Open);
            // Create a file stream for XML file - output file
            System.IO.FileStream xmlOutputStream = new FileStream(dataDir + "ConvertPdfToXML_out.xml", FileMode.Create);
            // Create a file stream for XML file - output file
            FormDataConverter.ConvertFdfToXml(fdfInputStream, xmlOutputStream);
            // ExEnd:ConvertPdfToXML
        }
        public static void Run()
        {
            // ExStart:ConcatenateMultiplePDFUsingMemoryStream
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create two file streams to read pdf files
            FileStream fs1 = new FileStream(dataDir + "inFile.pdf", FileMode.Open, FileAccess.Read);
            FileStream fs2 = new FileStream(dataDir + "inFile2.pdf", FileMode.Open, FileAccess.Read);

            // Create byte arrays to keep the contents of PDF files
            byte[] buffer1 = new byte[Convert.ToInt32(fs1.Length)];
            byte[] buffer2 = new byte[Convert.ToInt32(fs2.Length)];


            int i = 0;

            // Read PDF file contents into byte arrays
            i = fs1.Read(buffer1, 0, Convert.ToInt32(fs1.Length));
            i = fs2.Read(buffer2, 0, Convert.ToInt32(fs2.Length));

            // Now, first convert byte arrays into MemoryStreams and then concatenate those streams
            using (MemoryStream pdfStream = new MemoryStream())
            {
                using (MemoryStream fileStream1 = new MemoryStream(buffer1))
                {
                    using (MemoryStream fileStream2 = new MemoryStream(buffer2))
                    {
                        // Create instance of PdfFileEditor class to concatenate streams
                        PdfFileEditor pdfEditor = new PdfFileEditor();
                        // Concatenate both input MemoryStreams and save to putput MemoryStream
                        pdfEditor.Concatenate(fileStream1, fileStream2, pdfStream);
                        // Convert MemoryStream back to byte array
                        byte[] data = pdfStream.ToArray();
                        // Create a FileStream to save the output PDF file
                        FileStream output = new FileStream(dataDir + "merged_out_.pdf", FileMode.Create,
                                                           FileAccess.Write);
                        // Write byte array contents in the output file stream
                        output.Write(data, 0, data.Length);
                        // Close output file
                        output.Close();
                    }
                }
            }
            // Close input files
            fs1.Close();
            fs2.Close();
            // ExEnd:ConcatenateMultiplePDFUsingMemoryStream
        }
Exemplo n.º 14
0
        public static void CreateLocalLinks()
        {
            // ExStart:CreateLocalLinks
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Now we need to add Heading for Table Of Contents and links for documents
            PdfContentEditor contentEditor = new PdfContentEditor();

            // Bind the PDF file in which we added the blank page
            contentEditor.BindPdf(new FileStream(dataDir + "Concatenated_Table_Of_Contents.pdf", FileMode.Open));
            // Create link for first document
            contentEditor.CreateLocalLink(new System.Drawing.Rectangle(150, 650, 100, 20), 2, 1, System.Drawing.Color.Transparent);
            // ExEnd:CreateLocalLinks
        }
Exemplo n.º 15
0
        public static void AddTextStamps()
        {
            // ExStart:AddTextStamps
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Set Text Stamp to display string Table Of Contents
            Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
            stamp.BindLogo(new FormattedText("Table Of Contents", System.Drawing.Color.Maroon, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 18));
            // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp
            stamp.SetOrigin((new PdfFileInfo(new FileStream(dataDir + "input1.pdf", FileMode.Open)).GetPageWidth(1) / 3), 700);
            // Set particular pages
            stamp.Pages = new int[] { 1 };
            // ExEnd:AddTextStamps
        }
Exemplo n.º 16
0
        public static void Run()
        {
            // ExStart:EditPdfPages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create a new instance of PdfPageEditor class
            Aspose.Pdf.Facades.PdfPageEditor pEditor = new Aspose.Pdf.Facades.PdfPageEditor();
            // Bind an existing pdf file
            pEditor.BindPdf(dataDir + "FilledForm.pdf");
            // Specify an array of pages which need to be manipulated pages can be multiple, here we have specified only one page
            pEditor.ProcessPages = new int[] { 1 };

            //alignment related code

            // Horizontal alignment
            pEditor.HorizontalAlignment = HorizontalAlignment.Right;

            // Specify transition type for the pages
            pEditor.TransitionType = 2;
            //specify transition duration
            pEditor.TransitionDuration = 5;

            // Display related code

            // Select a page size from the enumeration and assign to property
            pEditor.PageSize = PageSize.PageLedger;
            // Assign page rotation
            pEditor.Rotation = 90;
            // Specify zoom factor for the page
            pEditor.Zoom = 100;
            // Assign display duration for the page
            pEditor.DisplayDuration = 5;

            // Methods provided by the class page rotation specified already can be fetched using this method
            int rotation = pEditor.GetPageRotation(1);
            // Already specified page can be fetched with the help of this method
            PageSize pagesize = pEditor.GetPageSize(1);
            // This method gets the page count
            int totalpages = pEditor.GetPages();

            // This method changes the origin from (0,0) to specified number
            pEditor.MovePosition(100, 100);

            // Finally save the output file
            pEditor.Save(dataDir + "EditPdfPages_out_.pdf");
            // ExEnd:EditPdfPages
        }
        public static void Run()
        {
            // ExStart:PdfAnnotationEditorFeatures
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create an object of PdfAnnotationEditor class
            PdfAnnotationEditor editor = new PdfAnnotationEditor();

            // Bind input PDF file
            editor.BindPdf(dataDir + "inFile.pdf");

            // Create a new object of type Annotation to modify annotation attributes
            Aspose.Pdf.Annotations.FreeTextAnnotation annotation = new Aspose.Pdf.Annotations.FreeTextAnnotation(
                editor.Document.Pages[1],
                new Aspose.Pdf.Rectangle(200, 400, 400, 600),
                new Aspose.Pdf.Annotations.DefaultAppearance("TimesNewRoman", 14, System.Drawing.Color.Orange));

            // Set new annotation attributees
            annotation.Subject = "technical article";

            // Modify annotations in the PDF file
            editor.ModifyAnnotations(1, 5, annotation);

            // Delete all the annotations of type Stamp
            editor.DeleteAnnotation("Stamp");

            // Extract annotations to an array list
            // String[] annType = { "Text" };
            string[]  annotType = { Aspose.Pdf.Annotations.AnnotationType.FreeText.ToString(), Aspose.Pdf.Annotations.AnnotationType.Line.ToString() };
            ArrayList list      = (ArrayList)editor.ExtractAnnotations(1, 5, annotType);

            for (int index = 0; index < list.Count; index++)
            {
                Aspose.Pdf.Annotations.Annotation list_annotation = (Aspose.Pdf.Annotations.Annotation)list[index];
                Console.WriteLine(list_annotation.Contents);
            }

            // Import annotations from another PDF file
            string[] importFrom = new string[1];
            importFrom[0] = dataDir + "inFile2.pdf";
            editor.ImportAnnotations(importFrom);

            // Finally save the output PDF file
            editor.Save(dataDir + "PdfAnnotationEditorFeatures_out.pdf");
            // ExEnd:PdfAnnotationEditorFeatures
        }
Exemplo n.º 18
0
        public static void Run()
        {
            // ExStart:JustifyText
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            using (FileStream source = File.Open(dataDir + "Input1.pdf", FileMode.Open))
            {
                MemoryStream ms = new MemoryStream();

                // Create Form Object
                Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form();

                // Open Source File
                form.BindPdf(source);

                // Fill Text Field
                form.FillField("Text1", "Thank you for using Aspose");

                // Save the document in Memory Stream
                form.Save(ms);

                ms.Seek(0, SeekOrigin.Begin);

                FileStream dest = new FileStream(dataDir + "JustifyText_out.pdf", FileMode.Create);

                // Create formEditor Object
                FormEditor formEditor = new FormEditor();

                // Open PDF from memory stream
                formEditor.BindPdf(ms);

                // Set Text Alignment as Justified
                formEditor.Facade.Alignment = FormFieldFacade.AlignJustified;

                // Decorate form field.
                formEditor.DecorateField();

                // Save te resultant file.
                formEditor.Save(dest);

                // Close file stream
                dest.Close();
            }
            // ExEnd:JustifyText
        }
        public static void VerifySignatures()
        {
            // ExStart:VerifySignatures
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();
            // Create PdfFileSignature object
            PdfFileSignature pdfVerify = new PdfFileSignature();

            // Bind input PDF file
            pdfVerify.BindPdf(dataDir + "inFile.pdf");
            // Check if PDF contains signature
            bool isSigned = pdfVerify.ContainsSignature();
            // All signatures have names Signaure#, this names kit generates automatically
            bool isSignatureVerified = pdfVerify.VerifySignature("Signature1");
            // However we can set necessary name manualy if we use signature fields (see below)
            bool isSignatureVerified2 = pdfVerify.VerifySignature("Signature from Alice");
            // ExEnd:VerifySignatures
        }
        public static void Run()
        {
            // ExStart:ExtensibleMetadataPlatform
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create an object of PdfXmpMetadata class
            Aspose.Pdf.Facades.PdfXmpMetadata xmpMetaData = new Aspose.Pdf.Facades.PdfXmpMetadata();

            // Create input and output file streams
            FileStream input = new FileStream(dataDir + "FilledForm.pdf", FileMode.Open);

            FileStream output = new FileStream(dataDir + "xmp_out_.pdf", FileMode.Create);

            // Set input file stream
            xmpMetaData.BindPdf(input);

            // Add base URL property to xmp metadata
            xmpMetaData.Add(DefaultMetadataProperties.BaseURL, "xmlns:pdf=http://ns.adobe.com/pdf/1.3/");

            // Add creation date property to xmp metadata
            xmpMetaData.Add(DefaultMetadataProperties.CreateDate, System.DateTime.Now.ToString());

            // Add Metadata Date property to xmp metadata
            xmpMetaData.Add(DefaultMetadataProperties.MetadataDate, System.DateTime.Now.ToString());

            // Add Creator Tool property to xmp metadata
            xmpMetaData.Add(DefaultMetadataProperties.CreatorTool, "Creator Tool Name");

            //Add Modify Date to xmp metadata
            xmpMetaData.Add(DefaultMetadataProperties.ModifyDate, System.DateTime.Now.ToString());

            // Add Nick Name to xmp metadata
            xmpMetaData.Add(DefaultMetadataProperties.Nickname, "Test");

            // Save xmp meta data in the pdf file
            xmpMetaData.Save(output);

            // Close input and output file streams
            input.Close();
            output.Close();
            // ExEnd:ExtensibleMetadataPlatform
        }
        public static void Run()
        {
            // ExStart:AddTextImagesUsingPdfFileMend
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Specify input and output PDF file paths
            string inputFile  = dataDir + "inFile.pdf";
            string outputFile = dataDir + "AddTextImagesUsingPdfFileMend_out_.pdf";

            // Specify image file path
            string imageName = dataDir + "aspose-logo.jpg";

            // Create file streams for all of the files to be used in the example
            FileStream inImgStream  = new FileStream(@imageName, FileMode.Open);
            FileStream outputStream = new FileStream(@outputFile, FileMode.Create);

            Document doc = new Document(inputFile);
            // Create instance of PdfFileMend class
            PdfFileMend mendor = new PdfFileMend(doc);

            // Add image to the input PDF file on page number 1 at specified location
            mendor.AddImage(inImgStream, 1, 50, 50, 100, 100);

            // Create new FormattedText type object to add text in the PDF file
            FormattedText ft = new FormattedText(
                "PdfFileMend testing! 0 rotation.",
                System.Drawing.Color.FromArgb(0, 200, 0),
                FontStyle.TimesRoman,
                EncodingType.Winansi,
                false,
                12);

            // Add text in the existing PDF file
            mendor.AddText(ft, 1, 50, 100, 100, 200);

            // Claose the PdfFileMend type object
            mendor.Close();
            // Close output file stream
            outputStream.Close();
            // ExEnd:AddTextImagesUsingPdfFileMend
        }
        public static void Run()
        {
            // ExStart:AnnotationsExport
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create an object of PdfAnnotationEditor class
            PdfAnnotationEditor editor = new PdfAnnotationEditor();

            // Bind input PDF file
            editor.BindPdf(dataDir + "inFile.pdf");
            // Create a file stream for output XFDF file to export annotations
            FileStream fileStream = new FileStream(dataDir + "exportannotations.xfdf", FileMode.Create, FileAccess.Write);

            // Create an enumeration of all the annotation types which you want to export
            string[] annoType = { AnnotationType.Text.ToString() };
            // Export annotations of specified type(s) to XFDF file
            editor.ExportAnnotationsXfdf(fileStream, 1, 5, annoType);
            // ExEnd:AnnotationsExport
        }
        public static void NewApproach()
        {
            // ExStart:NewApproach
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create PdfConverter object and bind input PDF file
            PdfConverter pdfConverter = new PdfConverter();

            pdfConverter.BindPdf(dataDir + "inFile.pdf");
            pdfConverter.DoConvert();

            // Create TiffSettings object and set CompressionType
            TiffSettings tiffSettings = new TiffSettings();

            // Convert to TIFF image
            pdfConverter.SaveAsTIFF(dataDir + "PDFToTIFFConversion_out.tif", 300, 300, tiffSettings, new WinAPIIndexBitmapConverter());
            pdfConverter.Close();
            // ExEnd:NewApproach
        }
        public static void Run()
        {
            // ExStart:PdfExtractorFeatures
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create an instance of PdfExtractor class
            PdfExtractor extractor = new PdfExtractor();

            // Set PDF file password
            extractor.Password = "";
            // Specify start and end pages of the PDF
            extractor.StartPage = 1;
            extractor.EndPage   = 10;

            // Bind PDF file with the extractor object
            extractor.BindPdf(dataDir + "inFile.pdf");
            // Extract all text from the PDF
            extractor.ExtractText();
            // Save extracted text in a text file
            extractor.GetText(dataDir + "PdfExtractorFeatures_text_out_.txt");

            // Text of individual pages can also be saved individually in single text files
            if (extractor.HasNextPageText())
            {
                extractor.GetNextPageText(dataDir + DateTime.Now.Ticks.ToString() + "_out_.txt");
            }

            // Extract images from PDF file
            extractor.ExtractImage();
            // Save each individual image in an image file
            if (extractor.HasNextImage())
            {
                extractor.GetNextImage(dataDir + DateTime.Now.Ticks.ToString() + "_out_.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }

            // Extract attachments
            extractor.ExtractAttachment();
            extractor.GetAttachment(dataDir);
            // ExEnd:PdfExtractorFeatures
        }
        public static void Run()
        {
            // ExStart:PDFToTIFFConversion
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create PdfConverter object and bind input PDF file
            PdfConverter pdfConverter = new PdfConverter();

            pdfConverter.Resolution = new Aspose.Pdf.Devices.Resolution(300);
            pdfConverter.BindPdf(dataDir + "inFile.pdf");
            pdfConverter.DoConvert();
            // Create TiffSettings object and set ColorDepth
            TiffSettings tiffSettings = new TiffSettings();

            tiffSettings.Depth = ColorDepth.Format1bpp;
            // Convert to TIFF image
            pdfConverter.SaveAsTIFF(dataDir + "PDFToTIFFConversion_out.tif", 300, 300, tiffSettings);
            pdfConverter.Close();
            // ExEnd:PDFToTIFFConversion
        }
        public static void Run()
        {
            // ExStart:PDFSigningMechanism
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            Document doc = new Document(dataDir + "inFile.pdf");
            // Create PdfFileSignature object and bind input and output PDF files
            PdfFileSignature pdfSign = new PdfFileSignature(doc);

            // Create a rectangle for signature location
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
            // Set signature appearance
            pdfSign.SignatureAppearance = dataDir + "aspose-logo.jpg";

            // Create any of the three signature types
            PKCS1 signature = new PKCS1(dataDir + "inFile2.pdf", "password");

            pdfSign.Sign(1, "Signature Reason", "Alice", "Odessa", true, rect, signature);
            // ExEnd:PDFSigningMechanism
        }
Exemplo n.º 27
0
        public static void Run()
        {
            // ExStart:AnnotationsImport
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Create an object of PdfAnnotationEditor class
            PdfAnnotationEditor editor = new PdfAnnotationEditor();

            // Bind input PDF file
            editor.BindPdf(dataDir + "inFile.pdf");
            // Create a file stream for input XFDF file to import annotations
            FileStream fileStream = new FileStream(dataDir + "exportannotations.xfdf", FileMode.Open, FileAccess.Read);

            // Create an enumeration of all the annotation types which you want to import
            Enum[] annType = { AnnotationType.Text };
            // Import annotations of specified type(s) from XFDF file
            editor.ImportAnnotationFromXfdf(fileStream, annType);
            // Save output pdf file
            editor.Save(dataDir + "ImportAnnotations_out.pdf");
            // ExEnd:AnnotationsImport
        }
        public static void Run()
        {
            // ExStart:ChangingFieldAppearance
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            Document doc = new Document(dataDir + "FilledForm.pdf");
            // Open the document and create a Form object
            FormEditor formEditor = new FormEditor(doc);

            // Add a text field
            formEditor.AddField(FieldType.Text, "text1", 1, 200, 550, 300, 575);

            // Set field attribute - PropertyFlag enumeration contains 4 options
            formEditor.SetFieldAttribute("text1", PropertyFlag.Required);
            // Set field limit - this field will take maximum 20 characters as input
            formEditor.SetFieldLimit("text1", 20);

            // Close the document
            formEditor.Save(dataDir + "ChangingFieldAppearance_out.pdf");
            // ExEnd:ChangingFieldAppearance
        }
        public static void Run()
        {
            // ExStart:ConcatenatePDFForms
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Set input and output file paths
            string inputFile1 = dataDir + "inFile1.pdf";
            string inputFile2 = dataDir + "inFile2.pdf";
            string outFile    = dataDir + "ConcatenatePDFForms_out.pdf";

            // Instantiate PdfFileEditor Object
            PdfFileEditor fileEditor = new PdfFileEditor();

            // To keep unique field Id for all the fields
            fileEditor.KeepFieldsUnique = true;
            // Format of the suffix which is added to field name to make it unique when forms are concatenated.
            fileEditor.UniqueSuffix = "_%NUM%";

            // Concatenate the files into a resultant Pdf file
            fileEditor.Concatenate(inputFile1, inputFile2, outFile);
            // ExEnd:ConcatenatePDFForms
        }
Exemplo n.º 30
0
        public static void Run()
        {
            // ExStart:ConcatenatingAllPdfFiles
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            // Retrieve names of all the Pdf files in a particular Directory
            string[] fileEntries = Directory.GetFiles(dataDir, "*.pdf");

            // Get the current System date and set its format
            string date = DateTime.Now.ToString("MM-dd-yyyy");
            // Get the current System time and set its format
            string hoursSeconds = DateTime.Now.ToString("hh-mm");
            // Set the value for the final Resultant Pdf document
            string masterFileName = date + "_" + hoursSeconds + "_out_.pdf";

            // Instantiate PdfFileEditor object
            Aspose.Pdf.Facades.PdfFileEditor pdfEditor = new PdfFileEditor();

            //Call Concatenate method of PdfFileEditor object to concatenate all input files
            //into a single output file
            pdfEditor.Concatenate(fileEntries, dataDir + masterFileName);
            // ExEnd:ConcatenatingAllPdfFiles
        }