Esempio n. 1
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. 2
0
        /// <summary>
        /// This feature is supported by version 19.6 or greater
        /// </summary>
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
            // Create document
            Document       document      = new Document();
            ITaggedContent taggedContent = document.TaggedContent;

            taggedContent.SetTitle("Example table row style");
            taggedContent.SetLanguage("en-US");

            // Get root structure element
            StructureElement rootElement = taggedContent.RootElement;


            // Create table structure element
            TableElement tableElement = taggedContent.CreateTableElement();

            rootElement.AppendChild(tableElement);


            TableTHeadElement tableTHeadElement = tableElement.CreateTHead();
            TableTBodyElement tableTBodyElement = tableElement.CreateTBody();
            TableTFootElement tableTFootElement = tableElement.CreateTFoot();
            int rowCount = 7;
            int colCount = 3;
            int rowIndex;
            int colIndex;

            TableTRElement headTrElement = tableTHeadElement.CreateTR();

            headTrElement.AlternativeText = "Head Row";

            for (colIndex = 0; colIndex < colCount; colIndex++)
            {
                TableTHElement thElement = headTrElement.CreateTH();
                thElement.SetText(String.Format("Head {0}", colIndex));
            }

            for (rowIndex = 0; rowIndex < rowCount; rowIndex++)
            {
                TableTRElement trElement = tableTBodyElement.CreateTR();
                trElement.AlternativeText = String.Format("Row {0}", rowIndex);

                trElement.BackgroundColor = Color.LightGoldenrodYellow;
                trElement.Border          = new BorderInfo(BorderSide.All, 0.75F, Color.DarkGray);

                trElement.DefaultCellBorder = new BorderInfo(BorderSide.All, 0.50F, Color.Blue);
                trElement.MinRowHeight      = 100.0;
                trElement.FixedRowHeight    = 120.0;
                trElement.IsInNewPage       = (rowIndex % 3 == 1);
                trElement.IsRowBroken       = true;

                TextState cellTextState = new TextState();
                cellTextState.ForegroundColor  = Color.Red;
                trElement.DefaultCellTextState = cellTextState;

                trElement.DefaultCellPadding = new MarginInfo(16.0, 2.0, 8.0, 2.0);
                trElement.VerticalAlignment  = VerticalAlignment.Bottom;

                for (colIndex = 0; colIndex < colCount; colIndex++)
                {
                    TableTDElement tdElement = trElement.CreateTD();
                    tdElement.SetText(String.Format("Cell [{0}, {1}]", rowIndex, colIndex));
                }
            }

            TableTRElement footTrElement = tableTFootElement.CreateTR();

            footTrElement.AlternativeText = "Foot Row";

            for (colIndex = 0; colIndex < colCount; colIndex++)
            {
                TableTDElement tdElement = footTrElement.CreateTD();
                tdElement.SetText(String.Format("Foot {0}", colIndex));
            }



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

            // Checking PDF/UA compliance
            document = new Document(dataDir + "StyleTableRow.pdf");
            bool isPdfUaCompliance = document.Validate(dataDir + "StyleTableRow.xml", PdfFormat.PDF_UA_1);

            Console.WriteLine(String.Format("PDF/UA compliance: {0}", isPdfUaCompliance));

            // ExEnd:1
        }
        /// <summary>
        /// This feature is supported by version 19.6 or greater
        /// </summary>
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
            // Create document
            Document       document      = new Document();
            ITaggedContent taggedContent = document.TaggedContent;

            taggedContent.SetTitle("Example table style");
            taggedContent.SetLanguage("en-US");

            // Get root structure element
            StructureElement rootElement = taggedContent.RootElement;


            // Create table structure element
            TableElement tableElement = taggedContent.CreateTableElement();

            rootElement.AppendChild(tableElement);


            tableElement.BackgroundColor    = Color.Beige;
            tableElement.Border             = new BorderInfo(BorderSide.All, 0.80F, Color.Gray);
            tableElement.Alignment          = HorizontalAlignment.Center;
            tableElement.Broken             = TableBroken.Vertical;
            tableElement.ColumnAdjustment   = ColumnAdjustment.AutoFitToWindow;
            tableElement.ColumnWidths       = "80 80 80 80 80";
            tableElement.DefaultCellBorder  = new BorderInfo(BorderSide.All, 0.50F, Color.DarkBlue);
            tableElement.DefaultCellPadding = new MarginInfo(16.0, 2.0, 8.0, 2.0);
            tableElement.DefaultCellTextState.ForegroundColor = Color.DarkCyan;
            tableElement.DefaultCellTextState.FontSize        = 8F;
            tableElement.DefaultColumnWidth = "70";

            tableElement.IsBroken          = false;
            tableElement.IsBordersIncluded = true;

            tableElement.Left = 0F;
            tableElement.Top  = 40F;

            tableElement.RepeatingColumnsCount = 2;
            tableElement.RepeatingRowsCount    = 3;
            TextState rowStyle = new TextState();

            rowStyle.BackgroundColor        = Color.LightCoral;
            tableElement.RepeatingRowsStyle = rowStyle;



            TableTHeadElement tableTHeadElement = tableElement.CreateTHead();
            TableTBodyElement tableTBodyElement = tableElement.CreateTBody();
            TableTFootElement tableTFootElement = tableElement.CreateTFoot();
            int rowCount = 10;
            int colCount = 5;
            int rowIndex;
            int colIndex;

            TableTRElement headTrElement = tableTHeadElement.CreateTR();

            headTrElement.AlternativeText = "Head Row";

            for (colIndex = 0; colIndex < colCount; colIndex++)
            {
                TableTHElement thElement = headTrElement.CreateTH();
                thElement.SetText(String.Format("Head {0}", colIndex));
            }

            for (rowIndex = 0; rowIndex < rowCount; rowIndex++)
            {
                TableTRElement trElement = tableTBodyElement.CreateTR();
                trElement.AlternativeText = String.Format("Row {0}", rowIndex);

                for (colIndex = 0; colIndex < colCount; colIndex++)
                {
                    TableTDElement tdElement = trElement.CreateTD();
                    tdElement.SetText(String.Format("Cell [{0}, {1}]", rowIndex, colIndex));
                }
            }

            TableTRElement footTrElement = tableTFootElement.CreateTR();

            footTrElement.AlternativeText = "Foot Row";

            for (colIndex = 0; colIndex < colCount; colIndex++)
            {
                TableTDElement tdElement = footTrElement.CreateTD();
                tdElement.SetText(String.Format("Foot {0}", colIndex));
            }

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



            // Checking PDF/UA compliance
            document = new Document(dataDir + "StyleTableElement.pdf");
            bool isPdfUaCompliance = document.Validate(dataDir + "StyleTableElement.xml", PdfFormat.PDF_UA_1);

            Console.WriteLine(String.Format("PDF/UA compliance: {0}", isPdfUaCompliance));

            // ExEnd:1
        }
