public static void Run()
        {
            // ExStart:CreatePDFPortfolio
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_TechnicalArticles();

            // Instantiate Document Object
            Document doc = new Document();

            // Instantiate document Collection object
            doc.Collection = new Collection();

            // Get Files to add to Portfolio
            FileSpecification excel = new FileSpecification( dataDir + "HelloWorld.xlsx");
            FileSpecification word = new FileSpecification( dataDir + "HelloWorld.docx");
            FileSpecification image = new FileSpecification(dataDir + "aspose-logo.jpg");

            // Provide description of the files
            excel.Description = "Excel File";
            word.Description = "Word File";
            image.Description = "Image File";

            // Add files to document collection
            doc.Collection.Add(excel);
            doc.Collection.Add(word);
            doc.Collection.Add(image);

            // Save Portfolio document
            doc.Save(dataDir + "CreatePDFPortfolio_out.pdf");
            // ExEnd:CreatePDFPortfolio                      
        }
Exemplo n.º 2
0
   public FileAttachment(
 Page page,
 RectangleF box,
 string text,
 FileSpecification dataFile
 )
       : base(page, PdfName.FileAttachment, box, text)
   {
       DataFile = dataFile;
   }
Exemplo n.º 3
0
 private void EvaluateDataFile(
     FileSpecification dataFile
     )
 {
     if(dataFile is FullFileSpecification)
       {
     EmbeddedFile embeddedFile = ((FullFileSpecification)dataFile).EmbeddedFile;
     if(embeddedFile != null)
     {ExportAttachment(embeddedFile.Data, dataFile.Path);}
       }
 }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //open document
            Document pdfDocument = new Document(dataDir + "input.pdf");

            //setup new file to be added as attachment
            FileSpecification fileSpecification = new FileSpecification(dataDir + "test.txt", "Sample text file");

            //add attachment to document's attachment collection
            pdfDocument.EmbeddedFiles.Add(fileSpecification);

            //save new output
            pdfDocument.Save(dataDir + "output.pdf");
        }
Exemplo n.º 5
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Attachments();

            //open document
            Document pdfDocument = new Document(dataDir + "AddAttachment.pdf");

            //setup new file to be added as attachment
            FileSpecification fileSpecification = new FileSpecification(dataDir + "test.txt", "Sample text file");

            //add attachment to document's attachment collection
            pdfDocument.EmbeddedFiles.Add(fileSpecification);

            //save new output
            pdfDocument.Save(dataDir + "AddAttachment_out.pdf");

        }
        public static void Run()
        {
            // ExStart:DisableFilesCompression
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Attachments();

            Document pdfDocument = new Document(dataDir + "GetAlltheAttachments.pdf");
            // Setup new file to be added as attachment
            FileSpecification fileSpecification = new FileSpecification("test_out.txt", "Sample text file");
            // Specify Encoding proparty setting it to FileEncoding.None
            fileSpecification.Encoding = FileEncoding.None;
            // Add attachment to document's attachment collection
            pdfDocument.EmbeddedFiles.Add(fileSpecification);
            dataDir = dataDir + "DisableFilesCompression_out.pdf";
            // Save new output
            pdfDocument.Save(dataDir);
            // ExEnd:DisableFilesCompression
            Console.WriteLine("\nFile compression disabled successfully.\nFile saved at " + dataDir);
        }
        public static void Run()
        {
            // ExStart:AddAttachmentToPDFA
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

            // Instantiate Document instance to load existing file
            Aspose.Pdf.Document doc = new Document(dataDir + "input.pdf");
            // Setup new file to be added as attachment
            FileSpecification fileSpecification = new FileSpecification(dataDir + "aspose-logo.jpg", "Large Image file");
            // Add attachment to document's attachment collection
            doc.EmbeddedFiles.Add(fileSpecification);
            // Perform conversion to PDF/A_3a so attachment is included in resultnat file
            doc.Convert(dataDir + "log.txt", Aspose.Pdf.PdfFormat.PDF_A_3A, ConvertErrorAction.Delete);
            // Save resultant file
            doc.Save(dataDir + "AddAttachmentToPDFA_out.pdf");
            // ExEnd:AddAttachmentToPDFA
            Console.WriteLine("\nAttachment added successfully to PDF/A file.\nFile saved at " + dataDir);
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

            Document pdfDocument = new Document(dataDir+ "Input.pdf");
            //Setup new file to be added as attachment
            FileSpecification fileSpecification = new FileSpecification("test.txt", "Sample text file");
            //Specify Encoding proparty setting it to FileEncoding.None
            fileSpecification.Encoding = FileEncoding.None;
            //Add attachment to document's attachment collection
            pdfDocument.EmbeddedFiles.Add(fileSpecification);
            //Save new output
            pdfDocument.Save(dataDir+ "DisableFilesCompression_out.pdf");
 


            
            
        }
        public static void Run()
        {
            // ExStart:AddAttachment
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Attachments();

            // Open document
            Document pdfDocument = new Document(dataDir + "AddAttachment.pdf");

            // Setup new file to be added as attachment
            FileSpecification fileSpecification = new FileSpecification(dataDir + "test.txt", "Sample text file");

            // Add attachment to document's attachment collection
            pdfDocument.EmbeddedFiles.Add(fileSpecification);

            dataDir = dataDir + "AddAttachment_out.pdf";

            // Save new output
            pdfDocument.Save(dataDir);
            // ExEnd:AddAttachment
            Console.WriteLine("\nSample text file attached successfully.\nFile saved at " + dataDir);
        }
