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

            // Create Pdf Document
            Document document = new Document();

            // Get Content for work with TaggedPdf
            ITaggedContent taggedContent = document.TaggedContent;

            // Set Title and Language for Documnet
            taggedContent.SetTitle("Tagged Pdf Document");
            taggedContent.SetLanguage("en-US");

            ParagraphElement p = taggedContent.CreateParagraphElement();

            taggedContent.RootElement.AppendChild(p);

            // Under Development
            p.StructureTextState.FontSize        = 18F;
            p.StructureTextState.ForegroundColor = Color.Red;
            p.StructureTextState.FontStyle       = FontStyles.Italic;

            p.SetText("Red italic text.");

            // Save Tagged Pdf Document
            document.Save(dataDir + "StyleTextStructure.pdf");
            // ExEnd:StyleTextStructure
        }
Esempio n. 2
0
 private static void ProcessParagraphElement(ParagraphElement p, XmlWriter xmlw)
 {
     xmlw.WriteStartElement("ParagraphElement");
     xmlw.WriteAttributeString("Kind", p.Kind.ToStringSafe());
     ProcessFontColor(p.FontColor, xmlw);
     xmlw.WriteEndElement();
 }
Esempio n. 3
0
        public static void Run()
        {
            // ExStart:TextStructureElements
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            // Create Pdf Document
            Document document = new Document();

            // Get Content for work with TaggedPdf
            ITaggedContent taggedContent = document.TaggedContent;

            // Set Title and Language for Documnet
            taggedContent.SetTitle("Tagged Pdf Document");
            taggedContent.SetLanguage("en-US");

            // Get Root Structure Elements
            StructureElement rootElement = taggedContent.RootElement;

            ParagraphElement p = taggedContent.CreateParagraphElement();

            // Set Text to Text Structure Element
            p.SetText("Paragraph.");
            rootElement.AppendChild(p);


            // Save Tagged Pdf Document
            document.Save(dataDir + "TextStructureElement.pdf");
            // ExEnd:TextStructureElements
        }
Esempio n. 4
0
 private static void ProcessParagraphElement(ParagraphElement p, Utf8JsonWriter jsonw)
 {
     jsonw.WriteStartObject();
     jsonw.WriteString("Kind", p.Kind.ToStringSafe());
     ProcessFontColor(p.FontColor, jsonw);
     jsonw.WriteEndObject();
 }
Esempio n. 5
0
        private static string ReadParagraphElement(ParagraphElement element)
        {
            TextRun run    = element.TextRun;
            string  result = run?.Content ?? "";

            return(result);
        }
Esempio n. 6
0
        public static void TestMarkElement()
        {
            var root = Document.GetElementById("qunit-fixture");

            var markElement1 = new MarkElement();

            Assert.NotNull(markElement1, "MarkElement created");
            Assert.AreEqual(markElement1.TagName, "MARK");

            var p = new ParagraphElement();

            root.AppendChild(p);

            markElement1.Id = "markElement1";
            p.AppendChild(markElement1);
            markElement1.InnerHTML = "I'm highlighted";

            var m1 = Document.GetElementById("markElement1");

            Assert.AreEqual("I'm highlighted", m1.InnerHTML, "m1.InnerHTML");

            var markElement2 = new MarkElement();

            markElement2.Id = "markElement2";
            p.AppendChild(markElement2);
            markElement2.InnerHTML = "Me too";

            var m2 = Document.GetElementById("markElement2");

            Assert.AreEqual("Me too", m2.InnerHTML, "m2.InnerHTML");
        }
Esempio n. 7
0
        public void ProcessDocument(DocumentDef doc)
        {
            Contract.Requires(doc != null);

            paragraphsStack.Clear();
            OnDocumentBegin(doc);

            foreach (IDocumentElement el in doc.Children)
            {
                ParagraphElement paragraphEl = el as ParagraphElement;
                HeadingElement   headingEl   = el as HeadingElement;

                if (paragraphEl != null)
                {
                    ProcessParagraphElement(paragraphEl);
                }
                else if (headingEl != null)
                {
                    ProcessHeadingElement(headingEl);
                }
                else
                {
                    throw new NotImplementedException("todo next: {0}".Fmt(el.GetType().Name));
                }
            }

            EnsureParagraphStackIsCleared();

            OnDocumentEnd(doc);
        }
