Пример #1
1
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
              string filePath = PromptFileChoice("Please select a PDF file");
              using(File file = new File(filePath))
              {
            // Define the text pattern to look for!
            string textRegEx = PromptChoice("Please enter the pattern to look for: ");
            Regex pattern = new Regex(textRegEx, RegexOptions.IgnoreCase);

            // 2. Iterating through the document pages...
            TextExtractor textExtractor = new TextExtractor(true, true);
            foreach(Page page in file.Document.Pages)
            {
              Console.WriteLine("\nScanning page " + (page.Index+1) + "...\n");

              // 2.1. Extract the page text!
              IDictionary<RectangleF?,IList<ITextString>> textStrings = textExtractor.Extract(page);

              // 2.2. Find the text pattern matches!
              MatchCollection matches = pattern.Matches(TextExtractor.ToString(textStrings));

              // 2.3. Highlight the text pattern matches!
              textExtractor.Filter(
            textStrings,
            new TextHighlighter(page, matches)
            );
            }

            // 3. Highlighted file serialization.
            Serialize(file);
              }
        }
Пример #2
1
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
              string filePath = PromptFileChoice("Please select a PDF file");
              using(File file = new File(filePath))
              {
            Document document = file.Document;

            // 2. Text extraction from the document pages.
            TextExtractor extractor = new TextExtractor();
            foreach(Page page in document.Pages)
            {
              if(!PromptNextPage(page, false))
              {
            Quit();
            break;
              }

              IList<ITextString> textStrings = extractor.Extract(page)[TextExtractor.DefaultArea];
              foreach(ITextString textString in textStrings)
              {
            RectangleF textStringBox = textString.Box.Value;
            Console.WriteLine(
              "Text ["
                + "x:" + Math.Round(textStringBox.X) + ","
                + "y:" + Math.Round(textStringBox.Y) + ","
                + "w:" + Math.Round(textStringBox.Width) + ","
                + "h:" + Math.Round(textStringBox.Height)
                + "]: " + textString.Text
                );
              }
            }
              }
        }
Пример #3
1
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
              string filePath = PromptFileChoice("Please select a PDF file");
              using(File file = new File(filePath))
              {
            Document document = file.Document;
            Page page = document.Pages[1]; // Page 2 (zero-based index).

            // 2. Applying actions...
            // 2.1. Local go-to.
            /*
              NOTE: This statement instructs the PDF viewer to go to page 2 on document opening.
            */
            document.Actions.OnOpen = new GoToLocal(
              document,
              new LocalDestination(page) // Page 2 (zero-based index).
              );

            // 2.2. Remote go-to.
            try
            {
              /*
            NOTE: This statement instructs the PDF viewer to navigate to the given URI on page 2
            opening.
              */
              page.Actions.OnOpen = new GoToURI(
            document,
            new Uri("http://www.sourceforge.net/projects/clown")
            );
            }
            catch(Exception exception)
            {throw new Exception("Remote goto failed.",exception);}

            // 3. Serialize the PDF file!
            Serialize(file, "Actions", "applying actions", "actions, creation, local goto, remote goto");
              }
        }
Пример #4
0
        public System.Windows.Media.Imaging.BitmapImage createImage()
        {
            string fileName = filePath;

            using (var file = new org.pdfclown.files.File(fileName)) {
                Document document = file.Document;
                Pages    pages    = document.Pages;

                Page                 page      = pages[0];
                SizeF                imageSize = page.Size;
                Renderer             renderer  = new Renderer();
                System.Drawing.Image image     = renderer.Render(page, imageSize);

                // Winforms Image we want to get the WPF Image from
                var bitmap = new System.Windows.Media.Imaging.BitmapImage();
                bitmap.BeginInit();
                MemoryStream memoryStream = new MemoryStream();
                // Save to a memory stream
                image.Save(memoryStream, ImageFormat.Bmp);
                // Rewind the stream
                memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
                bitmap.StreamSource = memoryStream;
                bitmap.EndInit();

                return(bitmap);
            }
        }
Пример #5
0
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
              string filePath = PromptFileChoice("Please select a PDF file");
              using(File file = new File(filePath))
              {
            Document document = file.Document;

            PageStamper stamper = new PageStamper(); // NOTE: Page stamper is used to draw contents on existing pages.

            // 2. Iterating through the document pages...
            foreach(Page page in document.Pages)
            {
              Console.WriteLine("\nScanning page " + (page.Index+1) + "...\n");

              stamper.Page = page;

              Extract(
            new ContentScanner(page), // Wraps the page contents into a scanner.
            stamper.Foreground
            );

              stamper.Flush();
            }

            // 3. Decorated version serialization.
            Serialize(file);
              }
        }
