本文整理匯總了C#中iTextSharp.text.pdf.PdfContentByte.Rectangle方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfContentByte.Rectangle方法的具體用法?C# PdfContentByte.Rectangle怎麽用?C# PdfContentByte.Rectangle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfContentByte
的用法示例。
在下文中一共展示了PdfContentByte.Rectangle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DrawRectangles
// ---------------------------------------------------------------------------
/**
* Draws three rectangles
* @param canvas
*/
public void DrawRectangles(PdfContentByte canvas) {
canvas.SaveState();
canvas.SetGrayFill(0.9f);
canvas.Rectangle(33, 592, 72, 72);
canvas.Rectangle(263, 406, 72, 72);
canvas.Rectangle(491, 168, 72, 72);
canvas.FillStroke();
canvas.RestoreState();
}
示例2: Render_FrontBase
private static void Render_FrontBase(PdfContentByte under, DateTime expiration)
{
float BORDER_WIDTH = 1.5f;
// Draw background stripes and bars
under.SaveState();
under.SetRGBColorFill(0xff, 0x45, 0x00);
under.Rectangle(0, CARD_HEIGHT - (UPPER_BAR_HEIGHT + PHOTO_BAR_HEIGHT + LOWER_BAR_HEIGHT), CARD_WIDTH, (UPPER_BAR_HEIGHT + PHOTO_BAR_HEIGHT + LOWER_BAR_HEIGHT));
under.Fill();
under.SetRGBColorFill(0x0, 0x0, 0x0);
under.Rectangle(0, CARD_HEIGHT - (UPPER_BAR_HEIGHT + PHOTO_BAR_HEIGHT) - BORDER_WIDTH, CARD_WIDTH, PHOTO_BAR_HEIGHT + 2 * BORDER_WIDTH);
under.Fill();
under.SetRGBColorFill(0xff, 0xff, 0xff);
under.Rectangle(0, CARD_HEIGHT - (UPPER_BAR_HEIGHT + PHOTO_BAR_HEIGHT), CARD_WIDTH, PHOTO_BAR_HEIGHT);
under.Fill();
under.RestoreState();
var img = Image.GetInstance(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content", "images", "sheriff.png"));
img.ScaleToFit(CARD_WIDTH - PHOTO_WIDTH - 8, PHOTO_BAR_HEIGHT);
img.SetAbsolutePosition(
((CARD_WIDTH - PHOTO_WIDTH) - img.ScaledWidth) / 2,
CARD_HEIGHT - (UPPER_BAR_HEIGHT + img.ScaledHeight) - 4);
under.AddImage(img);
Font f = new Font(baseFont, 8) { Color = BaseColor.WHITE };
Phrase p = new Phrase("Expiration:", f);
ColumnText.ShowTextAligned(under, Element.ALIGN_LEFT, p, 4, CARD_HEIGHT - 10, 0);
p = new Phrase(expiration.ToString("MM/dd/yyyy"), f);
ColumnText.ShowTextAligned(under, Element.ALIGN_RIGHT, p, CARD_WIDTH - 4, CARD_HEIGHT - 10, 0);
f = new Font(baseFont, 11) { Color = BaseColor.WHITE };
p = new Phrase("King County", f);
ColumnText.ShowTextAligned(under, Element.ALIGN_CENTER, p, CARD_WIDTH / 2, CARD_HEIGHT - 34, 0);
f = new Font(baseFont, 14, Font.BOLD) { Color = BaseColor.WHITE };
p = new Phrase("Search & Rescue", f);
ColumnText.ShowTextAligned(under, Element.ALIGN_CENTER, p, CARD_WIDTH / 2, CARD_HEIGHT - 49, 0);
}
示例3: Strip
public void Strip(PdfContentByte content, Rectangle rect) {
content.Rectangle(
rect.Left - 1, rect.Bottom - 5f,
rect.Width, rect.Height + 8
);
content.Rectangle(
rect.Left, rect.Bottom - 2,
rect.Width - 2, rect.Height + 2
);
float y1 = rect.Top + 0.5f;
float y2 = rect.Bottom - 4;
for (float f = rect.Left; f < rect.Right - 4; f += 5) {
content.Rectangle(f, y1, 4f, 1.5f);
content.Rectangle(f, y2, 4f, 1.5f);
}
content.EoFill();
}
示例4: DrawBlock
// ---------------------------------------------------------------------------
/**
* Draws a colored block on the time table, corresponding with
* the screening of a specific movie.
* @param screening a screening POJO, contains a movie and a category
* @param under the canvas to which the block is drawn
*/
protected void DrawBlock(
Screening screening, PdfContentByte under, PdfContentByte over
) {
under.SaveState();
BaseColor color = WebColors.GetRGBColor(
"#" + screening.movie.entry.category.color
);
under.SetColorFill(color);
Rectangle rect = GetPosition(screening);
under.Rectangle(
rect.Left, rect.Bottom, rect.Width, rect.Height
);
under.Fill();
over.Rectangle(
rect.Left, rect.Bottom, rect.Width, rect.Height
);
over.Stroke();
under.RestoreState();
}
示例5: PlaceBarcode
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The
* barcode is always placed at coodinates (0, 0). Use the
* translation matrix to move it elsewhere.<p>
* The bars and text are written in the following colors:<p>
* <P><TABLE BORDER=1>
* <TR>
* <TH><P><CODE>barColor</CODE></TH>
* <TH><P><CODE>textColor</CODE></TH>
* <TH><P>Result</TH>
* </TR>
* <TR>
* <TD><P><CODE>null</CODE></TD>
* <TD><P><CODE>null</CODE></TD>
* <TD><P>bars and text painted with current fill color</TD>
* </TR>
* <TR>
* <TD><P><CODE>barColor</CODE></TD>
* <TD><P><CODE>null</CODE></TD>
* <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
* </TR>
* <TR>
* <TD><P><CODE>null</CODE></TD>
* <TD><P><CODE>textColor</CODE></TD>
* <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
* </TR>
* <TR>
* <TD><P><CODE>barColor</CODE></TD>
* <TD><P><CODE>textColor</CODE></TD>
* <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
* </TR>
* </TABLE>
* @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
* @param barColor the color of the bars. It can be <CODE>null</CODE>
* @param textColor the color of the text. It can be <CODE>null</CODE>
* @return the dimensions the barcode occupies
*/
public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor)
{
if (barColor != null)
cb.SetColorFill(barColor);
byte[] bars = GetBarsPostnet(code);
byte flip = 1;
if (codeType == PLANET) {
flip = 0;
bars[0] = 0;
bars[bars.Length - 1] = 0;
}
float startX = 0;
for (int k = 0; k < bars.Length; ++k) {
cb.Rectangle(startX, 0, x - inkSpreading, bars[k] == flip ? barHeight : size);
startX += n;
}
cb.Fill();
return this.BarcodeSize;
}
示例6: PlaceBarcode
virtual public void PlaceBarcode(PdfContentByte cb, BaseColor foreground, float moduleHeight, float moduleWidth) {
int w = width + 2*ws;
int h = height + 2*ws;
int stride = (w + 7)/8;
int ptr = 0;
cb.SetColorFill(foreground);
for (int k = 0; k < h; ++k) {
int p = k*stride;
for (int j = 0; j < w; ++j) {
int b = image[p + j/8] & 0xff;
b <<= j%8;
if ((b & 0x80) != 0) {
cb.Rectangle(j*moduleWidth, (h - k - 1)*moduleHeight, moduleWidth, moduleHeight);
}
}
}
cb.Fill();
}
示例7: WriteLineToContent
/**
* Writes a text line to the document. It takes care of all the attributes.
* <P>
* Before entering the line position must have been established and the
* <CODE>text</CODE> argument must be in text object scope (<CODE>beginText()</CODE>).
* @param line the line to be written
* @param text the <CODE>PdfContentByte</CODE> where the text will be written to
* @param graphics the <CODE>PdfContentByte</CODE> where the graphics will be written to
* @param currentValues the current font and extra spacing values
* @param ratio
* @throws DocumentException on error
*/
internal void WriteLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object[] currentValues, float ratio)
{
PdfFont currentFont = (PdfFont)(currentValues[0]);
float lastBaseFactor = (float)currentValues[1];
//PdfChunk chunkz;
int numberOfSpaces;
int lineLen;
bool isJustified;
float hangingCorrection = 0;
float hScale = 1;
float lastHScale = float.NaN;
float baseWordSpacing = 0;
float baseCharacterSpacing = 0;
numberOfSpaces = line.NumberOfSpaces;
lineLen = line.ToString().Length;
// does the line need to be justified?
isJustified = line.HasToBeJustified() && (numberOfSpaces != 0 || lineLen > 1);
if (isJustified) {
if (line.NewlineSplit && line.WidthLeft >= (lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1))) {
if (line.RTL) {
text.MoveText(line.WidthLeft - lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1), 0);
}
baseWordSpacing = ratio * lastBaseFactor;
baseCharacterSpacing = lastBaseFactor;
}
else {
float width = line.WidthLeft;
PdfChunk last = line.GetChunk(line.Size - 1);
if (last != null) {
String s = last.ToString();
char c;
if (s.Length > 0 && hangingPunctuation.IndexOf((c = s[s.Length - 1])) >= 0) {
float oldWidth = width;
width += last.Font.Width(c) * 0.4f;
hangingCorrection = width - oldWidth;
}
}
float baseFactor = width / (ratio * numberOfSpaces + lineLen - 1);
baseWordSpacing = ratio * baseFactor;
baseCharacterSpacing = baseFactor;
lastBaseFactor = baseFactor;
}
}
int lastChunkStroke = line.LastStrokeChunk;
int chunkStrokeIdx = 0;
float xMarker = text.XTLM;
float baseXMarker = xMarker;
float yMarker = text.YTLM;
bool adjustMatrix = false;
// looping over all the chunks in 1 line
foreach (PdfChunk chunk in line) {
Color color = chunk.Color;
hScale = 1;
if (chunkStrokeIdx <= lastChunkStroke) {
float width;
if (isJustified) {
width = chunk.GetWidthCorrected(baseCharacterSpacing, baseWordSpacing);
}
else
width = chunk.Width;
if (chunk.IsStroked()) {
PdfChunk nextChunk = line.GetChunk(chunkStrokeIdx + 1);
if (chunk.IsAttribute(Chunk.BACKGROUND)) {
float subtract = lastBaseFactor;
if (nextChunk != null && nextChunk.IsAttribute(Chunk.BACKGROUND))
subtract = 0;
if (nextChunk == null)
subtract += hangingCorrection;
float fontSize = chunk.Font.Size;
float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
Object[] bgr = (Object[])chunk.GetAttribute(Chunk.BACKGROUND);
graphics.SetColorFill((Color)bgr[0]);
float[] extra = (float[])bgr[1];
graphics.Rectangle(xMarker - extra[0],
yMarker + descender - extra[1] + chunk.TextRise,
width - subtract + extra[0] + extra[2],
ascender - descender + extra[1] + extra[3]);
graphics.Fill();
graphics.SetGrayFill(0);
}
if (chunk.IsAttribute(Chunk.UNDERLINE)) {
float subtract = lastBaseFactor;
if (nextChunk != null && nextChunk.IsAttribute(Chunk.UNDERLINE))
//.........這裏部分代碼省略.........
示例8: PlaceBarcode
public override Rectangle PlaceBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor)
{
const float distanceBetweenBars = MmToPoints;
const float wideBarPoints = MmToPoints;
const float narrowBarPoints = HalfMmToPoints;
const float barWidth = DefaultBarWidthInPoints;
const float fullHeight = DefaultBarHeightInPoints;
var barStartX = IsisPoint.X - _mmFromPageBorder;
var barStartY = IsisPoint.Y - _mmFromDrawningBar;
var bars = GetBarsCode39("123456789012345678901234567890123456789");
var print = true;
if (barColor != null)
{
cb.SetColorFill(barColor);
cb.SetColorStroke(barColor);
}
const int elementBars = 20;
var elemBarCount = 1;
foreach (var vbarHeight in bars.Select(t => (t == 0 ? narrowBarPoints : wideBarPoints)))
{
if (print)
{
cb.Rectangle(barStartX, barStartY, barWidth, vbarHeight);
}
print = !print;
barStartY += vbarHeight;
if (elemBarCount++ != elementBars) continue; // start a new element
elemBarCount = 1;
barStartY = IsisPoint.Y - _mmFromDrawningBar;
barStartX += barWidth + distanceBetweenBars;
}
cb.Fill();
var fullWidth = barStartX + barWidth;
return new Rectangle(fullWidth, fullHeight);
}
示例9: DrawRectangle
// ---------------------------------------------------------------------------
/**
* Draws a rectangle
* @param content the direct content layer
* @param width the width of the rectangle
* @param height the height of the rectangle
*/
public static void DrawRectangle(
PdfContentByte content, float width, float height)
{
content.SaveState();
PdfGState state = new PdfGState();
state.FillOpacity = 0.6f;
content.SetGState(state);
content.SetRGBColorFill(0xFF, 0xFF, 0xFF);
content.SetLineWidth(3);
content.Rectangle(0, 0, width, height);
content.FillStroke();
content.RestoreState();
}
示例10: PlaceBarcode
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The
* barcode is always placed at coodinates (0, 0). Use the
* translation matrix to move it elsewhere.<p>
* The bars and text are written in the following colors:<p>
* <P><TABLE BORDER=1>
* <TR>
* <TH><P><CODE>barColor</CODE></TH>
* <TH><P><CODE>textColor</CODE></TH>
* <TH><P>Result</TH>
* </TR>
* <TR>
* <TD><P><CODE>null</CODE></TD>
* <TD><P><CODE>null</CODE></TD>
* <TD><P>bars and text painted with current fill color</TD>
* </TR>
* <TR>
* <TD><P><CODE>barColor</CODE></TD>
* <TD><P><CODE>null</CODE></TD>
* <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
* </TR>
* <TR>
* <TD><P><CODE>null</CODE></TD>
* <TD><P><CODE>textColor</CODE></TD>
* <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
* </TR>
* <TR>
* <TD><P><CODE>barColor</CODE></TD>
* <TD><P><CODE>textColor</CODE></TD>
* <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
* </TR>
* </TABLE>
* @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
* @param barColor the color of the bars. It can be <CODE>null</CODE>
* @param textColor the color of the text. It can be <CODE>null</CODE>
* @return the dimensions the barcode occupies
*/
public override Rectangle PlaceBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor) {
string fullCode;
if (codeType == CODE128_RAW) {
int idx = code.IndexOf('\uffff');
if (idx < 0)
fullCode = "";
else
fullCode = code.Substring(idx + 1);
}
else if (codeType == CODE128_UCC)
fullCode = GetHumanReadableUCCEAN(code);
else
fullCode = RemoveFNC1(code);
float fontX = 0;
if (font != null) {
fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size);
}
string bCode;
if (codeType == CODE128_RAW) {
int idx = code.IndexOf('\uffff');
if (idx >= 0)
bCode = code.Substring(0, idx);
else
bCode = code;
}
else {
bCode = GetRawText(code, codeType == CODE128_UCC);
}
int len = bCode.Length;
float fullWidth = (len + 2) * 11 * x + 2 * x;
float barStartX = 0;
float textStartX = 0;
switch (textAlignment) {
case Element.ALIGN_LEFT:
break;
case Element.ALIGN_RIGHT:
if (fontX > fullWidth)
barStartX = fontX - fullWidth;
else
textStartX = fullWidth - fontX;
break;
default:
if (fontX > fullWidth)
barStartX = (fontX - fullWidth) / 2;
else
textStartX = (fullWidth - fontX) / 2;
break;
}
float barStartY = 0;
float textStartY = 0;
if (font != null) {
if (baseline <= 0)
textStartY = barHeight - baseline;
else {
textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
barStartY = textStartY + baseline;
}
}
byte[] bars = GetBarsCode128Raw(bCode);
bool print = true;
if (barColor != null)
cb.SetColorFill(barColor);
for (int k = 0; k < bars.Length; ++k) {
float w = bars[k] * x;
//.........這裏部分代碼省略.........
示例11: PictureBackdrop
/**
* Prints a square and fills half of it with a gray rectangle.
*
* @param x
* @param y
* @param cb
* @throws Exception
*/
private void PictureBackdrop(float x, float y, PdfContentByte cb,
PdfWriter writer) {
PdfShading axial = PdfShading.SimpleAxial(writer, x, y, x + 200, y,
BaseColor.YELLOW, BaseColor.RED);
PdfShadingPattern axialPattern = new PdfShadingPattern(axial);
cb.SetShadingFill(axialPattern);
cb.SetColorStroke(BaseColor.BLACK);
cb.SetLineWidth(2);
cb.Rectangle(x, y, 200, 200);
cb.FillStroke();
}
示例12: InsertFormXObj
private void InsertFormXObj(PdfContentByte canvas, PdfDictionary pageDict, PdfStream formXObj, IList<Rectangle> clippingRects, Rectangle annotRect) {
PdfName xobjName = GenerateNameForXObj(pageDict);
canvas.SaveState();
foreach (Rectangle rect in clippingRects) {
canvas.Rectangle(rect.Left, rect.Bottom, rect.Width, rect.Height);
}
canvas.Clip();
canvas.NewPath();
canvas.AddFormXObj(formXObj, xobjName, 1, 0, 0, 1, annotRect.Left, annotRect.Bottom);
canvas.RestoreState();
}
示例13: PlaceBarcode
// /** Creates a <CODE>java.awt.Image</CODE>.
// * @param foreground the color of the bars
// * @param background the color of the background
// * @return the image
// */
// public java.awt.Image CreateAwtImage(java.awt.Color foreground, java.awt.Color background) {
// int f = foreground.GetRGB();
// int g = background.GetRGB();
// Canvas canvas = new Canvas();
// int width = bm.GetWidth();
// int height = bm.GetHeight();
// int[] pix = new int[width * height];
// byte[][] mt = bm.GetArray();
// for (int y = 0; y < height; ++y) {
// byte[] line = mt[y];
// for (int x = 0; x < width; ++x) {
// pix[y * width + x] = line[x] == 0 ? f : g;
// }
// }
// java.awt.Image img = canvas.CreateImage(new MemoryImageSource(width, height, pix, 0, width));
// return img;
//}
public void PlaceBarcode(PdfContentByte cb, BaseColor foreground, float moduleSide)
{
int width = bm.GetWidth();
int height = bm.GetHeight();
sbyte[][] mt = bm.GetArray();
cb.SetColorFill(foreground);
for (int y = 0; y < height; ++y)
{
sbyte[] line = mt[y];
for (int x = 0; x < width; ++x)
{
if (line[x] == 0)
{
cb.Rectangle(x * moduleSide, (height - y - 1) * moduleSide, moduleSide, moduleSide);
}
}
}
cb.Fill();
}
示例14: DrawArc
private void DrawArc(PdfContentByte cb, IList<float> numbers)
{
EllipseArc ellipse = EllipseArc.CreateEllipseArc(numbers[7], numbers[8], numbers[5], numbers[6], numbers[0], numbers[1], numbers[4], numbers[3]);
cb.SetColorFill(BaseColor.ORANGE);
cb.Rectangle(numbers[7], numbers[8], 2, 2); //p1
cb.Fill();
cb.SetColorFill(BaseColor.GREEN);
cb.Rectangle(numbers[5], numbers[6], 2, 2); //p2
cb.Fill();
cb.Arc(ellipse.Cx - numbers[0], ellipse.Cy - numbers[1], ellipse.Cx + numbers[0], ellipse.Cy + numbers[1],
ellipse.StartAng, ellipse.Extend);
}
示例15: Layout
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);
//.........這裏部分代碼省略.........