Esempio n. 8
0
        private void ProcessParagraphContents(ParagraphElement paragraphEl)
        {
            Contract.Requires(paragraphEl != null);

            foreach (IDocumentElement el in paragraphEl.Children)
            {
                TextElement         textEl         = el as TextElement;
                InternalLinkElement internalLinkEl = el as InternalLinkElement;
                ExternalLinkElement externalLinkEl = el as ExternalLinkElement;

                if (textEl != null)
                {
                    ProcessTextElement(textEl);
                }
                else if (internalLinkEl != null)
                {
                    ProcessInternalLinkElement(internalLinkEl);
                }
                else if (externalLinkEl != null)
                {
                    ProcessExternalLinkElement(externalLinkEl);
                }
                else
                {
                    throw new NotImplementedException("todo next:");
                }
            }
        }
        public static void Run()
        {
            // ExStart:CreateStructureElements
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            // Create Pdf Document
            Document document = new Document();

            // Get Content for work with TaggedPdf
            ITaggedContent taggedContent = document.TaggedContent;

            // Set Title and Language for Documnet
            taggedContent.SetTitle("Tagged Pdf Document");
            taggedContent.SetLanguage("en-US");

            // Create Grouping Elements
            PartElement       partElement       = taggedContent.CreatePartElement();
            ArtElement        artElement        = taggedContent.CreateArtElement();
            SectElement       sectElement       = taggedContent.CreateSectElement();
            DivElement        divElement        = taggedContent.CreateDivElement();
            BlockQuoteElement blockQuoteElement = taggedContent.CreateBlockQuoteElement();
            CaptionElement    captionElement    = taggedContent.CreateCaptionElement();
            TOCElement        tocElement        = taggedContent.CreateTOCElement();
            TOCIElement       tociElement       = taggedContent.CreateTOCIElement();
            IndexElement      indexElement      = taggedContent.CreateIndexElement();
            NonStructElement  nonStructElement  = taggedContent.CreateNonStructElement();
            PrivateElement    privateElement    = taggedContent.CreatePrivateElement();

            // Create Text Block-Level Structure Elements
            ParagraphElement paragraphElement = taggedContent.CreateParagraphElement();
            HeaderElement    headerElement    = taggedContent.CreateHeaderElement();
            HeaderElement    h1Element        = taggedContent.CreateHeaderElement(1);

            // Create Text Inline-Level Structure Elements
            SpanElement  spanElement  = taggedContent.CreateSpanElement();
            QuoteElement quoteElement = taggedContent.CreateQuoteElement();
            NoteElement  noteElement  = taggedContent.CreateNoteElement();

            // Create Illustration Structure Elements
            FigureElement  figureElement  = taggedContent.CreateFigureElement();
            FormulaElement formulaElement = taggedContent.CreateFormulaElement();

            // Methods are under development
            ListElement      listElement      = taggedContent.CreateListElement();
            TableElement     tableElement     = taggedContent.CreateTableElement();
            ReferenceElement referenceElement = taggedContent.CreateReferenceElement();
            BibEntryElement  bibEntryElement  = taggedContent.CreateBibEntryElement();
            CodeElement      codeElement      = taggedContent.CreateCodeElement();
            LinkElement      linkElement      = taggedContent.CreateLinkElement();
            AnnotElement     annotElement     = taggedContent.CreateAnnotElement();
            RubyElement      rubyElement      = taggedContent.CreateRubyElement();
            WarichuElement   warichuElement   = taggedContent.CreateWarichuElement();
            FormElement      formElement      = taggedContent.CreateFormElement();

            // Save Tagged Pdf Document
            document.Save(dataDir + "StructureElements.pdf");
            // ExEnd:CreateStructureElements
        }