Пример #6
0
        private void SelectSelection(String pSelection)
        {
            SetProgress(listBoxSelection.SelectedItems.Count + 1);
            DisplayProgress();
            String filename = textBoxPDFDirectory.Text + "\\" + pSelection + ".pdf";

            using (org.pdfclown.files.File file = new org.pdfclown.files.File(filename))
            {
                Document      document  = file.Document;
                TextExtractor extractor = new TextExtractor();

                // 2. Text extraction from the document pages.
                foreach (Page page in document.Pages)
                {
                    IList <ITextString> textStrings = extractor.Extract(page)[TextExtractor.DefaultArea];
                    foreach (ITextString textString in textStrings)
                    {
                        // Identifier si le texte est un registre d'élève.
                        if (IsStudent(textString.Text))
                        {
                            RectangleF textStringBox = textString.Box.Value;
                            listBoxFiches.Items.Add(recordEtudiants[recordEtudiants.Count - 1].Fiche);
                            Console.WriteLine("Text ["
                                              + "x:" + Math.Round(textStringBox.X) + ","
                                              + "y:" + Math.Round(textStringBox.Y) + ","
                                              + "w:" + Math.Round(textStringBox.Width) + ","
                                              + "h:" + Math.Round(textStringBox.Height)
                                              + "]: " + textString.Text);
                        }
                        listBoxFiches.Update();
                    }
                }
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            // Opening the PDF file...
            string mainFilePath = args[1];
            using (File mainFile = new File(mainFilePath))
            {
                Document mainDocument = mainFile.Document;
                Pages mainPages = mainDocument.Pages;
                int mainPagesCount = mainPages.Count;

                // Opening the source file...
                string sourceFilePath = args[1];
                using (File sourceFile = new File(sourceFilePath))
                {
                    // Append the chosen source document to the main document!
                    new PageManager(mainDocument).Add(sourceFile.Document);
                }

                try
                { file.Save(outputFilePath, SerializationModeEnum.Standard); }
                catch (Exception e)
                {
                    Console.WriteLine("File writing failed: " + e.Message);
                    Console.WriteLine(e.StackTrace);
                }
                Console.WriteLine("\nOutput: " + outputFilePath);

            }
        }
Пример #8
0
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
              string filePath = PromptFileChoice("Please select a PDF file");
              using(File file = new File(filePath))
              {
            Document document = file.Document;

            // 2. Applying the visual transitions...
            Transition.StyleEnum[] transitionStyles = (Transition.StyleEnum[])Enum.GetValues(typeof(Transition.StyleEnum));
            int transitionStylesLength = transitionStyles.Length;
            Random random = new Random();
            foreach(Page page in document.Pages)
            {
              // Apply a transition to the page!
              page.Transition = new Transition(
            document,
            transitionStyles[random.Next(transitionStylesLength)], // NOTE: Random selection of the transition is done here just for demonstrative purposes; in real world, you would obviously choose only the appropriate enumeration constant among those available.
            .5 // Transition duration (half a second).
            );
              // Set the display time of the page on presentation!
              page.Duration = 2; // Page display duration (2 seconds).
            }

            // 3. Serialize the PDF file!
            Serialize(file, "Transition", "applying visual transitions to pages", "page transition");
              }
        }
Пример #9
0
        private void exportPDFProcess(string filename, FPDFSave dialog)
        {
            org.pdfclown.files.File         file     = new org.pdfclown.files.File();
            org.pdfclown.documents.Document document = file.Document;
            Page   page;
            Stream stream;

            org.pdfclown.documents.contents.entities.JpegImage currentImage;
            int i = 1;

            foreach (CScannedImage img in images.Values)
            {
                ThreadStart setstatus = delegate { dialog.SetStatus(i, images.Count); };
                dialog.Invoke(setstatus);
                Size      pageSize  = new Size((int)(img.BaseImage.Width / img.BaseImage.HorizontalResolution * 72), (int)(img.BaseImage.Height / img.BaseImage.VerticalResolution * 72));
                PointF    point     = new PointF(0, 0);
                Resources resources = new Resources(document);
                //page = new Page(document,pageSize,resources);
                page = new Page(document);
                document.Pages.Add(page);
                stream = new MemoryStream();
                img.BaseImage.Save(stream, ImageFormat.Jpeg);
                PrimitiveComposer composer = new PrimitiveComposer(page);
                currentImage = new org.pdfclown.documents.contents.entities.JpegImage(stream);
                composer.ShowXObject(currentImage.ToXObject(document), point, pageSize);
                stream.Flush();
                composer.Flush();
                i++;
            }
            file.Save(filename, SerializationModeEnum.Standard);
            dialog.Invoke(new ThreadStart(dialog.Close));
        }
