public void CreateTaggedPdf19() { InitializeDocument("19"); PdfDiv div = new PdfDiv(); writer.DirectContent.OpenMCBlock(div); PdfArtifact artifact = new PdfArtifact(); artifact.Type = new PdfString("Rectangle"); writer.DirectContent.OpenMCBlock(artifact); writer.DirectContent.SetColorFill(BaseColor.RED); writer.DirectContent.Rectangle(100, 100, 400, 400); writer.DirectContent.Fill(); writer.DirectContent.CloseMCBlock(artifact); writer.DirectContent.CloseMCBlock(div); document.Close(); CompareResults("19"); }
/** Finishes writing the table. * @param canvases the array returned by <CODE>beginWritingRows()</CODE> */ public static void EndWritingRows(PdfContentByte[] canvases) { PdfContentByte canvas = canvases[BASECANVAS]; PdfArtifact artifact = new PdfArtifact(); canvas.OpenMCBlock(artifact); canvas.SaveState(); canvas.Add(canvases[BACKGROUNDCANVAS]); canvas.RestoreState(); canvas.SaveState(); canvas.SetLineCap(2); canvas.ResetRGBColorStroke(); canvas.Add(canvases[LINECANVAS]); canvas.RestoreState(); canvas.CloseMCBlock(artifact); canvas.Add(canvases[TEXTCANVAS]); }
virtual public int Layout(PdfContentByte canvas, bool useAscender, bool simulate, float llx, float lly, float urx, float ury) { float leftX = Math.Min(llx, urx); float maxY = Math.Max(lly, ury); float minY = Math.Min(lly, ury); float rightX = Math.Max(llx, urx); yLine = maxY; bool contentCutByFixedHeight = false; if (width != null && width > 0) { if (width < rightX - leftX) { rightX = leftX + (float)width; } else if (width > rightX - leftX) { return(ColumnText.NO_MORE_COLUMN); } } else if (percentageWidth != null) { contentWidth = (rightX - leftX) * (float)percentageWidth; rightX = leftX + contentWidth; } else if (percentageWidth == null) { if (this.floatType == FloatType.NONE && (this.display == DisplayType.DEFAULT_NULL_VALUE || this.display == DisplayType.BLOCK || this.display == DisplayType.LIST_ITEM || this.display == DisplayType.RUN_IN)) { contentWidth = rightX - leftX; } } if (height != null && height > 0) { if (height < maxY - minY) { contentCutByFixedHeight = true; minY = maxY - (float)height; } else if (height > maxY - minY) { return(ColumnText.NO_MORE_COLUMN); } } else if (percentageHeight != null) { if (percentageHeight < 1.0) { contentCutByFixedHeight = true; } contentHeight = (maxY - minY) * (float)percentageHeight; minY = maxY - contentHeight; } if (!simulate && position == PdfDiv.PositionType.RELATIVE) { float?translationX = null; if (left != null) { translationX = left; } else if (right != null) { translationX = -right; } else { translationX = 0f; } float?translationY = null; if (top != null) { translationY = -top; } else if (bottom != null) { translationY = bottom; } else { translationY = 0f; } canvas.SaveState(); canvas.Transform(new AffineTransform(1f, 0, 0, 1f, translationX.Value, translationY.Value)); } if (!simulate) { if ((backgroundColor != null || backgroundImage != null) && getActualWidth() > 0 && getActualHeight() > 0) { float backgroundWidth = getActualWidth(); float backgroundHeight = getActualHeight(); if (width != null) { backgroundWidth = width > 0 ? (float)width : 0; } if (height != null) { backgroundHeight = height > 0 ? (float)height : 0; } if (backgroundWidth > 0 && backgroundHeight > 0) { Rectangle background = new Rectangle(leftX, maxY - backgroundHeight, leftX + backgroundWidth, maxY); if (backgroundColor != null) { background.BackgroundColor = backgroundColor; PdfArtifact artifact = new PdfArtifact(); canvas.OpenMCBlock(artifact); canvas.Rectangle(background); canvas.CloseMCBlock(artifact); } if (backgroundImage != null) { if (backgroundImageWidth == null) { backgroundImage.ScaleToFit(background); } else { backgroundImage.ScaleAbsolute((float)backgroundImageWidth, backgroundImageHeight); } backgroundImage.SetAbsolutePosition(background.Left, background.Bottom); canvas.OpenMCBlock(backgroundImage); canvas.AddImage(backgroundImage); canvas.CloseMCBlock(backgroundImage); } } } } if (percentageWidth == null) { contentWidth = 0; } if (percentageHeight == null) { contentHeight = 0; } minY += paddingBottom; leftX += paddingLeft; rightX -= paddingRight; yLine -= paddingTop; int status = ColumnText.NO_MORE_TEXT; if (content.Count > 0) { if (floatLayout == null) { List <IElement> floatingElements = new List <IElement>(content); floatLayout = new FloatLayout(floatingElements, useAscender); floatLayout.RunDirection = runDirection; } floatLayout.SetSimpleColumn(leftX, minY, rightX, yLine); if (borderTopStyle != BorderTopStyle.NONE) { floatLayout.compositeColumn.IgnoreSpacingBefore = false; } status = floatLayout.Layout(canvas, simulate); yLine = floatLayout.YLine; if (percentageWidth == null && contentWidth < floatLayout.FilledWidth) { contentWidth = floatLayout.FilledWidth; } } if (!simulate && position == PdfDiv.PositionType.RELATIVE) { canvas.RestoreState(); } yLine -= paddingBottom; if (percentageHeight == null) { contentHeight = maxY - yLine; } if (percentageWidth == null) { contentWidth += paddingLeft + paddingRight; } return(contentCutByFixedHeight ? ColumnText.NO_MORE_TEXT : status); }
virtual public int Layout(PdfContentByte canvas, bool useAscender, bool simulate, float llx, float lly, float urx, float ury) { float leftX = Math.Min(llx, urx); float maxY = Math.Max(lly, ury); float minY = Math.Min(lly, ury); float rightX = Math.Max(llx, urx); yLine = maxY; bool contentCutByFixedHeight = false; if (width != null && width > 0) { if (width < rightX - leftX) rightX = leftX + (float) width; else if (width > rightX - leftX) return ColumnText.NO_MORE_COLUMN; } else if (percentageWidth != null) { contentWidth = (rightX - leftX)*(float) percentageWidth; rightX = leftX + contentWidth; } if (height != null && height > 0) { if (height < maxY - minY) { contentCutByFixedHeight = true; minY = maxY - (float) height; } else if (height > maxY - minY) { return ColumnText.NO_MORE_COLUMN; } } else if (percentageHeight != null) { if (percentageHeight < 1.0) contentCutByFixedHeight = true; contentHeight = (maxY - minY)*(float) percentageHeight; minY = maxY - contentHeight; } if (!simulate && position == PdfDiv.PositionType.RELATIVE) { float? translationX = null; if (left != null) translationX = left; else if (right != null) translationX = -right; else translationX = 0f; float? translationY = null; if (top != null) translationY = -top; else if (bottom != null) translationY = bottom; else translationY = 0f; canvas.SaveState(); canvas.Transform(new AffineTransform(1f, 0, 0, 1f, translationX.Value, translationY.Value)); } if (!simulate) { if (backgroundColor != null && getActualWidth() > 0 && getActualHeight() > 0) { float backgroundWidth = getActualWidth(); float backgroundHeight = getActualHeight(); if (width != null) backgroundWidth = width > 0 ? (float) width : 0; if (height != null) backgroundHeight = height > 0 ? (float) height : 0; if (backgroundWidth > 0 && backgroundHeight > 0) { Rectangle background = new Rectangle(leftX, maxY - backgroundHeight, leftX + backgroundWidth, maxY); background.BackgroundColor = backgroundColor; PdfArtifact artifact = new PdfArtifact(); canvas.OpenMCBlock(artifact); canvas.Rectangle(background); canvas.CloseMCBlock(artifact); } } } if (percentageWidth == null) contentWidth = 0; if (percentageHeight == null) contentHeight = 0; minY += paddingBottom; leftX += paddingLeft; rightX -= paddingRight; yLine -= paddingTop; int status = ColumnText.NO_MORE_TEXT; if (content.Count > 0) { if (floatLayout == null) { List<IElement> floatingElements = new List<IElement>(content); floatLayout = new FloatLayout(floatingElements, useAscender); } floatLayout.SetSimpleColumn(leftX, minY, rightX, yLine); status = floatLayout.Layout(canvas, simulate); yLine = floatLayout.YLine; if (percentageWidth == null && contentWidth < floatLayout.FilledWidth) contentWidth = floatLayout.FilledWidth; } if (!simulate && position == PdfDiv.PositionType.RELATIVE) canvas.RestoreState(); yLine -= paddingBottom; if (percentageHeight == null) contentHeight = maxY - yLine; if (percentageWidth == null) contentWidth += paddingLeft + paddingRight; return contentCutByFixedHeight ? ColumnText.NO_MORE_TEXT : status; }
public void StamperTextTest() { PdfReader reader = new PdfReader(RESOURCES + "pdfa1.pdf"); PdfAStamper stamper = new PdfAStamper(reader, new FileStream(OUT + "stamperTextTest.pdf", FileMode.Create), PdfAConformanceLevel.PDF_A_1A); PdfArtifact artifact = new PdfArtifact(); BaseFont bf = BaseFont.CreateFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED); artifact.SetType(PdfArtifact.ArtifactType.LAYOUT); PdfContentByte canvas = stamper.GetOverContent(1); canvas.OpenMCBlock(artifact); canvas.BeginText(); canvas.SetFontAndSize(bf, 120); canvas.ShowTextAligned(Element.ALIGN_CENTER, "TEST", 200, 400, 45); canvas.EndText(); canvas.CloseMCBlock(artifact); stamper.Close(); reader.Close(); }
/** * Adds a form XObject to this content. * * @param formXObj the form XObject * @param name the name of form XObject in content stream * @param a an element of the transformation matrix * @param b an element of the transformation matrix * @param c an element of the transformation matrix * @param d an element of the transformation matrix * @param e an element of the transformation matrix * @param f an element of the transformation matrix */ public virtual void AddFormXObj(PdfStream formXObj, PdfName name, float a, float b, float c, float d, float e, float f) { CheckWriter(); PdfWriter.CheckPdfIsoConformance(writer, PdfIsoKeys.PDFISOKEY_STREAM, formXObj); PageResources prs = PageResources; prs.AddXObject(name, writer.AddToBody(formXObj).IndirectReference); PdfArtifact artifact = null; if (IsTagged()) { if (inText) EndText(); artifact = new PdfArtifact(); OpenMCBlock(artifact); } content.Append("q "); content.Append(a).Append(' '); content.Append(b).Append(' '); content.Append(c).Append(' '); content.Append(d).Append(' '); content.Append(e).Append(' '); content.Append(f).Append(" cm "); content.Append(name.GetBytes()).Append(" Do Q").Append_i(separator); if (IsTagged()) { CloseMCBlock(artifact); } }
virtual public void SetType(PdfArtifact.ArtifactType type) { PdfString artifactType = null; switch (type) { case ArtifactType.BACKGROUND: artifactType = new PdfString("Background"); break; case ArtifactType.LAYOUT: artifactType = new PdfString("Layout"); break; case ArtifactType.PAGE: artifactType = new PdfString("Page"); break; case ArtifactType.PAGINATION: artifactType = new PdfString("Pagination"); break; } SetAccessibleAttribute(PdfName.TYPE, artifactType); }
virtual public int Layout(PdfContentByte canvas, bool useAscender, bool simulate, float llx, float lly, float urx, float ury) { float leftX = Math.Min(llx, urx); float maxY = Math.Max(lly, ury); float minY = Math.Min(lly, ury); float rightX = Math.Max(llx, urx); yLine = maxY; bool contentCutByFixedHeight = false; if (width != null && width > 0) { if (width < rightX - leftX) { rightX = leftX + (float)width; } else if (width > rightX - leftX) { return(ColumnText.NO_MORE_COLUMN); } } else if (percentageWidth != null) { contentWidth = (rightX - leftX) * (float)percentageWidth; rightX = leftX + contentWidth; } if (height != null && height > 0) { if (height < maxY - minY) { contentCutByFixedHeight = true; minY = maxY - (float)height; } else if (height > maxY - minY) { return(ColumnText.NO_MORE_COLUMN); } } else if (percentageHeight != null) { if (percentageHeight < 1.0) { contentCutByFixedHeight = true; } contentHeight = (maxY - minY) * (float)percentageHeight; minY = maxY - contentHeight; } if (!simulate && position == PdfDiv.PositionType.RELATIVE) { float?translationX = null; if (left != null) { translationX = left; } else if (right != null) { translationX = -right; } else { translationX = 0f; } float?translationY = null; if (top != null) { translationY = -top; } else if (bottom != null) { translationY = bottom; } else { translationY = 0f; } canvas.SaveState(); canvas.Transform(new AffineTransform(1f, 0, 0, 1f, translationX.Value, translationY.Value)); } if (!simulate) { if (backgroundColor != null && getActualWidth() > 0 && getActualHeight() > 0) { float backgroundWidth = getActualWidth(); float backgroundHeight = getActualHeight(); if (width != null) { backgroundWidth = width > 0 ? (float)width : 0; } if (height != null) { backgroundHeight = height > 0 ? (float)height : 0; } if (backgroundWidth > 0 && backgroundHeight > 0) { Rectangle background = new Rectangle(leftX, maxY - backgroundHeight, leftX + backgroundWidth, maxY); background.BackgroundColor = backgroundColor; PdfArtifact artifact = new PdfArtifact(); canvas.OpenMCBlock(artifact); canvas.Rectangle(background); canvas.CloseMCBlock(artifact); } } } if (percentageWidth == null) { contentWidth = 0; } if (percentageHeight == null) { contentHeight = 0; } minY += paddingBottom; leftX += paddingLeft; rightX -= paddingRight; yLine -= paddingTop; int status = ColumnText.NO_MORE_TEXT; if (content.Count > 0) { if (floatLayout == null) { List <IElement> floatingElements = new List <IElement>(content); floatLayout = new FloatLayout(floatingElements, useAscender); } floatLayout.SetSimpleColumn(leftX, minY, rightX, yLine); status = floatLayout.Layout(canvas, simulate); yLine = floatLayout.YLine; if (percentageWidth == null && contentWidth < floatLayout.FilledWidth) { contentWidth = floatLayout.FilledWidth; } } if (!simulate && position == PdfDiv.PositionType.RELATIVE) { canvas.RestoreState(); } yLine -= paddingBottom; if (percentageHeight == null) { contentHeight = maxY - yLine; } if (percentageWidth == null) { contentWidth += paddingLeft + paddingRight; } return(contentCutByFixedHeight ? ColumnText.NO_MORE_TEXT : status); }
virtual public int Layout(PdfContentByte canvas, bool useAscender, bool simulate, float llx, float lly, float urx, float ury) { float leftX = Math.Min(llx, urx); float maxY = Math.Max(lly, ury); float minY = Math.Min(lly, ury); float rightX = Math.Max(llx, urx); yLine = maxY; bool contentCutByFixedHeight = false; if (width != null && width > 0) { if (width < rightX - leftX) rightX = leftX + (float) width; else if (width > rightX - leftX) return ColumnText.NO_MORE_COLUMN; } else if (percentageWidth != null) { contentWidth = (rightX - leftX)*(float) percentageWidth; rightX = leftX + contentWidth; } else if (percentageWidth == null) { if (this.floatType == FloatType.NONE && (this.display == DisplayType.DEFAULT_NULL_VALUE || this.display == DisplayType.BLOCK || this.display == DisplayType.LIST_ITEM || this.display == DisplayType.RUN_IN)) { contentWidth = rightX - leftX; } } if (height != null && height > 0) { if (height < maxY - minY) { contentCutByFixedHeight = true; minY = maxY - (float) height; } else if (height > maxY - minY) { return ColumnText.NO_MORE_COLUMN; } } else if (percentageHeight != null) { if (percentageHeight < 1.0) contentCutByFixedHeight = true; contentHeight = (maxY - minY)*(float) percentageHeight; minY = maxY - contentHeight; } if (!simulate && position == PdfDiv.PositionType.RELATIVE) { float? translationX = null; if (left != null) translationX = left; else if (right != null) translationX = -right; else translationX = 0f; float? translationY = null; if (top != null) translationY = -top; else if (bottom != null) translationY = bottom; else translationY = 0f; canvas.SaveState(); canvas.Transform(new AffineTransform(1f, 0, 0, 1f, translationX.Value, translationY.Value)); } if (!simulate) { if ((backgroundColor != null || backgroundImage != null) && getActualWidth() > 0 && getActualHeight() > 0) { float backgroundWidth = getActualWidth(); float backgroundHeight = getActualHeight(); if (width != null) backgroundWidth = width > 0 ? (float) width : 0; if (height != null) backgroundHeight = height > 0 ? (float) height : 0; if (backgroundWidth > 0 && backgroundHeight > 0) { Rectangle background = new Rectangle(leftX, maxY - backgroundHeight, leftX + backgroundWidth, maxY); if (backgroundColor != null) { background.BackgroundColor = backgroundColor; PdfArtifact artifact = new PdfArtifact(); canvas.OpenMCBlock(artifact); canvas.Rectangle(background); canvas.CloseMCBlock(artifact); } if (backgroundImage != null) { if (backgroundImageWidth == null) { backgroundImage.ScaleToFit(background); } else { backgroundImage.ScaleAbsolute((float)backgroundImageWidth, backgroundImageHeight); } backgroundImage.SetAbsolutePosition(background.Left, background.Bottom); canvas.OpenMCBlock(backgroundImage); canvas.AddImage(backgroundImage); canvas.CloseMCBlock(backgroundImage); } } } } if (percentageWidth == null) contentWidth = 0; if (percentageHeight == null) contentHeight = 0; minY += paddingBottom; leftX += paddingLeft; rightX -= paddingRight; yLine -= paddingTop; int status = ColumnText.NO_MORE_TEXT; if (content.Count > 0) { if (floatLayout == null) { List<IElement> floatingElements = new List<IElement>(content); floatLayout = new FloatLayout(floatingElements, useAscender); floatLayout.RunDirection = runDirection; } floatLayout.SetSimpleColumn(leftX, minY, rightX, yLine); if (borderTopStyle != BorderTopStyle.NONE) floatLayout.compositeColumn.IgnoreSpacingBefore = false; status = floatLayout.Layout(canvas, simulate); yLine = floatLayout.YLine; if (percentageWidth == null && contentWidth < floatLayout.FilledWidth) { contentWidth = floatLayout.FilledWidth; } } if (!simulate && position == PdfDiv.PositionType.RELATIVE) canvas.RestoreState(); yLine -= paddingBottom; if (percentageHeight == null) contentHeight = maxY - yLine; if (percentageWidth == null) contentWidth += paddingLeft + paddingRight; return contentCutByFixedHeight ? ColumnText.NO_MORE_TEXT : status; }