Esempio n. 10
0
        public static void Show(string titleText, string bodyText)
        {
            ParagraphElement bodyContent = new ParagraphElement();

            bodyContent.InnerHTML = bodyText;

            ShowDlgWithContent(titleText, bodyContent);
        }
Esempio n. 11
0
        public static void Run()
        {
            // ExStart:CreateNoteStructureElement
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
            string outFile = dataDir + "45929_doc.pdf";
            string logFile = dataDir + "45929_log.xml";

            // Create Pdf Document
            Document       document      = new Document();
            ITaggedContent taggedContent = document.TaggedContent;

            taggedContent.SetTitle("Sample of Note Elements");
            taggedContent.SetLanguage("en-US");

            // Add Paragraph Element
            ParagraphElement paragraph = taggedContent.CreateParagraphElement();

            taggedContent.RootElement.AppendChild(paragraph);

            // Add NoteElement
            NoteElement note1 = taggedContent.CreateNoteElement();

            paragraph.AppendChild(note1);
            note1.SetText("Note with auto generate ID. ");

            // Add NoteElement
            NoteElement note2 = taggedContent.CreateNoteElement();

            paragraph.AppendChild(note2);
            note2.SetText("Note with ID = 'note_002'. ");
            note2.SetId("note_002");

            // Add NoteElement
            NoteElement note3 = taggedContent.CreateNoteElement();

            paragraph.AppendChild(note3);
            note3.SetText("Note with ID = 'note_003'. ");
            note3.SetId("note_003");

            // Must throw exception - Aspose.Pdf.Tagged.TaggedException : Structure element with ID='note_002' already exists
            //note3.SetId("note_002");

            // Resultant document does not compliance to PDF/UA If ClearId() used for Note Structure Element
            //note3.ClearId();


            // Save Tagged Pdf Document
            document.Save(outFile);

            // Checking PDF/UA compliance
            document = new Document(outFile);
            bool isPdfUaCompliance = document.Validate(logFile, PdfFormat.PDF_UA_1);

            Console.WriteLine(String.Format("PDF/UA compliance: {0}", isPdfUaCompliance));
            // ExEnd:CreateNoteStructureElement
        }
Esempio n. 12
0
        protected override void OnParagraphBegin(ParagraphElement el)
        {
            if (el.Indentation > 0)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "{0}-{1}".Fmt(CssParagraphIndentClass, el.Indentation));
            }

            writer.RenderBeginTag(HtmlTextWriterTag.P);
        }
Esempio n. 13
0
 /// <summary>Visits the provided <paramref name="paragraph"/> element.</summary>
 /// <param name="paragraph">The <see cref="ParagraphElement"/> to visit.</param>
 protected internal override void Visit(ParagraphElement paragraph)
 {
     BeginElement("p");
     foreach (var element in paragraph.Content)
     {
         element.Accept(this);
     }
     EndElementWithoutIndent();
 }
Esempio n. 14
0
        private void ProcessRegularParagraphElement(ParagraphElement paragraphEl)
        {
            Contract.Requires(paragraphEl != null);

            EnsureParagraphStackIsCleared();

            OnParagraphBegin(paragraphEl);
            ProcessParagraphContents(paragraphEl);
            OnParagraphEnd(paragraphEl);
        }
Esempio n. 15
0
        public void StartNewParagraph(ParagraphElement.ParagraphType paragraphType, int indentation)
        {
            Contract.Requires(indentation >= 0);

            FinalizeCurrentParagraph();

            currentParagraph          = new ParagraphElement(paragraphType, indentation);
            currentParagraphTextStyle = TextElement.TextStyle.Regular;
            doc.AddChild(currentParagraph);
        }