Пример #10
0
        /// <summary>
        /// Constructor
        /// </summary>
        public PdfClownCreator()
        {
            //create a new document
            PdfFile = new org.pdfclown.files.File();

            //create the document now
            Doc = PdfFile.Document;
        }
Пример #11
0
 /**
   <remarks>
 <para>This is a necessary hack because indirect objects are unreachable on parsing bootstrap
 (see File(IInputStream) constructor).</para>
   </remarks>
 */
 internal PdfReference(
     FileParser.Reference reference,
     File file
     )
 {
     this.objectNumber = reference.ObjectNumber;
       this.file = file;
 }
Пример #12
0
        public void AdicionarLogoPdf(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            using var pdfFile = new File(new org.pdfclown.bytes.Stream(stream));
            _LogoObject       = pdfFile.Document.Pages[0].ToXObject(PdfDocument);
        }
Пример #13
0
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
              string filePath = PromptFileChoice("Please select a PDF file");
              using(File file = new File(filePath))
              {
            Document document = file.Document;
            Pages pages = document.Pages;

            // 2. Inserting page destinations...
            NamedDestinations destinations = document.Names.Destinations;
            /*
              NOTE: Here we are registering page 1 multiple times to test tree structure sorting and splitting.
            */
            Destination page1Destination = new LocalDestination(pages[0]);
            destinations[new PdfString("d31e1142")] = page1Destination;
            destinations[new PdfString("Z1")] = page1Destination;
            destinations[new PdfString("d38e1142")] = page1Destination;
            destinations[new PdfString("B84afaba8")] = page1Destination;
            destinations[new PdfString("z38e1142")] = page1Destination;
            destinations[new PdfString("d3A8e1142")] = page1Destination;
            destinations[new PdfString("f38e1142")] = page1Destination;
            destinations[new PdfString("B84afaba6")] = page1Destination;
            destinations[new PdfString("d3a8e1142")] = page1Destination;
            destinations[new PdfString("Z38e1142")] = page1Destination;
            if(pages.Count > 1)
            {
              LocalDestination page2Destination = new LocalDestination(pages[1], Destination.ModeEnum.FitHorizontal, 0, null);
              destinations[new PdfString("N84afaba6")] = page2Destination;

              // Let the viewer go to the second page on document opening!
              /*
            NOTE: Any time a named destination is applied, its name is retrieved and used as reference.
              */
              document.Actions.OnOpen = new GoToLocal(
            document,
            page2Destination // Its name ("N84afaba6") is retrieved behind the scenes.
            );
              // Define a link to the second page on the first one!
              new Link(
            pages[0],
            new RectangleF(0,0,100,50),
            "Link annotation",
            page2Destination // Its name ("N84afaba6") is retrieved behind the scenes.
            );

              if(pages.Count > 2)
              {destinations[new PdfString("1845505298")] = new LocalDestination(pages[2], Destination.ModeEnum.XYZ, new PointF(50, Single.NaN), null);}
            }

            // 3. Serialize the PDF file!
            Serialize(file, "Named destinations", "manipulating named destinations", "named destinations, creation");
              }
        }
Пример #14
0
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
              string filePath = PromptFileChoice("Please select a PDF file");
              using(File file = new File(filePath))
              {
            Document document = file.Document;

            // 2. Get the acroform!
            Form form = document.Form;
            if(!form.Exists())
            {Console.WriteLine("\nNo acroform available (AcroForm dictionary not found).");}
            else
            {
              Console.WriteLine("\nIterating through the fields collection...\n");

              // 3. Showing the acroform fields...
              Dictionary<string,int> objCounters = new Dictionary<string,int>();
              foreach(Field field in form.Fields.Values)
              {
            Console.WriteLine("* Field '" + field.FullName + "' (" + field.BaseObject + ")");

            string typeName = field.GetType().Name;
            Console.WriteLine("    Type: " + typeName);
            Console.WriteLine("    Value: " + field.Value);
            Console.WriteLine("    Data: " + field.BaseDataObject.ToString());

            int widgetIndex = 0;
            foreach(Widget widget in field.Widgets)
            {
              Console.WriteLine("    Widget " + (++widgetIndex) + ":");
              Page widgetPage = widget.Page;
              Console.WriteLine("      Page: " + (widgetPage == null ? "undefined" : (widgetPage.Index + 1) + " (" + widgetPage.BaseObject + ")"));

              RectangleF widgetBox = widget.Box;
              Console.WriteLine("      Coordinates: {x:" + Math.Round(widgetBox.X) + "; y:" + Math.Round(widgetBox.Y) + "; width:" + Math.Round(widgetBox.Width) + "; height:" + Math.Round(widgetBox.Height) + "}");
            }

            objCounters[typeName] = (objCounters.ContainsKey(typeName) ? objCounters[typeName] : 0) + 1;
              }

              int fieldCount = form.Fields.Count;
              if(fieldCount == 0)
              {Console.WriteLine("No field available.");}
              else
              {
            Console.WriteLine("\nFields partial counts (grouped by type):");
            foreach(KeyValuePair<string,int> entry in objCounters)
            {Console.WriteLine(" " + entry.Key + ": " + entry.Value);}
            Console.WriteLine("Fields total count: " + fieldCount);
              }
            }
              }
        }
