public static void Run()
        {
            // ExStart:IllustrationStructureElements
            // 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");

            // Under Development
            IllustrationElement figure1 = taggedContent.CreateFigureElement();

            taggedContent.RootElement.AppendChild(figure1);
            figure1.AlternativeText = "Figure One";
            figure1.Title           = "Image 1";
            figure1.SetTag("Fig1");
            figure1.SetImage("image.png");

            // Save Tagged Pdf Document
            document.Save(dataDir + "IllustrationStructureElements.pdf");
            // ExEnd:IllustrationStructureElements
        }
        public static void Run()
        {
            // ExStart:CreatePDFwithTaggedImage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            Document       document      = new Document();
            ITaggedContent taggedContent = document.TaggedContent;

            taggedContent.SetTitle("CreatePDFwithTaggedImage");
            taggedContent.SetLanguage("en-US");

            IllustrationElement figure1 = taggedContent.CreateFigureElement();

            taggedContent.RootElement.AppendChild(figure1);
            figure1.AlternativeText = "Aspose Logo";
            figure1.Title           = "Image 1";
            figure1.SetTag("Fig");
            // Add image with resolution 300 DPI (by default)
            figure1.SetImage(dataDir + @"aspose-logo.jpg");

            // Save PDF Document
            document.Save(dataDir + "PDFwithTaggedImage.pdf");
            // ExEnd:CreatePDFwithTaggedImage
        }
        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
        }
        private static FigureElement ExtractToFigureElement(ITaggedContent taggedContent, Page page, int imageIndex)
        {
            ImagePlacementAbsorber imagePlacementAbsorber = new ImagePlacementAbsorber();

            page.Accept(imagePlacementAbsorber);
            XImage xImage = imagePlacementAbsorber.ImagePlacements[imageIndex].Image;

            FileStream outputImage = new FileStream("temp-image.png", FileMode.Create);

            xImage.Save(outputImage, ImageFormat.Png);
            outputImage.Close();

            FigureElement figureElement = taggedContent.CreateFigureElement();

            figureElement.SetImage("temp-image.png");
            figureElement.AlternativeText = "Aspose logo";

            return(figureElement);
        }
Beispiel #5
0
        public static void Run()
        {
            // ExStart:LinkStructureElements
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
            string outFile = dataDir + "LinkStructureElements_Output.pdf";
            string logFile = dataDir + "46035_log.xml";
            string imgFile = dataDir + "google-icon-512.png";

            // Creation document and getting Tagged Pdf Content
            Document       document      = new Document();
            ITaggedContent taggedContent = document.TaggedContent;


            // Setting Title and Nature Language for document
            taggedContent.SetTitle("Link Elements Example");
            taggedContent.SetLanguage("en-US");

            // Getting Root structure element (Document structure element)
            StructureElement rootElement = taggedContent.RootElement;


            ParagraphElement p1 = taggedContent.CreateParagraphElement();

            rootElement.AppendChild(p1);
            LinkElement link1 = taggedContent.CreateLinkElement();

            p1.AppendChild(link1);
            link1.Hyperlink = new WebHyperlink("http://google.com");
            link1.SetText("Google");
            link1.AlternateDescriptions = "Link to Google";


            ParagraphElement p2 = taggedContent.CreateParagraphElement();

            rootElement.AppendChild(p2);
            LinkElement link2 = taggedContent.CreateLinkElement();

            p2.AppendChild(link2);
            link2.Hyperlink = new WebHyperlink("http://google.com");
            SpanElement span2 = taggedContent.CreateSpanElement();

            span2.SetText("Google");
            link2.AppendChild(span2);
            link2.AlternateDescriptions = "Link to Google";


            ParagraphElement p3 = taggedContent.CreateParagraphElement();

            rootElement.AppendChild(p3);
            LinkElement link3 = taggedContent.CreateLinkElement();

            p3.AppendChild(link3);
            link3.Hyperlink = new WebHyperlink("http://google.com");
            SpanElement span31 = taggedContent.CreateSpanElement();

            span31.SetText("G");
            SpanElement span32 = taggedContent.CreateSpanElement();

            span32.SetText("oogle");
            link3.AppendChild(span31);
            link3.SetText("-");
            link3.AppendChild(span32);
            link3.AlternateDescriptions = "Link to Google";


            ParagraphElement p4 = taggedContent.CreateParagraphElement();

            rootElement.AppendChild(p4);
            LinkElement link4 = taggedContent.CreateLinkElement();

            p4.AppendChild(link4);
            link4.Hyperlink = new WebHyperlink("http://google.com");
            link4.SetText("The multiline link: Google Google Google Google Google Google Google Google Google Google Google Google Google Google Google Google Google Google Google Google");
            link4.AlternateDescriptions = "Link to Google (multiline)";


            ParagraphElement p5 = taggedContent.CreateParagraphElement();

            rootElement.AppendChild(p5);
            LinkElement link5 = taggedContent.CreateLinkElement();

            p5.AppendChild(link5);
            link5.Hyperlink = new WebHyperlink("http://google.com");
            FigureElement figure5 = taggedContent.CreateFigureElement();

            figure5.SetImage(imgFile, 1200);
            figure5.AlternativeText = "Google icon";
            StructureAttributes linkLayoutAttributes = link5.Attributes.GetAttributes(AttributeOwnerStandard.Layout);
            StructureAttribute  placementAttribute   = new StructureAttribute(AttributeKey.Placement);

            placementAttribute.SetNameValue(AttributeName.Placement_Block);
            linkLayoutAttributes.SetAttribute(placementAttribute);
            link5.AppendChild(figure5);
            link5.AlternateDescriptions = "Link to Google";


            // 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:LinkStructureElements
        }