Esempio n. 16
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
            string inFile  = dataDir + "TH.pdf";
            string outFile = dataDir + "TH_out.pdf";
            string logFile = dataDir + "TH_out.xml";

            // Open document
            Document document = new Document(inFile);

            // Gets tagged content and root structure element
            ITaggedContent   taggedContent = document.TaggedContent;
            StructureElement rootElement   = taggedContent.RootElement;

            // Set title for tagged pdf document
            taggedContent.SetTitle("Document with images");

            foreach (FigureElement figureElement in rootElement.FindElements <FigureElement>(true))
            {
                // Set Alternative Text  for Figure
                figureElement.AlternativeText = "Figure alternative text (technique 2)";


                // Create and Set BBox Attribute
                StructureAttribute bboxAttribute = new StructureAttribute(AttributeKey.BBox);
                bboxAttribute.SetRectangleValue(new Rectangle(0.0, 0.0, 100.0, 100.0));

                StructureAttributes figureLayoutAttributes = figureElement.Attributes.GetAttributes(AttributeOwnerStandard.Layout);
                figureLayoutAttributes.SetAttribute(bboxAttribute);
            }

            // Move Span Element into Paragraph (find wrong span and paragraph in first TD)
            TableElement     tableElement   = rootElement.FindElements <TableElement>(true)[0];
            SpanElement      spanElement    = tableElement.FindElements <SpanElement>(true)[0];
            TableTDElement   firstTdElement = tableElement.FindElements <TableTDElement>(true)[0];
            ParagraphElement paragraph      = firstTdElement.FindElements <ParagraphElement>(true)[0];

            // Move Span Element into Paragraph
            spanElement.ChangeParentElement(paragraph);


            // Save document
            document.Save(outFile);



            // Checking PDF/UA Compliance for out document
            document = new Document(outFile);

            bool isPdfUaCompliance = document.Validate(logFile, PdfFormat.PDF_UA_1);

            Console.WriteLine(String.Format("PDF/UA compliance: {0}", isPdfUaCompliance));
        }
Esempio n. 17
0
        private void CreateParagraphIfNoneIsAlreadyOpen()
        {
            if (currentParagraph != null)
            {
                return;
            }

            currentParagraph          = new ParagraphElement(ParagraphElement.ParagraphType.Regular, 0);
            currentParagraphTextStyle = currentParagraphTextStyle ?? TextElement.TextStyle.Regular;
            doc.AddChild(currentParagraph);
        }
Esempio n. 18
0
        private static void ProcessBody(BodyElement bodyElement, Body xmlBody)
        {
            var xmlBodyElements = xmlBody.Elements();

            foreach (var xmlBodyElement in xmlBodyElements)
            {
                if (xmlBodyElement is Paragraph xmlParagraph)
                {
                    var paragraphElement = new ParagraphElement();
                    ProcessParagraph(paragraphElement, xmlParagraph);
                    bodyElement.AddElement(paragraphElement);
                }
            }
        }
Esempio n. 19
0
        private void ProcessNumberedParagraphElement(ParagraphElement paragraphEl)
        {
            Contract.Requires(paragraphEl != null);

            bool beginsNewList = EnsureParagraphStackIsClearedUntil(paragraphEl);

            if (beginsNewList)
            {
                OnNumberedListBegin(paragraphEl);
            }

            OnNumberedListItemBegin(paragraphEl);
            ProcessParagraphContents(paragraphEl);
        }
Esempio n. 20
0
        private static void AddTextElementToParagraph(
            ParagraphElement paragraph,
            string text,
            TextElement.TextStyle currentStyle,
            bool insertSpaceBefore)
        {
            Contract.Requires(paragraph != null);
            Contract.Requires(text != null);
            TextElement newStyleChild = CreateTextElement(
                insertSpaceBefore ? ' ' + text : text,
                currentStyle);

            paragraph.AddChild(newStyleChild);
        }