Пример #15
0
        public override void Run(
            )
        {
            // 1. PDF file instantiation.
              File file = new File();
              Document document = file.Document;

              // 2. Content creation.
              Populate(document);

              // 3. PDF file serialization.
              Serialize(file, "Layer", "inserting layers", "layers, optional content");
        }
Пример #16
0
        public override void Run(
            )
        {
            // 1. PDF file instantiation.
              File file = new File();
              Document document = file.Document;

              // 2. Populate the document!
              Populate(document);

              // 3. Serialize the PDF file!
              Serialize(file, "Page Format", "page formats", "page formats");
        }
Пример #17
0
        public override void Run(
            )
        {
            // 1. Instantiate a new PDF file!
              File file = new File();
              Document document = file.Document;

              // 2. Insert the contents into the document!
              Populate(document);

              // 3. Serialize the PDF file!
              Serialize(file, "Text frame", "getting the actual bounding box of text shown", "text frames");
        }
Пример #18
0
        public override void Run(
            )
        {
            // 1. PDF file instantiation.
              File file = new File();
              Document document = file.Document;

              // 2. Content creation.
              Populate(document);

              // 3. Serialize the PDF file!
              Serialize(file, "Barcode", "showing barcodes", "barcodes, creation, EAN13");
        }
Пример #19
0
        public override void Run(
            )
        {
            // 1. PDF file instantiation.
              File file = new File();
              Document document = file.Document;

              // 2. Content creation.
              Populate(document);

              // 3. Serialize the PDF file!
              Serialize(file, "AcroForm", "inserting AcroForm fields", "Acroform, creation, annotations, actions, javascript, button, combo, textbox, radio button");
        }
Пример #20
0
        public override void Run(
            )
        {
            // 1. Instantiate a new PDF file!
              File file = new File();
              Document document = file.Document;

              // 2. Insert the contents into the document!
              BuildContent(document);

              // 3. Serialize the PDF file!
              Serialize(file, "Page coordinates", "manipulating the CTM", "page coordinates, ctm");
        }
Пример #21
0
        /**
          <param name="file">Associated file.</param>
          <param name="dataObject">
        <para>Data object associated to the indirect object. It MUST be</para>
        <list type="bullet">
          <item><code>null</code>, if the indirect object is original or free.</item>
          <item>NOT <code>null</code>, if the indirect object is new and in-use.</item>
        </list>
          </param>
          <param name="xrefEntry">Cross-reference entry associated to the indirect object. If the
        indirect object is new, its offset field MUST be set to 0.</param>
        */
        internal PdfIndirectObject(
      File file,
      PdfDataObject dataObject,
      XRefEntry xrefEntry
      )
        {
            this.file = file;
              this.dataObject = Include(dataObject);
              this.xrefEntry = xrefEntry;

              this.original = (xrefEntry.Offset >= 0);
              this.reference = new PdfReference(this);
        }
Пример #22
0
        public DanfeService(DanfeViewModel viewModel)
        {
            ViewModel = viewModel ?? throw new ArgumentNullException(nameof(viewModel));

            Blocos      = new List <BlocoBase>();
            _file       = new File();
            PdfDocument = _file.Document;

            // De acordo com o item 7.7, a fonte deve ser Times New Roman ou Courier New.
            var fonteFamilia = StandardType1Font.FamilyEnum.Times;

            _fonteRegular = new StandardType1Font(PdfDocument, fonteFamilia, false, false);
            _fonteNegrito = new StandardType1Font(PdfDocument, fonteFamilia, true, false);
            _fonteItalico = new StandardType1Font(PdfDocument, fonteFamilia, false, true);

            EstiloPadrao = CriarEstilo();

            Paginas = new List <DanfePagina>();
            Canhoto = CriarBloco <BlocoCanhoto>();
            _identificacaoEmitente = AdicionarBloco <BlocoIdentificacaoEmitente>();
            AdicionarBloco <BlocoDestinatarioRemetente>();

            if (ViewModel.LocalRetirada != null && ViewModel.ExibirBlocoLocalRetirada)
            {
                AdicionarBloco <BlocoLocalRetirada>();
            }

            if (ViewModel.LocalEntrega != null && ViewModel.ExibirBlocoLocalEntrega)
            {
                AdicionarBloco <BlocoLocalEntrega>();
            }

            if (ViewModel.Duplicatas.Count > 0)
            {
                AdicionarBloco <BlocoDuplicataFatura>();
            }

            AdicionarBloco <BlocoCalculoImposto>(ViewModel.Orientacao == Orientacao.Paisagem ? EstiloPadrao : CriarEstilo(4.75F));
            AdicionarBloco <BlocoTransportador>();
            AdicionarBloco <BlocoDadosAdicionais>(CriarEstilo(tFonteCampoConteudo: 8));

            if (ViewModel.CalculoIssqn.Mostrar)
            {
                AdicionarBloco <BlocoCalculoIssqn>();
            }

            AdicionarMetadata();

            _FoiGerado = false;
        }
