private void DrawSimulatedDiv(PdfPage page, IDictionary <int, Object> styles, float[] margins, bool drawBackground
                                      , int pageNumber, bool recalculateBodyAreaForContentSize)
        {
            Div pageBordersSimulation = new Div().SetFillAvailableArea(true);

            foreach (KeyValuePair <int, Object> entry in styles)
            {
                if ((entry.Key == Property.BACKGROUND || entry.Key == Property.BACKGROUND_IMAGE) && !drawBackground)
                {
                    continue;
                }
                pageBordersSimulation.SetProperty(entry.Key, entry.Value);
            }
            pageBordersSimulation.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT);
            Rectangle backgroundArea = new Rectangle(page.GetTrimBox()).ApplyMargins(margins[0], margins[1], margins[2
                                                                                     ], margins[3], false);

            if (recalculateBodyAreaForContentSize)
            {
                if (pageStylesPropertiesMap.Get(pageNumber).lowestAndHighest == null)
                {
                    return;
                }
                HtmlBodyStylesApplierHandler.LowestAndHighest lowestAndHighest = pageStylesPropertiesMap.Get(pageNumber).lowestAndHighest;
                RecalculateBackgroundAreaForBody(backgroundArea, pageBordersSimulation, lowestAndHighest);
            }
            if (pdfCanvas == null)
            {
                pdfCanvas = new PdfCanvas(page.NewContentStreamBefore(), page.GetResources(), page.GetDocument());
            }
            iText.Layout.Canvas canvas = new iText.Layout.Canvas(pdfCanvas, backgroundArea);
            canvas.EnableAutoTagging(page);
            canvas.Add(pageBordersSimulation);
            canvas.Close();
        }
 /// <summary>Draws page border.</summary>
 /// <param name="page">the page</param>
 private void DrawPageBorders(PdfPage page)
 {
     if (pageBordersSimulation == null)
     {
         return;
     }
     iText.Layout.Canvas canvas = new iText.Layout.Canvas(new PdfCanvas(page), page.GetTrimBox());
     canvas.EnableAutoTagging(page);
     canvas.Add(pageBordersSimulation);
     canvas.Close();
 }
Beispiel #3
0
 /// <summary>Draws page background and borders.</summary>
 /// <param name="page">the page</param>
 private void DrawPageBackgroundAndBorders(PdfPage page)
 {
     iText.Layout.Canvas canvas = new iText.Layout.Canvas(new PdfCanvas(page), page.GetBleedBox());
     canvas.EnableAutoTagging(page);
     canvas.Add(pageBackgroundSimulation);
     canvas.Close();
     canvas = new iText.Layout.Canvas(new PdfCanvas(page), page.GetTrimBox());
     canvas.EnableAutoTagging(page);
     canvas.Add(pageBordersSimulation);
     canvas.Close();
 }
        /// <summary>Draws page background.</summary>
        /// <param name="page">the page</param>
        /// <returns>pdfCanvas instance if there was a background to draw, otherwise returns null</returns>
        internal virtual PdfCanvas DrawPageBackground(PdfPage page)
        {
            PdfCanvas pdfCanvas = null;

            if (pageBackgroundSimulation != null)
            {
                pdfCanvas = new PdfCanvas(page.NewContentStreamBefore(), page.GetResources(), page.GetDocument());
                iText.Layout.Canvas canvas = new iText.Layout.Canvas(pdfCanvas, page.GetBleedBox());
                canvas.EnableAutoTagging(page);
                canvas.Add(pageBackgroundSimulation);
                canvas.Close();
            }
            return(pdfCanvas);
        }
Beispiel #5
0
        public virtual void CanvasWithPageEnableTaggingTest02()
        {
            String      testName = "canvasWithPageEnableTaggingTest02";
            String      @out     = destinationFolder + testName + ".pdf";
            String      cmp      = sourceFolder + "cmp_" + testName + ".pdf";
            PdfDocument pdf      = new PdfDocument(new PdfWriter(@out));

            pdf.SetTagged();
            PdfPage   page      = pdf.AddNewPage();
            Rectangle pageSize  = page.GetPageSize();
            Rectangle rectangle = new Rectangle(pageSize.GetX() + 36, pageSize.GetTop() - 80, pageSize.GetWidth() - 72
                                                , 50);

            iText.Layout.Canvas canvas = new iText.Layout.Canvas(page, rectangle);
            // This will disable tagging and also prevent annotations addition. Created tagged document is invalid. Expected log message.
            canvas.EnableAutoTagging(null);
            canvas.Add(new Paragraph(new Link("Google link!", PdfAction.CreateURI("https://www.google.com")).SetUnderline
                                         ().SetFontColor(ColorConstants.BLUE)));
            canvas.Close();
            pdf.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(@out, cmp, destinationFolder));
        }