Esempio n. 21
0
        public static void Run()
        {
            // ExStart:TextBlockStructureElements
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            // Create Pdf Document
            Document document = new Document();

            // Get Content for work with TaggedPdf
            ITaggedContent taggedContent = document.TaggedContent;

            // Set Title and Language for Documnet
            taggedContent.SetTitle("Tagged Pdf Document");
            taggedContent.SetLanguage("en-US");

            // Get Root Structure Element
            StructureElement rootElement = taggedContent.RootElement;

            HeaderElement h1 = taggedContent.CreateHeaderElement(1);
            HeaderElement h2 = taggedContent.CreateHeaderElement(2);
            HeaderElement h3 = taggedContent.CreateHeaderElement(3);
            HeaderElement h4 = taggedContent.CreateHeaderElement(4);
            HeaderElement h5 = taggedContent.CreateHeaderElement(5);
            HeaderElement h6 = taggedContent.CreateHeaderElement(6);

            h1.SetText("H1. Header of Level 1");
            h2.SetText("H2. Header of Level 2");
            h3.SetText("H3. Header of Level 3");
            h4.SetText("H4. Header of Level 4");
            h5.SetText("H5. Header of Level 5");
            h6.SetText("H6. Header of Level 6");
            rootElement.AppendChild(h1);
            rootElement.AppendChild(h2);
            rootElement.AppendChild(h3);
            rootElement.AppendChild(h4);
            rootElement.AppendChild(h5);
            rootElement.AppendChild(h6);

            ParagraphElement p = taggedContent.CreateParagraphElement();

            p.SetText("P. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean nec lectus ac sem faucibus imperdiet. Sed ut erat ac magna ullamcorper hendrerit. Cras pellentesque libero semper, gravida magna sed, luctus leo. Fusce lectus odio, laoreet nec ullamcorper ut, molestie eu elit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam lacinia sit amet elit ac consectetur. Donec cursus condimentum ligula, vitae volutpat sem tristique eget. Nulla in consectetur massa. Vestibulum vitae lobortis ante. Nulla ullamcorper pellentesque justo rhoncus accumsan. Mauris ornare eu odio non lacinia. Aliquam massa leo, rhoncus ac iaculis eget, tempus et magna. Sed non consectetur elit. Sed vulputate, quam sed lacinia luctus, ipsum nibh fringilla purus, vitae posuere risus odio id massa. Cras sed venenatis lacus.");
            rootElement.AppendChild(p);

            // Save Tagged Pdf Document
            document.Save(dataDir + "TextBlockStructureElements.pdf");

            // ExEnd:TextBlockStructureElements
        }
Esempio n. 22
0
        private static Node InsideParagraph(List <Node> elementList, string paragraphID = null)
        {
            var currentParagraphElement = new ParagraphElement();

            if (!String.IsNullOrWhiteSpace(paragraphID))
            {
                currentParagraphElement.Id = paragraphID;
            }

            foreach (var element in elementList)
            {
                currentParagraphElement.AppendChild(element);
            }

            return(currentParagraphElement);
        }
        public static void Run()
        {
            // ExStart:CreatePDFwithTaggedText
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            // Create Pdf Document
            Document document = new Document();

            // Get Content for work with TaggedPdf
            ITaggedContent taggedContent = document.TaggedContent;

            // Set Title and Language for Documnet
            taggedContent.SetTitle("Tagged Pdf Document");
            taggedContent.SetLanguage("en-US");

            // Create Text Block-Level Structure Elements
            HeaderElement headerElement = taggedContent.CreateHeaderElement();

            headerElement.ActualText = "Heading 1";
            ParagraphElement paragraphElement1 = taggedContent.CreateParagraphElement();

            paragraphElement1.ActualText = "test1";
            ParagraphElement paragraphElement2 = taggedContent.CreateParagraphElement();

            paragraphElement2.ActualText = "test 2";
            ParagraphElement paragraphElement3 = taggedContent.CreateParagraphElement();

            paragraphElement3.ActualText = "test 3";
            ParagraphElement paragraphElement4 = taggedContent.CreateParagraphElement();

            paragraphElement4.ActualText = "test 4";
            ParagraphElement paragraphElement5 = taggedContent.CreateParagraphElement();

            paragraphElement5.ActualText = "test 5";
            ParagraphElement paragraphElement6 = taggedContent.CreateParagraphElement();

            paragraphElement6.ActualText = "test 6";
            ParagraphElement paragraphElement7 = taggedContent.CreateParagraphElement();

            paragraphElement7.ActualText = "test 7";

            // Save PDF Document
            document.Save(dataDir + "PDFwithTaggedText.pdf");
            // ExEnd:CreatePDFwithTaggedText
        }
        private static ParagraphElement ExtractToParagraphElement(ITaggedContent taggedContent, Page page, int textIndex)
        {
            TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber();

            page.Accept(textFragmentAbsorber);

            TextFragment originalText = textFragmentAbsorber.TextFragments[textIndex];

            ParagraphElement p = taggedContent.CreateParagraphElement();

            p.StructureTextState.ForegroundColor = originalText.TextState.ForegroundColor;
            Font paraFont = FontRepository.FindFont(originalText.TextState.Font.FontName);

            paraFont.IsEmbedded       = true;
            p.StructureTextState.Font = paraFont;
            p.SetText(originalText.Text);

            return(p);
        }