Пример #23
0
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
              string filePath = PromptFileChoice("Please select a PDF file");
              using(File file = new File(filePath))
              {
            Document document = file.Document;

            // 2. Named objects extraction.
            Names names = document.Names;
            if(!names.Exists())
            {Console.WriteLine("\nNo names dictionary.");}
            else
            {
              Console.WriteLine("\nNames dictionary found (" + names.DataContainer.Reference + ")");

              NamedDestinations namedDestinations = names.Destinations;
              if(!namedDestinations.Exists())
              {Console.WriteLine("\nNo named destinations.");}
              else
              {
            Console.WriteLine("\nNamed destinations found (" + namedDestinations.DataContainer.Reference + ")");

            // Parsing the named destinations...
            foreach(KeyValuePair<PdfString,Destination> namedDestination in namedDestinations)
            {
              PdfString key = namedDestination.Key;
              Destination value = namedDestination.Value;

              Console.WriteLine("  Destination '" + key + "' (" + value.DataContainer.Reference + ")");

              Console.Write("    Target Page: number = ");
              object pageRef = value.Page;
              if(pageRef is Int32) // NOTE: numeric page refs are typical of remote destinations.
              {Console.WriteLine(((int)pageRef) + 1);}
              else // NOTE: explicit page refs are typical of local destinations.
              {
                Page page = (Page)pageRef;
                Console.WriteLine((page.Index + 1) + "; ID = " + ((PdfReference)page.BaseObject).Id);
              }
            }

            Console.WriteLine("Named destinations count = " + namedDestinations.Count);
              }
            }
              }
        }
Пример #24
0
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
              string filePath = PromptFileChoice("Please select a PDF file");
              using(File file = new File(filePath))
              {
            Document document = file.Document;

            // 2. Stamp the document!
            Stamp(document);

            // 3. Serialize the PDF file!
            Serialize(file, "Page numbering", "numbering a document's pages", "page numbering");
              }
        }
Пример #25
0
 public override void Run(
     )
 {
     // 1. Opening the PDF file...
       string filePath = PromptFileChoice("Please select a PDF file");
       using(File file = new File(filePath))
       {
     // 2. Printing the document...
     Renderer renderer = new Renderer();
     bool silent = false;
     if(renderer.Print(file.Document, silent))
     {Console.WriteLine("Print fulfilled.");}
     else
     {Console.WriteLine("Print discarded.");}
       }
 }
Пример #26
0
        public override void Run(
            )
        {
            // 1. Instantiate a new PDF file!
              /* NOTE: a File object is the low-level (syntactic) representation of a PDF file. */
              File file = new File();

              // 2. Get its corresponding document!
              /* NOTE: a Document object is the high-level (semantic) representation of a PDF file. */
              Document document = file.Document;

              // 3. Insert the contents into the document!
              Populate(document);

              // 4. Serialize the PDF file!
              Serialize(file, "Hello world", "a simple 'hello world'", "Hello world");
        }
Пример #27
0
        public DanfeEventoService(DanfeEventoViewModel viewModel)
        {
            ViewModel = viewModel ?? throw new ArgumentNullException(nameof(viewModel));

            _file       = new File();
            Blocos      = new List <BlocoEventoBase>();
            PdfDocument = _file.Document;

            // De acordo com o item 7.7, a fonte deve ser Times New Roman ou Courier New.
            var fonteFamilia = StandardType1Font.FamilyEnum.Times;

            _fonteRegular = new StandardType1Font(PdfDocument, fonteFamilia, false, false);
            _fonteNegrito = new StandardType1Font(PdfDocument, fonteFamilia, true, false);
            _fonteItalico = new StandardType1Font(PdfDocument, fonteFamilia, false, true);

            EstiloPadrao = CriarEstilo();
            EstiloPadrao.FonteBlocoCabecalho.Tamanho = 10;

            var estiloInformacao = CriarEstilo(tFonteCampoConteudo: 12f);

            estiloInformacao.FonteBlocoCabecalho.Tamanho = 10;

            Paginas = new List <DanfeEventoPagina>();

            AdicionarBloco <BlocoEventoCabecalho>();
            AdicionarBloco <BlocoEventoIdentificacao>();
            AdicionarBloco <BlocoEventoDados>();

            switch (viewModel.TipoEvento)
            {
            case NFeTipoEvento.CartaCorrecao:
                AdicionarBloco <BlocoEventoCartaCorrecaoCondicao>();
                AdicionarBloco <BlocoEventoCartaCorrecao>(estiloInformacao);
                break;

            case NFeTipoEvento.Cancelamento:
            case NFeTipoEvento.CancelamentoST:
                AdicionarBloco <BlocoEventoCancelamento>(estiloInformacao);
                break;
            }

            AdicionarMetadata();
            _FoiGerado = false;
        }