Esempio n. 4
0
        /// <summary>
        /// This feature is supported by version 19.6 or greater
        /// </summary>
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
            // Create document
            Document       document      = new Document();
            ITaggedContent taggedContent = document.TaggedContent;

            taggedContent.SetTitle("Example table cell style");
            taggedContent.SetLanguage("en-US");

            // Get root structure element
            StructureElement rootElement = taggedContent.RootElement;


            // Create table structure element
            TableElement tableElement = taggedContent.CreateTableElement();

            rootElement.AppendChild(tableElement);


            TableTHeadElement tableTHeadElement = tableElement.CreateTHead();
            TableTBodyElement tableTBodyElement = tableElement.CreateTBody();
            TableTFootElement tableTFootElement = tableElement.CreateTFoot();
            int rowCount = 4;
            int colCount = 4;
            int rowIndex;
            int colIndex;

            TableTRElement headTrElement = tableTHeadElement.CreateTR();

            headTrElement.AlternativeText = "Head Row";

            for (colIndex = 0; colIndex < colCount; colIndex++)
            {
                TableTHElement thElement = headTrElement.CreateTH();
                thElement.SetText(String.Format("Head {0}", colIndex));

                thElement.BackgroundColor = Color.GreenYellow;
                thElement.Border          = new BorderInfo(BorderSide.All, 4.0F, Color.Gray);

                thElement.IsNoBorder = true;
                thElement.Margin     = new MarginInfo(16.0, 2.0, 8.0, 2.0);

                thElement.Alignment = HorizontalAlignment.Right;
            }

            for (rowIndex = 0; rowIndex < rowCount; rowIndex++)
            {
                TableTRElement trElement = tableTBodyElement.CreateTR();
                trElement.AlternativeText = String.Format("Row {0}", rowIndex);

                for (colIndex = 0; colIndex < colCount; colIndex++)
                {
                    int colSpan = 1;
                    int rowSpan = 1;

                    if (colIndex == 1 && rowIndex == 1)
                    {
                        colSpan = 2;
                        rowSpan = 2;
                    }
                    else if (colIndex == 2 && (rowIndex == 1 || rowIndex == 2))
                    {
                        continue;
                    }
                    else if (rowIndex == 2 && (colIndex == 1 || colIndex == 2))
                    {
                        continue;
                    }

                    TableTDElement tdElement = trElement.CreateTD();
                    tdElement.SetText(String.Format("Cell [{0}, {1}]", rowIndex, colIndex));


                    tdElement.BackgroundColor = Color.Yellow;
                    tdElement.Border          = new BorderInfo(BorderSide.All, 4.0F, Color.Gray);

                    tdElement.IsNoBorder = false;
                    tdElement.Margin     = new MarginInfo(8.0, 2.0, 8.0, 2.0);

                    tdElement.Alignment = HorizontalAlignment.Center;

                    TextState cellTextState = new TextState();
                    cellTextState.ForegroundColor  = Color.DarkBlue;
                    cellTextState.FontSize         = 7.5F;
                    cellTextState.FontStyle        = FontStyles.Bold;
                    cellTextState.Font             = FontRepository.FindFont("Arial");
                    tdElement.DefaultCellTextState = cellTextState;

                    tdElement.IsWordWrapped     = true;
                    tdElement.VerticalAlignment = VerticalAlignment.Center;

                    tdElement.ColSpan = colSpan;
                    tdElement.RowSpan = rowSpan;
                }
            }

            TableTRElement footTrElement = tableTFootElement.CreateTR();

            footTrElement.AlternativeText = "Foot Row";

            for (colIndex = 0; colIndex < colCount; colIndex++)
            {
                TableTDElement tdElement = footTrElement.CreateTD();
                tdElement.SetText(String.Format("Foot {0}", colIndex));
            }


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

            // Checking PDF/UA compliance
            document = new Document(dataDir + "StyleTableCell.pdf");
            bool isPdfUaCompliance = document.Validate(dataDir + "StyleTableCell.xml", PdfFormat.PDF_UA_1);

            Console.WriteLine(String.Format("PDF/UA compliance: {0}", isPdfUaCompliance));
        }