Exemplo n.º 10
0
        private void Populate(Document document)
        {
            Page page = new Page(document);

            document.Pages.Add(page);

            PrimitiveComposer   composer = new PrimitiveComposer(page);
            fonts::PdfType1Font font     = fonts::PdfType1Font.Load(document, fonts::PdfType1Font.FamilyEnum.Courier, true, false);

            composer.SetFont(font, 12);

            // Sticky note.
            composer.ShowText("Sticky note annotation:", new SKPoint(35, 35));
            new StickyNote(page, new SKPoint(50, 50), "Text of the Sticky note annotation")
            {
                ImageName = ImageNameEnum.Note,
                Color     = DeviceRGBColor.Get(SKColors.Yellow),
                Popup     = new Popup(
                    page,
                    SKRect.Create(200, 25, 200, 75),
                    "Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)"
                    ),
                Author  = "Stefano",
                Subject = "Sticky note",
                IsOpen  = true
            };
            new StickyNote(page, new SKPoint(80, 50), "Text of the Help sticky note annotation")
            {
                ImageName = ImageNameEnum.Help,
                Color     = DeviceRGBColor.Get(SKColors.Pink),
                Author    = "Stefano",
                Subject   = "Sticky note",
                Popup     = new Popup(
                    page,
                    SKRect.Create(400, 25, 200, 75),
                    "Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)"
                    )
            };
            new StickyNote(page, new SKPoint(110, 50), "Text of the Comment sticky note annotation")
            {
                ImageName = ImageNameEnum.Comment,
                Color     = DeviceRGBColor.Get(SKColors.Green),
                Author    = "Stefano",
                Subject   = "Sticky note"
            };
            new StickyNote(page, new SKPoint(140, 50), "Text of the Key sticky note annotation")
            {
                ImageName = ImageNameEnum.Key,
                Color     = DeviceRGBColor.Get(SKColors.Blue),
                Author    = "Stefano",
                Subject   = "Sticky note"
            };

            // Callout.
            composer.ShowText("Callout note annotation:", new SKPoint(35, 85));
            new FreeText(page, SKRect.Create(250, 90, 150, 70), "Text of the Callout note annotation")
            {
                Line = new FreeText.CalloutLine(
                    page,
                    new SKPoint(100, 100),
                    new SKPoint(150, 125),
                    new SKPoint(250, 125)
                    ),
                Intent       = MarkupIntent.FreeTextCallout,
                LineEndStyle = LineEndStyleEnum.OpenArrow,
                Border       = new Border(1),
                Color        = DeviceRGBColor.Get(SKColors.Yellow)
            };

            // File attachment.
            composer.ShowText("File attachment annotation:", new SKPoint(35, 135));
            new FileAttachment(
                page,
                SKRect.Create(50, 150, 15, 20),
                "Text of the File attachment annotation",
                FileSpecification.Get(
                    EmbeddedFile.Get(document, GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")),
                    "happyGNU.jpg")
                )
            {
                AttachmentName = FileAttachmentImageType.PaperClip,
                Author         = "Stefano",
                Subject        = "File attachment"
            };

            composer.ShowText("Line annotation:", new SKPoint(35, 185));
            {
                composer.BeginLocalState();
                composer.SetFont(font, 10);

                // Arrow line.
                composer.ShowText("Arrow:", new SKPoint(50, 200));
                new Line(
                    page,
                    new SKPoint(50, 260),
                    new SKPoint(200, 210),
                    "Text of the Arrow line annotation",
                    DeviceRGBColor.Get(SKColors.Black))
                {
                    StartStyle     = LineEndStyleEnum.Circle,
                    EndStyle       = LineEndStyleEnum.ClosedArrow,
                    CaptionVisible = true,
                    InteriorColor  = DeviceRGBColor.Get(SKColors.Green),
                    Author         = "Stefano",
                    Subject        = "Arrow line"
                };

                // Dimension line.
                composer.ShowText("Dimension:", new SKPoint(300, 200));
                new Line(
                    page,
                    new SKPoint(300, 220),
                    new SKPoint(500, 220),
                    "Text of the Dimension line annotation",
                    DeviceRGBColor.Get(SKColors.Blue)
                    )
                {
                    LeaderLineLength    = -20,
                    LeaderLineExtension = 10,
                    StartStyle          = LineEndStyleEnum.OpenArrow,
                    EndStyle            = LineEndStyleEnum.OpenArrow,
                    Border         = new Border(1),
                    CaptionVisible = true,
                    Author         = "Stefano",
                    Subject        = "Dimension line"
                };

                composer.End();
            }

            var path = new SKPath();

            path.MoveTo(new SKPoint(50, 320));
            path.LineTo(new SKPoint(70, 305));
            path.LineTo(new SKPoint(110, 335));
            path.LineTo(new SKPoint(130, 320));
            path.LineTo(new SKPoint(110, 305));
            path.LineTo(new SKPoint(70, 335));
            path.LineTo(new SKPoint(50, 320));
            // Scribble.
            composer.ShowText("Scribble annotation:", new SKPoint(35, 285));
            new Scribble(
                page,
                new List <SKPath> {
                path
            },
                "Text of the Scribble annotation",
                DeviceRGBColor.Get(SKColors.Orange))
            {
                Border  = new Border(1, new LineDash(new float[] { 5, 2, 2, 2 })),
                Author  = "Stefano",
                Subject = "Scribble"
            };

            // Rectangle.
            composer.ShowText("Rectangle annotation:", new SKPoint(35, 350));
            new PdfClown.Documents.Interaction.Annotations.Rectangle(
                page,
                SKRect.Create(50, 370, 100, 30),
                "Text of the Rectangle annotation")
            {
                Color   = DeviceRGBColor.Get(SKColors.Red),
                Border  = new Border(1, new LineDash(new float[] { 5 })),
                Author  = "Stefano",
                Subject = "Rectangle",
                Popup   = new Popup(
                    page,
                    SKRect.Create(200, 325, 200, 75),
                    "Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)"
                    )
            };

            // Ellipse.
            composer.ShowText("Ellipse annotation:", new SKPoint(35, 415));
            new Ellipse(
                page,
                SKRect.Create(50, 440, 100, 30),
                "Text of the Ellipse annotation")
            {
                BorderEffect  = new BorderEffect(BorderEffectType.Cloudy, 1),
                InteriorColor = DeviceRGBColor.Get(SKColors.Cyan),
                Color         = DeviceRGBColor.Get(SKColors.Black),
                Author        = "Stefano",
                Subject       = "Ellipse"
            };

            // Rubber stamp.
            composer.ShowText("Rubber stamp annotations:", new SKPoint(35, 505));
            {
                fonts::Font stampFont = fonts::PdfType0Font.Load(document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "TravelingTypewriter.otf"));
                new Stamp(
                    page,
                    new SKPoint(75, 570),
                    "This is a round custom stamp",
                    new StampAppearanceBuilder(document, StampAppearanceBuilder.TypeEnum.Round, "Done", 50, stampFont)
                    .Build()
                    )
                {
                    Rotation = -10,
                    Author   = "Stefano",
                    Subject  = "Custom stamp"
                };

                new Stamp(
                    page,
                    new SKPoint(210, 570),
                    "This is a squared (and round-cornered) custom stamp",
                    new StampAppearanceBuilder(document, StampAppearanceBuilder.TypeEnum.Squared, "Classified", 150, stampFont)
                {
                    Color = DeviceRGBColor.Get(SKColors.Orange)
                }.Build()
                    )
                {
                    Rotation = 15,
                    Author   = "Stefano",
                    Subject  = "Custom stamp"
                };

                fonts::Font stampFont2 = fonts::PdfType0Font.Load(document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "MgOpenCanonicaRegular.ttf"));
                new Stamp(
                    page,
                    new SKPoint(350, 570),
                    "This is a striped custom stamp",
                    new StampAppearanceBuilder(document, StampAppearanceBuilder.TypeEnum.Striped, "Out of stock", 100, stampFont2)
                {
                    Color = DeviceRGBColor.Get(SKColors.Gray)
                }.Build()
                    )
                {
                    Rotation = 90,
                    Author   = "Stefano",
                    Subject  = "Custom stamp"
                };

                // Define the standard stamps template path!

                /*
                 * NOTE: The PDF specification defines several stamps (aka "standard stamps") whose rendering
                 * depends on the support of viewer applications. As such support isn't guaranteed, PDF Clown
                 * offers smooth, ready-to-use embedding of these stamps through the StampPath property of the
                 * document configuration: you can decide to point to the stamps directory of your Acrobat
                 * installation (e.g., in my GNU/Linux system it's located in
                 * "/opt/Adobe/Reader9/Reader/intellinux/plug_ins/Annotations/Stamps/ENU") or to the
                 * collection included in this distribution (std-stamps.pdf).
                 */
                document.Configuration.StampPath = GetResourcePath("../../pkg/templates/std-stamps.pdf");

                // Add a standard stamp, rotating it 15 degrees counterclockwise!
                new Stamp(
                    page,
                    new SKPoint(485, 515),
                    null, // Default size is natural size.
                    "This is 'Confidential', a standard stamp",
                    StandardStampEnum.Confidential)
                {
                    Rotation = 15,
                    Author   = "Stefano",
                    Subject  = "Standard stamp"
                };

                // Add a standard stamp, without rotation!
                new Stamp(
                    page,
                    new SKPoint(485, 580),
                    null, // Default size is natural size.
                    "This is 'SBApproved', a standard stamp",
                    StandardStampEnum.BusinessApproved)
                {
                    Author  = "Stefano",
                    Subject = "Standard stamp"
                };

                // Add a standard stamp, rotating it 10 degrees clockwise!
                new Stamp(
                    page,
                    new SKPoint(485, 635),
                    new SKSize(0, 40), // This scales the width proportionally to the 40-unit height (you can obviously do also the opposite, defining only the width).
                    "This is 'SHSignHere', a standard stamp",
                    StandardStampEnum.SignHere)
                {
                    Rotation = -10,
                    Author   = "Stefano",
                    Subject  = "Standard stamp"
                };
            }

            composer.ShowText("Text markup annotations:", new SKPoint(35, 650));
            {
                composer.BeginLocalState();
                composer.SetFont(font, 8);
                var matrix = page.RotateMatrix;
                new TextMarkup(page,
                               composer.ShowText("Highlight annotation", new SKPoint(35, 680)).Transform(ref matrix),
                               "Text of the Highlight annotation",
                               TextMarkupType.Highlight)
                {
                    Author  = "Stefano",
                    Subject = "An highlight text markup!"
                };

                new TextMarkup(page,
                               composer.ShowText("Highlight annotation 2", new SKPoint(35, 695)).Inflate(0, 1).Transform(ref matrix),
                               "Text of the Highlight annotation 2",
                               TextMarkupType.Highlight)
                {
                    Color = DeviceRGBColor.Get(SKColors.Magenta)
                };

                new TextMarkup(page,
                               composer.ShowText("Highlight annotation 3", new SKPoint(35, 710)).Inflate(0, 2).Transform(ref matrix),
                               "Text of the Highlight annotation 3",
                               TextMarkupType.Highlight)
                {
                    Color = DeviceRGBColor.Get(SKColors.Red)
                };

                new TextMarkup(page,
                               composer.ShowText("Squiggly annotation", new SKPoint(180, 680)).Transform(ref matrix),
                               "Text of the Squiggly annotation",
                               TextMarkupType.Squiggly);

                new TextMarkup(page,
                               composer.ShowText("Squiggly annotation 2", new SKPoint(180, 695)).Inflate(0, 2.5f).Transform(ref matrix),
                               "Text of the Squiggly annotation 2",
                               TextMarkupType.Squiggly)
                {
                    Color = DeviceRGBColor.Get(SKColors.Orange)
                };

                new TextMarkup(page,
                               composer.ShowText("Squiggly annotation 3", new SKPoint(180, 710)).Inflate(0, 3).Transform(ref matrix),
                               "Text of the Squiggly annotation 3",
                               TextMarkupType.Squiggly)
                {
                    Color = DeviceRGBColor.Get(SKColors.Pink)
                };

                new TextMarkup(page,
                               composer.ShowText("Underline annotation", new SKPoint(320, 680)).Transform(ref matrix),
                               "Text of the Underline annotation",
                               TextMarkupType.Underline);
                new TextMarkup(page,
                               composer.ShowText("Underline annotation 2", new SKPoint(320, 695)).Inflate(0, 2.5f).Transform(ref matrix),
                               "Text of the Underline annotation 2",
                               TextMarkupType.Underline)
                {
                    Color = DeviceRGBColor.Get(SKColors.Orange)
                };

                new TextMarkup(page,
                               composer.ShowText("Underline annotation 3", new SKPoint(320, 710)).Inflate(0, 3).Transform(ref matrix),
                               "Text of the Underline annotation 3",
                               TextMarkupType.Underline)
                {
                    Color = DeviceRGBColor.Get(SKColors.Green)
                };

                new TextMarkup(page,
                               composer.ShowText("StrikeOut annotation", new SKPoint(455, 680)).Transform(ref matrix),
                               "Text of the StrikeOut annotation",
                               TextMarkupType.StrikeOut);

                new TextMarkup(page,
                               composer.ShowText("StrikeOut annotation 2", new SKPoint(455, 695)).Inflate(0, 2.5f).Transform(ref matrix),
                               "Text of the StrikeOut annotation 2",
                               TextMarkupType.StrikeOut)
                {
                    Color = DeviceRGBColor.Get(SKColors.Orange)
                };

                new TextMarkup(page,
                               composer.ShowText("StrikeOut annotation 3", new SKPoint(455, 710)).Inflate(0, 3).Transform(ref matrix),
                               "Text of the StrikeOut annotation 3",
                               TextMarkupType.StrikeOut)
                {
                    Color = DeviceRGBColor.Get(SKColors.Green)
                };

                composer.End();
            }
            composer.Flush();
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            using (Library lib = new Library())
            {
                String sFileSpec = Library.ResourceDirectory + "Sample_Input/ducky.pdf";
                String sOutput   = "../RemoteGoToActions-out.pdf";

                if (args.Length > 0)
                {
                    sFileSpec = args[0];
                }

                if (args.Length > 1)
                {
                    sOutput = args[1];
                }

                Console.WriteLine("Writing to output " + sOutput + ". Using " + sFileSpec + " as file specification");

                Document doc = new Document();

                // Standard letter size page (8.5" x 11")
                Rect pageRect = new Rect(0, 0, 612, 792);
                Page docpage  = doc.CreatePage(Document.BeforeFirstPage, pageRect);
                Console.WriteLine("Created page.");

                LinkAnnotation newLink = new LinkAnnotation(docpage, new Rect(153, 198, 306, 396));
                Console.WriteLine("Created new Link Annotation");

                // RemoteGoToActions need a FileSpecification and a RemoteDestination.
                //
                // The FileSpecification specifies which file should be opened when the LinkAnnotation is "clicked"
                //
                // The RemoteDestination specifies a particular view (page number, Fit type, rectangle, and zoom level)
                // to display when the file in the FileSpecification is opened. Remember page numbers start at 0.
                //
                // FileSpecification objects, RemoteDestination objects, and RemoteGoToActions
                // must be associated with a Document. The association happens at object creation time and cannot be changed.
                //
                // FileSpecifications and RemoteDestinations are associated with the Document that is passed in the constructor.
                // RemoteGoToActions are associated with the same Document as the RemoteDestination used to create it.
                //
                // When creating a RemoteGoToAction, make sure that the FileSpecification and RemoteDestination are both
                // associated with the same Document, or an exception will be thrown.

                // FileSpecifications can take either a relative or an absolute path. It is best to specify
                // a relative path if the document is intended to work across multiple platforms (Windows, Linux, Mac)
                FileSpecification fileSpec = new FileSpecification(doc, sFileSpec);
                Console.WriteLine("Path to remote document : " + fileSpec.Path);

                RemoteDestination remoteDest = new RemoteDestination(doc, 0, "XYZ", new Rect(0, 0, 4 * 72, 4 * 72), 1.5);
                Console.WriteLine("When the Link is clicked the remote document will open to : ");
                Console.WriteLine("Page Number : " + remoteDest.PageNumber);
                Console.WriteLine("zoom level : " + remoteDest.Zoom);
                Console.WriteLine("fit type : " + remoteDest.FitType);
                Console.WriteLine("rectangle : " + remoteDest.DestRect.ToString());

                // Now create the RemoteGoToAction from the fileSpec and the RemoteDestination
                RemoteGoToAction remoteAction = new RemoteGoToAction(fileSpec, remoteDest);

                // assign the RemoteGoToAction to the LinkAnnotation
                newLink.Action = remoteAction;

                doc.Save(SaveFlags.Full, sOutput);
            }
        }