Пример #28
0
        public override void Run(
            )
        {
            string outputFilePath;
              {
            // 1. Opening the PDF file...
            string filePath = PromptFileChoice("Please select a PDF file");
            using(File file = new File(filePath))
            {
              Document document = file.Document;

              // 2. Defining the page labels...
              PageLabels pageLabels = document.PageLabels;
              pageLabels.Clear();
              /*
            NOTE: This sample applies labels to arbitrary page ranges: no sensible connection with their
            actual content has therefore to be expected.
              */
              int pageCount = document.Pages.Count;
              pageLabels[new PdfInteger(0)] = new PageLabel(document, "Introduction ", PageLabel.NumberStyleEnum.UCaseRomanNumber, 5);
              if(pageCount > 3)
              {pageLabels[new PdfInteger(3)] = new PageLabel(document, PageLabel.NumberStyleEnum.UCaseLetter);}
              if(pageCount > 6)
              {pageLabels[new PdfInteger(6)] = new PageLabel(document, "Contents ", PageLabel.NumberStyleEnum.ArabicNumber, 0);}

              // 3. Serialize the PDF file!
              outputFilePath = Serialize(file, "Page labelling", "labelling a document's pages", "page labels");
            }
              }

              {
            using(File file = new File(outputFilePath))
            {
              foreach(KeyValuePair<PdfInteger,PageLabel> entry in file.Document.PageLabels)
              {
            Console.WriteLine("Page label " + entry.Value.BaseObject);
            Console.WriteLine("    Initial page: " + (entry.Key.IntValue + 1));
            Console.WriteLine("    Prefix: " + (entry.Value.Prefix));
            Console.WriteLine("    Number style: " + (entry.Value.NumberStyle));
            Console.WriteLine("    Number base: " + (entry.Value.NumberBase));
              }
            }
              }
        }
Пример #29
0
        public override void Run(
            )
        {
            // 1. Instantiate a new PDF file!
              File file = new File();
              Document document = file.Document;

              // 2. Insert the contents into the document!
              BuildCurvesPage(document);
              BuildMiscellaneousPage(document);
              BuildSimpleTextPage(document);
              BuildTextBlockPage(document);
              BuildTextBlockPage2(document);
              BuildTextBlockPage3(document);
              BuildTextBlockPage4(document);

              // 3. Serialize the PDF file!
              Serialize(file, "Composition elements", "applying the composition elements", "graphics, line styles, text alignment, shapes, circles, ellipses, spirals, polygons, rounded rectangles, images, clipping");
        }
Пример #30
0
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
              string filePath = PromptFileChoice("Please select a PDF file");
              using(File file = new File(filePath))
              {
            Document document = file.Document;

            // 2. Parsing the document...
            Console.WriteLine("\nLooking for images...");
            foreach(Page page in document.Pages)
            {
              Scan(
            new ContentScanner(page), // Wraps the page contents into the scanner.
            page
            );
            }
              }
        }
Пример #31
0
        static void cleanPdf(String path, String filename)
        {
            using (org.pdfclown.files.File file = new org.pdfclown.files.File(path + filename))
            {
                Document    document = file.Document;
                Information info     = document.Information;
                if (info.Exists())
                {
                    document.Information.Clear();
                }

                Metadata metadata = document.Metadata;
                if (metadata.Exists())
                {
                    metadata.Content.RemoveAll();
                }

                document.File.Save(pathOut + filename, SerializationModeEnum.Standard);
            }
        }
Пример #32
0
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
              string filePath = PromptFileChoice("Please select a PDF file");
              using(File file = new File(filePath))
              {
            Document document = file.Document;

            // 2. Get the bookmarks collection!
            Bookmarks bookmarks = document.Bookmarks;
            if(!bookmarks.Exists())
            {Console.WriteLine("\nNo bookmark available (Outline dictionary not found).");}
            else
            {
              Console.WriteLine("\nIterating through the bookmarks collection (please wait)...\n");
              // 3. Show the bookmarks!
              PrintBookmarks(bookmarks);
            }
              }
        }