Esempio n. 25
0
        public static Element GetRepeatRegion()
        {
            var itemsSpan = new SpanElement();

            itemsSpan.InnerHTML = "Checkpoint";
            var itemsPara = new ParagraphElement();

            itemsPara.InnerHTML = "{{checkpoint.callsign}}[{{checkpoint.id}}]";

            var itemsLI = new LIElement();

            itemsLI.SetNGRepeat("checkpoint", "checkpoints");
            itemsLI.AppendChild(itemsSpan);
            itemsLI.AppendChild(itemsPara);

            var itemsUL = new UListElement();

            itemsUL.AppendChild(itemsLI);

            var itemsSubSpan = new SpanElement()
            {
                InnerHTML = "[{{checkpoint.callsign}}.{{checkpoint.id}}] "
            };

            var itemsSearchBox = new InputElement();

            itemsSearchBox.SetNGModel("cpFilter");

            var itemsOrderSelector = GetOrderBySelector("cpOrderBy");

            itemsSubSpan.SetNGRepeat("checkpoint", "checkpoints",
                                     itemsSearchBox.GetNGModel(), itemsOrderSelector.GetNGModel());

            var itemsDiv = new DivElement();

            itemsDiv.SetNGController("hwbSctl");
            itemsDiv.AppendChild(itemsUL);
            itemsDiv.AppendChild(itemsSearchBox);
            itemsDiv.AppendChild(itemsOrderSelector);
            itemsDiv.AppendChild(itemsSubSpan);

            return(itemsDiv);
        }
Esempio n. 26
0
        private static void ProcessParagraph(ParagraphElement paragraphElement, Paragraph xmlParagraph)
        {
            var xmlParagraphElements = xmlParagraph.Elements();

            foreach (var xmlParagraphElement in xmlParagraphElements)
            {
                if (xmlParagraphElement is Run run)
                {
                    var xmlRunElements = run.Elements();
                    foreach (var xmlRunElement in xmlRunElements)
                    {
                        if (xmlRunElement is Text text)
                        {
                            var textElement = new TextElement(text.Text);
                            paragraphElement.AddElement(textElement);
                        }
                    }
                }
            }
        }
        static void Main()
        {
            var inputFileName  = "non-compliant.pdf";
            var outputFileName = "compliant.pdf";

            // Use some helper functions to create an example non-PDf/UA-compliant PDF
            Helpers.CreateDemoNonCompliantPdfFile(inputFileName);
            using (var d = new Document(inputFileName))
            {
                bool isValid = d.Validate("non-compliant-validation-log.xml", Aspose.Pdf.PdfFormat.PDF_UA_1);
            }

            var originalDocument = new Document(inputFileName);
            var pageOne          = originalDocument.Pages[1];

            // Create our new tagged document
            var              taggedDocument = new Document();
            ITaggedContent   taggedContent  = taggedDocument.TaggedContent;
            StructureElement rootElement    = taggedContent.RootElement;

            // Set meta data required by PDF/UA
            taggedContent.SetTitle("Our compliant document.");
            taggedContent.SetLanguage("en-US");

            // Extract from original PDF and create new structured elements for tagged PDF
            HeaderElement    h1            = ExtractToHeaderElement(taggedContent, pageOne, 1, 1);
            ParagraphElement p             = ExtractToParagraphElement(taggedContent, pageOne, 2);
            FigureElement    figureElement = ExtractToFigureElement(taggedContent, pageOne, 1);

            // Append to new tagged content in desired order, which will build structure tree up from the 'root'
            rootElement.AppendChild(h1);
            rootElement.AppendChild(figureElement);
            rootElement.AppendChild(p);

            // Save and validate the compliant PDF
            taggedDocument.Save(outputFileName);
            using (var d = new Document(outputFileName))
            {
                bool isValid = d.Validate("compliant-validation-log.xml", Aspose.Pdf.PdfFormat.PDF_UA_1);
            }
        }