Exemplo n.º 12
0
 public static string AddAttachments(string path, string filename)
 {
     // Open document
     using (Document pdfDocument = new Document(HttpContext.Current.Server.MapPath("Convert/output.pdf")))
     {
         // Setup new file to be added as attachment
         FileSpecification fileSpecification = new FileSpecification(path, filename);
         // Add attachment to document's attachment collection
         pdfDocument.EmbeddedFiles.Add(fileSpecification);
         // Save new output
         pdfDocument.Save(HttpContext.Current.Server.MapPath("Convert/output.pdf"));
     }
     return "success";
 }
        /**
         * Mouse up handler.
         * All annotation transformation is performed in mouse move handler.
         * This handler is for context menu calls, and for finishing annotation tracking.
         */
        public override void MouseUp(MouseEventArgs e, System.Drawing.Point location)
        {
            captured = false;
            if (!docView.EditPermission)
            {
                return;
            }

            if (e.Button == MouseButtons.Right)
            {
                if (docView.ActiveAnnotation != null)
                {
                    ContextMenu currentContextMenu = null;

                    switch (docView.ActiveAnnotation.Properties.Subtype)
                    {
                    case "FreeText":
                        currentContextMenu = textAnnotationContextMenu;
                        break;

                    case "Link":
                        currentContextMenu = linkAnnotationContextMenu;
                        break;

                    default:
                        currentContextMenu = shapeAnnotationContextMenu;
                        break;
                    }
                    if (currentContextMenu != null)
                    {
                        UpdateMenuItems(currentContextMenu);
                        currentContextMenu.Show(docView.Parent, e.Location);
                    }
                }
            }
            else
            {
                docView.EditCheckPoint();
                if (e.Button == MouseButtons.Left && Control.ModifierKeys == Keys.Control && (docView.ActiveAnnotation != null || cachedIndex != -1))
                {
                    BaseAnnotationEditor editor = docView.EditAnnotations[cachedIndex];
                    if (editor is LinkAnnotationEditor)
                    {
                        LinkAnnotation annot = editor.Annotation as LinkAnnotation;
                        if (annot.Action is URIAction)
                        {
                            URIAction act = annot.Action as URIAction;
                            System.Diagnostics.Process.Start(act.URI);
                        }
                        else if (annot.Action is RemoteGoToAction)
                        {
                            RemoteGoToAction  action = annot.Action as RemoteGoToAction;
                            FileSpecification spec   = action.FileSpecification;

                            string fullPath = System.IO.Path.GetFullPath(spec.Path);
                            if (System.IO.File.Exists(fullPath))
                            {
                                System.Diagnostics.Process.Start(fullPath);
                            }
                        }
                        else if (annot.Action is GoToAction || annot.Destination != null)
                        {
                            GoToAction      action = (annot.Action as GoToAction);
                            ViewDestination dest   = action == null ? annot.Destination : action.Destination;

                            if (dest != null)
                            {
                                docView.GoToDestionation(dest);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
        public override void Run(
            )
        {
            // 1. Externalizing the streams...
            string externalizedFilePath;
            {
                // 1.1. Opening the PDF file...
                string filePath = PromptFileChoice("Please select a PDF file");
                using (var file = new files::File(filePath))
                {
                    Document document = file.Document;

                    /*
                     * NOTE: As we are going to export streams using paths relative to the output path, it's
                     * necessary to ensure they are properly resolved (otherwise they will be written relative to
                     * the current user directory).
                     */
                    file.Path = OutputPath;

                    // 1.2. Iterating through the indirect objects to externalize streams...
                    int filenameIndex = 0;
                    foreach (PdfIndirectObject indirectObject in file.IndirectObjects)
                    {
                        PdfDataObject dataObject = indirectObject.DataObject;
                        if (dataObject is PdfStream)
                        {
                            PdfStream stream = (PdfStream)dataObject;
                            if (stream.DataFile == null) // Internal stream to externalize.
                            {
                                stream.SetDataFile(
                                    FileSpecification.Get(
                                        document,
                                        GetType().Name + "-external" + filenameIndex++
                                        ),
                                    true // Forces the stream data to be transferred to the external location.
                                    );
                            }
                        }
                    }

                    // 1.3. Serialize the PDF file!
                    externalizedFilePath = Serialize(file, files::SerializationModeEnum.Standard);
                }
            }

            // 2. Reimporting the externalized streams...
            {
                // 2.1. Opening the PDF file...
                using (var file = new files::File(externalizedFilePath))
                {
                    // 2.2. Iterating through the indirect objects to internalize streams...
                    foreach (PdfIndirectObject indirectObject in file.IndirectObjects)
                    {
                        PdfDataObject dataObject = indirectObject.DataObject;
                        if (dataObject is PdfStream)
                        {
                            PdfStream stream = (PdfStream)dataObject;
                            if (stream.DataFile != null) // External stream to internalize.
                            {
                                stream.SetDataFile(
                                    null,
                                    true // Forces the stream data to be transferred to the internal location.
                                    );
                            }
                        }
                    }

                    // 2.3. Serialize the PDF file!
                    string externalizedFileName = Path.GetFileNameWithoutExtension(externalizedFilePath);
                    string internalizedFilePath = externalizedFileName + "-reimported.pdf";
                    Serialize(file, internalizedFilePath, files::SerializationModeEnum.Standard);
                }
            }
        }
Exemplo n.º 15
0
        private void Populate(
            Document document
            )
        {
            Page page = new Page(document);

            document.Pages.Add(page);

            PrimitiveComposer composer = new PrimitiveComposer(page);
            StandardType1Font font     = new StandardType1Font(
                document,
                StandardType1Font.FamilyEnum.Courier,
                true,
                false
                );

            composer.SetFont(font, 12);

            // Note.
            composer.ShowText("Note annotation:", new Point(35, 35));
            annotations::Note note = new annotations::Note(
                page,
                new Point(50, 50),
                "Note annotation"
                );

            note.IconType         = annotations::Note.IconTypeEnum.Help;
            note.ModificationDate = new DateTime();
            note.IsOpen           = true;

            // Callout.
            composer.ShowText("Callout note annotation:", new Point(35, 85));
            annotations::CalloutNote calloutNote = new annotations::CalloutNote(
                page,
                new Rectangle(50, 100, 200, 24),
                "Callout note annotation"
                );

            calloutNote.Justification = JustificationEnum.Right;
            calloutNote.Line          = new annotations::CalloutNote.LineObject(
                page,
                new Point(150, 650),
                new Point(100, 600),
                new Point(50, 100)
                );

            // File attachment.
            composer.ShowText("File attachment annotation:", new Point(35, 135));
            annotations::FileAttachment attachment = new annotations::FileAttachment(
                page,
                new Rectangle(50, 150, 12, 12),
                "File attachment annotation",
                FileSpecification.Get(
                    EmbeddedFile.Get(
                        document,
                        GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")
                        ),
                    "happyGNU.jpg"
                    )
                );

            attachment.IconType = annotations::FileAttachment.IconTypeEnum.PaperClip;

            composer.BeginLocalState();

            // Arrow line.
            composer.ShowText("Line annotation:", new Point(35, 185));
            composer.SetFont(font, 10);
            composer.ShowText("Arrow:", new Point(50, 200));
            annotations::Line line = new annotations::Line(
                page,
                new Point(50, 260),
                new Point(200, 210),
                "Arrow line annotation"
                );

            line.FillColor      = new DeviceRGBColor(1, 0, 0);
            line.StartStyle     = annotations::Line.LineEndStyleEnum.Circle;
            line.EndStyle       = annotations::Line.LineEndStyleEnum.ClosedArrow;
            line.CaptionVisible = true;

            // Dimension line.
            composer.ShowText("Dimension:", new Point(300, 200));
            line = new annotations::Line(
                page,
                new Point(300, 220),
                new Point(500, 220),
                "Dimension line annotation"
                );
            line.LeaderLineLength          = 20;
            line.LeaderLineExtensionLength = 10;
            line.CaptionVisible            = true;

            composer.End();

            // Scribble.
            composer.ShowText("Scribble annotation:", new Point(35, 285));
            new annotations::Scribble(
                page,
                new RectangleF(50, 300, 100, 30),
                "Scribble annotation",
                new List <IList <PointF> >(
                    new List <PointF>[]
            {
                new List <PointF>(
                    new PointF[]
                {
                    new PointF(50, 300),
                    new PointF(70, 310),
                    new PointF(100, 320)
                }
                    )
            }
                    )
                );

            // Rectangle.
            composer.ShowText("Rectangle annotation:", new Point(35, 335));
            annotations::Rectangle rectangle = new annotations::Rectangle(
                page,
                new Rectangle(50, 350, 100, 30),
                "Rectangle annotation"
                );

            rectangle.FillColor = new DeviceRGBColor(1, 0, 0);

            // Ellipse.
            composer.ShowText("Ellipse annotation:", new Point(35, 385));
            annotations::Ellipse ellipse = new annotations::Ellipse(
                page,
                new Rectangle(50, 400, 100, 30),
                "Ellipse annotation"
                );

            ellipse.FillColor = new DeviceRGBColor(0, 0, 1);

            // Rubber stamp.
            composer.ShowText("Rubber stamp annotation:", new Point(35, 435));
            new annotations::RubberStamp(
                page,
                new Rectangle(50, 450, 100, 30),
                "Rubber stamp annotation",
                annotations::RubberStamp.IconTypeEnum.Approved
                );

            // Caret.
            composer.ShowText("Caret annotation:", new Point(35, 485));
            annotations::Caret caret = new annotations::Caret(
                page,
                new Rectangle(50, 500, 100, 30),
                "Caret annotation"
                );

            caret.SymbolType = annotations::Caret.SymbolTypeEnum.NewParagraph;

            composer.Flush();
        }
Exemplo n.º 16
0
        private void BuildLinks(
            Document document
            )
        {
            Pages pages = document.Pages;
            Page  page  = new Page(document);

            pages.Add(page);

            PrimitiveComposer composer      = new PrimitiveComposer(page);
            BlockComposer     blockComposer = new BlockComposer(composer);

            StandardType1Font font = new StandardType1Font(document, StandardType1Font.FamilyEnum.Courier, true, false);

            /*
             * 2.1. Goto-URI link.
             */
            {
                blockComposer.Begin(new RectangleF(30, 100, 200, 50), XAlignmentEnum.Left, YAlignmentEnum.Middle);
                composer.SetFont(font, 12);
                blockComposer.ShowText("Go-to-URI link");
                composer.SetFont(font, 8);
                blockComposer.ShowText("\nIt allows you to navigate to a network resource.");
                composer.SetFont(font, 5);
                blockComposer.ShowText("\n\nClick on the box to go to the project's SourceForge.net repository.");
                blockComposer.End();

                /*
                 * NOTE: This statement instructs the PDF viewer to navigate to the given URI when the link is clicked.
                 */
                new Link(
                    page,
                    new RectangleF(240, 100, 100, 50),
                    "Link annotation",
                    new GoToURI(
                        document,
                        new Uri("http://www.sourceforge.net/projects/clown")
                        )
                    )
                {
                    Border = new Border(3, Border.StyleEnum.Beveled)
                };
            }

            /*
             * 2.2. Embedded-goto link.
             */
            {
                string filePath = PromptFileChoice("Please select a PDF file to attach");

                /*
                 * NOTE: These statements instruct PDF Clown to attach a PDF file to the current document.
                 * This is necessary in order to test the embedded-goto functionality,
                 * as you can see in the following link creation (see below).
                 */
                int    fileAttachmentPageIndex = page.Index;
                string fileAttachmentName      = "attachedSamplePDF";
                string fileName = System.IO.Path.GetFileName(filePath);
                new FileAttachment(
                    page,
                    new RectangleF(0, -20, 10, 10),
                    "File attachment annotation",
                    FileSpecification.Get(
                        EmbeddedFile.Get(
                            document,
                            filePath
                            ),
                        fileName
                        )
                    )
                {
                    Name     = fileAttachmentName,
                    IconType = FileAttachment.IconTypeEnum.PaperClip
                };

                blockComposer.Begin(new RectangleF(30, 170, 200, 50), XAlignmentEnum.Left, YAlignmentEnum.Middle);
                composer.SetFont(font, 12);
                blockComposer.ShowText("Go-to-embedded link");
                composer.SetFont(font, 8);
                blockComposer.ShowText("\nIt allows you to navigate to a destination within an embedded PDF file.");
                composer.SetFont(font, 5);
                blockComposer.ShowText("\n\nClick on the button to go to the 2nd page of the attached PDF file (" + fileName + ").");
                blockComposer.End();

                /*
                 * NOTE: This statement instructs the PDF viewer to navigate to the page 2 of a PDF file
                 * attached inside the current document as described by the FileAttachment annotation on page 1 of the current document.
                 */
                new Link(
                    page,
                    new RectangleF(240, 170, 100, 50),
                    "Link annotation",
                    new GoToEmbedded(
                        document,
                        new GoToEmbedded.PathElement(
                            document,
                            fileAttachmentPageIndex, // Page of the current document containing the file attachment annotation of the target document.
                            fileAttachmentName,      // Name of the file attachment annotation corresponding to the target document.
                            null                     // No sub-target.
                            ),                       // Target represents the document to go to.
                        new RemoteDestination(
                            document,
                            1,                        // Show the page 2 of the target document.
                            Destination.ModeEnum.Fit, // Show the target document page entirely on the screen.
                            null,
                            null
                            ) // The destination must be within the target document.
                        )
                    )
                {
                    Border = new Border(1, new LineDash(new double[] { 8, 5, 2, 5 }))
                };
            }

            /*
             * 2.3. Textual link.
             */
            {
                blockComposer.Begin(new RectangleF(30, 240, 200, 50), XAlignmentEnum.Left, YAlignmentEnum.Middle);
                composer.SetFont(font, 12);
                blockComposer.ShowText("Textual link");
                composer.SetFont(font, 8);
                blockComposer.ShowText("\nIt allows you to expose any kind of link (including the above-mentioned types) as text.");
                composer.SetFont(font, 5);
                blockComposer.ShowText("\n\nClick on the text links to go either to the project's SourceForge.net repository or to the project's home page.");
                blockComposer.End();

                composer.BeginLocalState();
                composer.SetFont(font, 10);
                composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Blue));
                composer.ShowText(
                    "PDF Clown Project's repository at SourceForge.net",
                    new PointF(240, 265),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0,
                    new GoToURI(
                        document,
                        new Uri("http://www.sourceforge.net/projects/clown")
                        )
                    );
                composer.ShowText(
                    "PDF Clown Project's home page",
                    new PointF(240, 285),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Bottom,
                    -90,
                    new GoToURI(
                        document,
                        new Uri("http://www.pdfclown.org")
                        )
                    );
                composer.End();
            }

            composer.Flush();
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine
                (
                    "RecordDumper <connection-string> "
                    + "<search-expression> <output-file>"
                );

                return;
            }

            string connectionString = args[0];
            string searchExpression = args[1];
            string outputFileName   = args[2];

            try
            {
                JObject config
                    = JsonUtility.ReadObjectFromFile("dumperConfig.json");
                int   etalonTag   = config["etalonTag"].Value <int>();
                int[] excludeTags = config["excludeTags"]
                                    .Values <int>().ToArray();
                string[] excludePages = config["excludePages"]
                                        .Values <string>().ToArray();

                using (IrbisProvider provider = ProviderManager
                                                .GetAndConfigureProvider(connectionString))
                    using (StreamWriter writer = TextWriterUtility.Create
                                                 (
                               outputFileName,
                               IrbisEncoding.Utf8
                                                 ))
                    {
                        FileSpecification specification = new FileSpecification
                                                          (
                            IrbisPath.MasterFile,
                            provider.Database,
                            "WS31.OPT"
                                                          );
                        IrbisOpt opt = IrbisOpt.LoadFromServer
                                       (
                            provider,
                            specification
                                       );
                        if (ReferenceEquals(opt, null))
                        {
                            throw new IrbisException("Can't load OPT file!");
                        }

                        int[] found = provider.Search(searchExpression);
                        Console.WriteLine("Found: {0}", found.Length);

                        foreach (int mfn in found)
                        {
                            MarcRecord record = provider.ReadRecord(mfn);
                            if (ReferenceEquals(record, null))
                            {
                                continue;
                            }
                            string title = record.FM(etalonTag);
                            if (string.IsNullOrEmpty(title))
                            {
                                continue;
                            }

                            string wsName = opt.SelectWorksheet(opt.GetWorksheet(record));
                            if (string.IsNullOrEmpty(wsName))
                            {
                                continue;
                            }
                            specification = new FileSpecification
                                            (
                                IrbisPath.MasterFile,
                                provider.Database,
                                wsName + ".ws"
                                            );
                            WsFile worksheet = WsFile.ReadFromServer
                                               (
                                provider,
                                specification
                                               );
                            if (ReferenceEquals(worksheet, null))
                            {
                                continue;
                            }

                            Console.WriteLine("MFN={0}: {1}", mfn, title);
                            writer.WriteLine("<h3>{0}</h3>", title);

                            string description = provider.FormatRecord(record, "@");
                            writer.WriteLine(description);

                            RecordField[] fields = record.Fields
                                                   .Where(field => !field.Tag.OneOf(excludeTags))
                                                   .ToArray();

                            writer.WriteLine
                            (
                                "<table border=\"1\" "
                                + "cellpadding=\"3\" "
                                + "cellspacing=\"0\" "
                                + ">"
                            );
                            writer.WriteLine
                            (
                                "<tr bgcolor=\"black\">"
                                + "<th style=\"color:white;text-align:left;\">Поле</th>"
                                + "<th style=\"color:white;text-align:left;\">Подполе</th>"
                                + "<th style=\"color:white;text-align:left;\">Значение</th>"
                                + "</tr>"
                            );
                            foreach (WorksheetPage page in worksheet.Pages)
                            {
                                if (page.Name.OneOf(excludePages))
                                {
                                    continue;
                                }

                                int[] tags = page.Items
                                             .Select(item => item.Tag)
                                             .Select(NumericUtility.ParseInt32)
                                             .ToArray();
                                if (!fields.Any(field => field.Tag.OneOf(tags)))
                                {
                                    continue;
                                }
                                writer.WriteLine
                                (
                                    "<tr><td colspan=\"3\"><b>Вкладка «{0}»</b></td></tr>",
                                    page.Name
                                );

                                foreach (WorksheetItem item in page.Items)
                                {
                                    if (string.IsNullOrEmpty(item.Tag))
                                    {
                                        continue;
                                    }

                                    int tag = NumericUtility.ParseInt32(item.Tag);
                                    if (tag <= 0)
                                    {
                                        continue;
                                    }

                                    RecordField[] itemFields = fields.GetField(tag);
                                    for (int i = 0; i < itemFields.Length; i++)
                                    {
                                        RecordField field = itemFields[i];
                                        title = item.Title;
                                        title = StringUtility.Sparse(title);
                                        if (i != 0)
                                        {
                                            title = string.Format
                                                    (
                                                "(повторение {0})",
                                                i + 1
                                                    );
                                        }
                                        int rowspan = 1;
                                        if (string.IsNullOrEmpty(field.Value))
                                        {
                                            rowspan = 1 + field.SubFields.Count;
                                        }
                                        writer.WriteLine
                                        (
                                            "<tr><td rowspan=\"{0}\" \"width=\"{1}\"><b>{2}</b></td><td colspan=\"2\"><b>{3}</b></td></tr>",
                                            rowspan,
                                            FirstWidth,
                                            field.Tag,
                                            HtmlText.Encode(title)
                                        );

                                        if (!string.IsNullOrEmpty(field.Value))
                                        {
                                            writer.WriteLine
                                            (
                                                "<tr><td colspan=\"2\">&nbsp;</td><td>{0}</td></tr>",
                                                HtmlText.Encode(field.Value)
                                            );
                                        }

                                        if (item.EditMode == "5")
                                        {
                                            string inputInfo = item.InputInfo
                                                               .ThrowIfNull("item.InputInfo");

                                            // Поле с подполями
                                            specification = new FileSpecification
                                                            (
                                                IrbisPath.MasterFile,
                                                provider.Database,
                                                inputInfo
                                                            );
                                            WssFile wss = WssFile.ReadFromServer
                                                          (
                                                provider,
                                                specification
                                                          );
                                            if (ReferenceEquals(wss, null))
                                            {
                                                Console.WriteLine
                                                (
                                                    "Can't load: " + inputInfo
                                                );
                                            }
                                            else
                                            {
                                                foreach (WorksheetItem line in wss.Items)
                                                {
                                                    char     code     = line.Tag.FirstChar();
                                                    SubField subField = field.GetFirstSubField(code);
                                                    if (!ReferenceEquals(subField, null))
                                                    {
                                                        writer.WriteLine
                                                        (
                                                            "<tr>"
                                                            + "<td width=\"{0}\"><b>{1}</b>: {2}</td>"
                                                            + "<td width=\"{3}\">{4}</td></tr>",
                                                            SecondWidth,
                                                            CharUtility.ToUpperInvariant(code),
                                                            HtmlText.Encode(line.Title),
                                                            ThirdWidth,
                                                            HtmlText.Encode(subField.Value)
                                                        );
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            writer.WriteLine("</table>");
                        }
                    }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Exemplo n.º 18
0
        /**
          <param name="preserve">Indicates whether the data from the old data source substitutes the
          new one. This way data can be imported to/exported from local or preserved in case of external
          file location changed.</param>
          <seealso cref="DataFile"/>
        */
        public void SetDataFile(
            FileSpecification value,
            bool preserve
            )
        {
            /*
            NOTE: If preserve argument is set to true, body's dirtiness MUST be forced in order to ensure
            data serialization to the new external location.

            Old data source | New data source | preserve | Action
            ----------------------------------------------------------------------------------------------
            local           | not null        | false     | A. Substitute local with new file.
            local           | not null        | true      | B. Export local to new file.
            external        | not null        | false     | C. Substitute old file with new file.
            external        | not null        | true      | D. Copy old file data to new file.
            local           | null            | (any)     | E. No action.
            external        | null            | false     | F. Empty local.
            external        | null            | true      | G. Import old file to local.
            ----------------------------------------------------------------------------------------------
              */
              FileSpecification oldDataFile = DataFile;
              PdfDirectObject dataFileObject = (value != null ? value.BaseObject : null);
              if(value != null)
              {
            if(preserve)
            {
              if(oldDataFile != null) // Case D (copy old file data to new file).
              {
            if(!bodyResolved)
            {
              // Transfer old file data to local!
              GetBody(false); // Ensures that external data is loaded as-is into the local buffer.
            }
              }
              else // Case B (export local to new file).
              {
            // Transfer local settings to file!
            header[PdfName.FFilter] = header[PdfName.Filter]; header.Remove(PdfName.Filter);
            header[PdfName.FDecodeParms] = header[PdfName.DecodeParms]; header.Remove(PdfName.DecodeParms);

            // Ensure local data represents actual data (otherwise it would be substituted by resolved file data)!
            bodyResolved = true;
              }
              // Ensure local data has to be serialized to new file!
              body.Dirty = true;
            }
            else // Case A/C (substitute local/old file with new file).
            {
              // Dismiss local/old file data!
              body.SetLength(0);
              // Dismiss local/old file settings!
              Filter = null;
              Parameters = null;
              // Ensure local data has to be loaded from new file!
              bodyResolved = false;
            }
              }
              else
              {
            if(oldDataFile != null)
            {
              if(preserve) // Case G (import old file to local).
              {
            // Transfer old file data to local!
            GetBody(false); // Ensures that external data is loaded as-is into the local buffer.
            // Transfer old file settings to local!
            header[PdfName.Filter] = header[PdfName.FFilter]; header.Remove(PdfName.FFilter);
            header[PdfName.DecodeParms] = header[PdfName.FDecodeParms]; header.Remove(PdfName.FDecodeParms);
              }
              else // Case F (empty local).
              {
            // Dismiss old file data!
            body.SetLength(0);
            // Dismiss old file settings!
            Filter = null;
            Parameters = null;
            // Ensure local data represents actual data (otherwise it would be substituted by resolved file data)!
            bodyResolved = true;
              }
            }
            else // E (no action).
            { /* NOOP */ }
              }
              header[PdfName.F] = dataFileObject;
        }