Пример #33
0
        /**
          <summary>Removes indirect objects which have no reference in the document structure.</summary>
          <param name="file">File to optimize.</param>
        */
        public static void RemoveOrphanedObjects(
            File file
            )
        {
            // 1. Collecting alive indirect objects...
              ISet<int> aliveObjectNumbers = new HashSet<int>();
              {
            // Alive indirect objects collector.
            IVisitor visitor = new AliveObjectCollector(aliveObjectNumbers);
            // Walk through the document structure to collect alive indirect objects!
            file.Trailer.Accept(visitor, null);
              }

              // 2. Removing orphaned indirect objects...
              IndirectObjects indirectObjects = file.IndirectObjects;
              for(int objectNumber = 0, objectCount = indirectObjects.Count; objectNumber < objectCount; objectNumber++)
              {
            if(!aliveObjectNumbers.Contains(objectNumber))
            {indirectObjects.RemoveAt(objectNumber);}
              }
        }
Пример #34
0
        public override void Run(
            )
        {
            // 1. Opening the form source file...
              string filePath = PromptFileChoice("Please select a PDF file to use as form");
              using(File formFile = new File(filePath))
              {
            // 2. Instantiate a new PDF file!
            File file = new File();
            Document document = file.Document;

            // 3. Convert the first page of the source file into a form inside the new document!
            XObject form = formFile.Document.Pages[0].ToXObject(document);

            // 4. Insert the contents into the new document!
            Populate(document,form);

            // 5. Serialize the PDF file!
            Serialize(file, "Page-to-form", "converting a page to a reusable form", "page to form");
              }
        }
Пример #35
0
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
              string filePath = PromptFileChoice("Please select a PDF file");
              using(File file = new File(filePath))
              {
            Document document = file.Document;
            Pages pages = document.Pages;

            // 2. Page rasterization.
            int pageIndex = PromptPageChoice("Select the page to render", pages.Count);
            Page page = pages[pageIndex];
            SizeF imageSize = page.Size;
            Renderer renderer = new Renderer();
            Image image = renderer.Render(page, imageSize);

            // 3. Save the page image!
            image.Save(GetOutputPath("ContentRenderingSample.jpg"), ImageFormat.Jpeg);
              }
        }
Пример #36
0
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
              string filePath = PromptFileChoice("Please select a PDF file");
              using(File file = new File(filePath))
              {
            Document document = file.Document;

            // 2. Get the layer definition!
            LayerDefinition layerDefinition = document.Layer;
            if(!layerDefinition.Exists())
            {Console.WriteLine("\nNo layer definition available.");}
            else
            {
              Console.WriteLine("\nIterating through the layers...\n");

              // 3. Parse the layer hierarchy!
              Parse(layerDefinition.Layers,0);
            }
              }
        }