Esempio n. 28
0
        private void ProcessParagraphElement(ParagraphElement paragraphEl)
        {
            Contract.Requires(paragraphEl != null);

            switch (paragraphEl.Type)
            {
            case ParagraphElement.ParagraphType.Regular:
                ProcessRegularParagraphElement(paragraphEl);
                break;

            case ParagraphElement.ParagraphType.Bulleted:
                ProcessBulletedParagraphElement(paragraphEl);
                break;

            case ParagraphElement.ParagraphType.Numbered:
                ProcessNumberedParagraphElement(paragraphEl);
                break;

            default:
                throw new NotSupportedException();
            }
        }
Esempio n. 29
0
        private void EnsureParagraphStackIsCleared()
        {
            while (paragraphsStack.Count > 0)
            {
                ParagraphElement stackedParagraph = paragraphsStack.Pop();

                switch (stackedParagraph.Type)
                {
                case ParagraphElement.ParagraphType.Bulleted:
                    OnBulletListItemEnd(stackedParagraph);
                    OnBulletListEnd(stackedParagraph);
                    break;

                case ParagraphElement.ParagraphType.Numbered:
                    OnNumberedListItemEnd(stackedParagraph);
                    OnNumberedListEnd(stackedParagraph);
                    break;

                default:
                    throw new InvalidOperationException("BUG");
                }
            }
        }
Esempio n. 30
0
        Paragraph GetParagraph(ParagraphElement paragraph)
        {
            var para = new Paragraph();
            var run  = new Run();

            var paraProps = new ParagraphProperties();

            if (paragraph.Style != null && paragraph.Style.HorizontalAlignment.HasValue)
            {
                paraProps.Append(new Justification
                {
                    Val = new EnumValue <JustificationValues>((JustificationValues)paragraph.Style.HorizontalAlignment.Value)
                });
            }

            foreach (TextElement text in paragraph.Elements)
            {
                var style = text.Style;

                if (style == null)
                {
                    style = paragraph.Style;
                }

                if (style != null)
                {
                    var props = new RunProperties();
                    run.Append(props);

                    if (!string.IsNullOrWhiteSpace(style.ForegroundColor))
                    {
                        props.Append(new Color()
                        {
                            Val = style.ForegroundColor
                        });
                    }

                    if (!string.IsNullOrWhiteSpace(style.FontName))
                    {
                        props.Append(new RunFonts
                        {
                            Ascii = style.FontName
                        });
                    }

                    if (style.FontSize.HasValue)
                    {
                        props.Append(new FontSize
                        {
                            Val = $"{style.FontSize.Value * 2}"
                        });
                    }

                    if (style.Bold == true)
                    {
                        props.Append(new Bold());
                    }

                    if (style.Italic == true)
                    {
                        props.Append(new Italic());
                    }
                }

                run.Append(GetConcatenatedText(text));
            }

            para.Append(paraProps);
            para.Append(run);

            return(para);
        }