Пример #37
0
        private void createPDF()
        {
            SaveFileDialog saveFileDialog2 = new SaveFileDialog();

            saveFileDialog2.Filter   = "PDF File|*.pdf";
            saveFileDialog2.Title    = "Save as PDF";
            saveFileDialog2.FileName = "" + profile.fname + " " + profile.sname + " 6CIT Results";

            File     file     = new File();
            Document document = file.Document;
            Page     page     = new Page(document);

            document.Pages.Add(page);

            PrimitiveComposer Composer = new PrimitiveComposer(page);

            Composer.SetLineWidth(200);

            //Image
            Image image = Image.Get("brain100.jpg");

            org.pdfclown.documents.contents.xObjects.XObject imageXObject = image.ToXObject(document);
            Composer.ShowXObject(imageXObject, new PointF(450, 40));
            Composer.Flush();

            //Title
            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 32);
            Composer.ShowText("6CIT Results", new PointF(32, 40));

            //Heading 1
            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 24);
            Composer.ShowText("Patient Details", new PointF(32, 100));

            //Heading 1 - Body
            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 12);
            Composer.ShowText("NHS ID: " + profile.ID, new PointF(32, 140));
            Composer.ShowText("Name: " + profile.fname + " " + profile.sname, new PointF(32, 160));
            Composer.ShowText("Sex: " + profile.sex, new PointF(32, 180));
            Composer.ShowText("DOB: " + profile.DOB, new PointF(32, 200));
            Composer.ShowText("Address: " + profile.al1 + " " + profile.al2, new PointF(32, 220));
            Composer.ShowText("Postcode: " + profile.postcode, new PointF(32, 240));
            Composer.ShowText("Occupation: " + profile.occupation, new PointF(32, 260));
            Composer.ShowText("Test Score: " + score + " , Advice: " + calcAdvice(score), new PointF(32, 300));


            //Patient Notes
            BlockComposer bc = new BlockComposer(Composer);

            bc.Hyphenation = false;
            bc.LineSpace   = new Length(1.0, Length.UnitModeEnum.Relative);

            int notesLength = profile.notes.Length;
            int notesHeight = 40;
            int notesY      = 320;

            if (notesLength < 300)
            {
                notesHeight = 150;
            }
            else if (notesLength > 300 && notesLength < 600)
            {
                notesHeight = 200;
            }
            else if (notesLength > 600 && notesLength <= 1000)
            {
                notesHeight = 350;
            }

            RectangleF area = new RectangleF(new PointF(32, notesY), new SizeF(400, notesHeight));

            bc.Begin(area, XAlignmentEnum.Left, YAlignmentEnum.Top);
            bc.ShowText("Notes: " + "\n" + profile.notes);
            bc.End();

            Composer.Flush();

            var date = DateTime.Now;

            //Add Page 2
            Page page2 = new Page(document);

            document.Pages.Add(page2);
            Composer = new PrimitiveComposer(page2);

            //Heading 2
            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 24);
            Composer.ShowText("6CIT Results ", new PointF(32, 40));

            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 12);
            Composer.ShowText("Test Carried out on: " /*+ Clinician Details Input Get*/ + " on: " + date, new PointF(32, 80));

            //Convert Question Answers to Temporary Text
            string six_q1_txt = "Incorrect";
            string six_q2_txt = "Incorrect";
            string six_q3_txt = "Incorrect";
            string six_q4_txt = "Incorrect";
            string six_q5_txt = "Incorrect";
            string six_q6_txt;

            if (q1 == 0)
            {
                six_q1_txt = "Correct";
            }
            if (q2 == 0)
            {
                six_q2_txt = "Correct";
            }
            if (q3 == 0)
            {
                six_q3_txt = "Correct";
            }

            //Q4
            if (q4 == 0)
            {
                six_q4_txt = "Correct";
            }
            else if (q4 == 4)
            {
                six_q4_txt = "More Than One Incorrect";
            }

            //Q5
            if (q5 == 0)
            {
                six_q5_txt = "Correct";
            }
            else if (q5 == 2)
            {
                six_q5_txt = "One Incorrect";
            }
            else if (q5 == 4)
            {
                six_q5_txt = "More Than One Incorrect";
            }

            //Q6
            if (q6 == 0)
            {
                six_q6_txt = "Correct";
            }
            else if (q6 == 2)
            {
                six_q6_txt = "One Incorrect";
            }
            else if (q6 == 4)
            {
                six_q6_txt = "More Than One Incorrect";
            }
            else if (q6 == 6)
            {
                six_q6_txt = "More Than Two Incorrect";
            }
            else if (q6 == 8)
            {
                six_q6_txt = "More Than Three Incorrect";
            }
            else if (q6 == 10)
            {
                six_q6_txt = "More Than Four Incorrect";
            }
            else
            {
                six_q6_txt = "All Incorrect";
            }

            Composer.ShowText("Question 1: What Year Is It? : ", new PointF(32, 120));
            Composer.ShowText(six_q1_txt, new PointF(32, 140));

            Composer.ShowText("Question 2: What Month Is It? : ", new PointF(32, 180));
            Composer.ShowText(six_q2_txt, new PointF(32, 200));

            Composer.ShowText("Question 3: What Time Is It? : ", new PointF(32, 240));
            Composer.ShowText(six_q3_txt, new PointF(32, 260));

            Composer.ShowText("Question 4: Count Backwards From 20 to 1: ", new PointF(32, 300));
            Composer.ShowText(six_q4_txt, new PointF(32, 320));

            Composer.ShowText("Question 5: Say The Months of the Year Backwards: ", new PointF(32, 360));
            Composer.ShowText(six_q5_txt, new PointF(32, 380));

            Composer.ShowText("Question 6: Repeat the Memory Phrase: ", new PointF(32, 420));
            Composer.ShowText(six_q6_txt, new PointF(32, 440));

            Composer.ShowText("Test Result was:  " + score, new PointF(32, 480));
            Composer.ShowText("Advice: " + calcAdvice(score), new PointF(32, 500));

            Composer.Flush();

            if (saveFileDialog2.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    file.Save(saveFileDialog2.FileName, SerializationModeEnum.Incremental);
                }
                catch (IOException)
                {
                    MessageBox.Show("File is open somewhere else; Cannot Save to PDF.");
                }
            }
        }
Пример #38
-1
        public override void Run(
            )
        {
            // 1. PDF file instantiation.
              File file = new File();
              Document document = file.Document;

              // 2. Content creation.
              Populate(document);

              // 3. Serialize the PDF file!
              Serialize(file, "Standard Type 1 fonts", "applying standard Type 1 fonts", "Standard Type1 fonts");
        }