本文整理匯總了C#中iTextSharp.text.pdf.PdfContentByte.SetColorFill方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfContentByte.SetColorFill方法的具體用法?C# PdfContentByte.SetColorFill怎麽用?C# PdfContentByte.SetColorFill使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfContentByte
的用法示例。
在下文中一共展示了PdfContentByte.SetColorFill方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: PdfText
private static void PdfText(PdfContentByte cb, TextAlignedPdfConfig parms)
{
var bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.SetColorFill(BaseColor.BLACK);
cb.SetFontAndSize(bf, 18);
cb.BeginText();
cb.ShowTextAligned(parms.Alignment, parms.Text, parms.X, parms.Y, parms.Rotation);
cb.EndText();
}
示例2: 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();
}
示例3: Render
/// <summary>
/// Renders the object in a document using a <see cref="PdfContentByte"/> by invoking the <see cref="Render(ContentWriter, Vector2D)"/> method.
/// This method can be overridden in derived classes to specify rendering.
/// </summary>
/// <param name="cb">The <see cref="PdfContentByte"/> used for rendering.</param>
/// <param name="offset">The calculated offset for the rendered item.</param>
protected internal virtual void Render(PdfContentByte cb, Vector2D offset)
{
using (var writer = new ContentWriter(cb))
{
var stroke = this as StrokeObject;
var fill = this as FillObject;
bool hasstroke = stroke?.BorderColor.HasValue ?? false;
bool hasfill = fill?.FillColor.HasValue ?? false;
if (hasstroke)
{
cb.SetLineWidth((float)stroke.BorderWidth.Value(UnitsOfMeasure.Points));
cb.SetColorStroke(new Color(stroke.BorderColor.Value));
}
if (hasfill)
cb.SetColorFill(new Color(fill.FillColor.Value));
Render(writer, offset);
if (hasstroke && hasfill)
{
if (writer.CloseShape)
cb.ClosePathFillStroke();
else
cb.FillStroke();
}
else if (hasstroke)
{
if (writer.CloseShape)
cb.ClosePathStroke();
else
cb.Stroke();
}
else if (hasfill)
cb.Fill();
}
}
示例4: WriteLine
internal void WriteLine(PdfLine line, PdfContentByte text, PdfContentByte graphics)
{
PdfFont currentFont = null;
foreach(PdfChunk chunk in line) {
if (chunk.Font.CompareTo(currentFont) != 0) {
currentFont = chunk.Font;
text.SetFontAndSize(currentFont.Font, currentFont.Size);
}
Object[] textRender = (Object[])chunk.GetAttribute(Chunk.TEXTRENDERMODE);
int tr = 0;
float strokeWidth = 1;
BaseColor color = chunk.Color;
BaseColor strokeColor = null;
if (textRender != null) {
tr = (int)textRender[0] & 3;
if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
text.SetTextRenderingMode(tr);
if (tr == PdfContentByte.TEXT_RENDER_MODE_STROKE || tr == PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE) {
strokeWidth = (float)textRender[1];
if (strokeWidth != 1)
text.SetLineWidth(strokeWidth);
strokeColor = (BaseColor)textRender[2];
if (strokeColor == null)
strokeColor = color;
if (strokeColor != null)
text.SetColorStroke(strokeColor);
}
}
object charSpace = chunk.GetAttribute(Chunk.CHAR_SPACING);
// no char space setting means "leave it as is".
if (charSpace != null && !curCharSpace.Equals(charSpace)) {
curCharSpace = (float)charSpace;
text.SetCharacterSpacing(curCharSpace);
}
if (color != null)
text.SetColorFill(color);
text.ShowText(chunk.ToString());
if (color != null)
text.ResetRGBColorFill();
if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
text.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
if (strokeColor != null)
text.ResetRGBColorStroke();
if (strokeWidth != 1)
text.SetLineWidth(1);
}
}
示例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: Render
protected internal override void Render(PdfContentByte cb, Vector2D offset)
{
offset.Y += Size.Y + Offset.Y - Baseline;
cb.BeginText();
cb.SetColorFill(new iTextSharp.text.Color(color));
cb.SetFontAndSize(font.iTextSharpFont.BaseFont, font.Size);
foreach (var s in text.Split('\n'))
{
cb.ShowTextAligned(textAlignment(alignment), s, (float)offset.X.Value(UnitsOfMeasure.Points), (float)offset.Y.Value(UnitsOfMeasure.Points), 0);
offset.Y -= font.Height;
}
cb.EndText();
}
示例7: 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) {
Rectangle rect = this.BarcodeSize;
float barStartX = 0;
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;
}
}
switch (codeType) {
case EAN13:
case UPCA:
case UPCE:
if (font != null)
barStartX += font.GetWidthPoint(code[0], size);
break;
}
byte[] bars = null;
int[] guard = GUARD_EMPTY;
switch (codeType) {
case EAN13:
bars = GetBarsEAN13(code);
guard = GUARD_EAN13;
break;
case EAN8:
bars = GetBarsEAN8(code);
guard = GUARD_EAN8;
break;
case UPCA:
bars = GetBarsEAN13("0" + code);
guard = GUARD_UPCA;
break;
case UPCE:
bars = GetBarsUPCE(code);
guard = GUARD_UPCE;
break;
case SUPP2:
bars = GetBarsSupplemental2(code);
break;
case SUPP5:
bars = GetBarsSupplemental5(code);
break;
}
float keepBarX = barStartX;
bool print = true;
float gd = 0;
if (font != null && baseline > 0 && guardBars) {
gd = baseline / 2;
}
if (barColor != null)
cb.SetColorFill(barColor);
for (int k = 0; k < bars.Length; ++k) {
float w = bars[k] * x;
if (print) {
if (Array.BinarySearch(guard, k) >= 0)
cb.Rectangle(barStartX, barStartY - gd, w - inkSpreading, barHeight + gd);
else
cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
}
print = !print;
//.........這裏部分代碼省略.........
示例8: PictureCircles
// ---------------------------------------------------------------------------
/**
* Prints 3 circles in different colors that intersect with eachother.
*
* @param x
* @param y
* @param cb
* @throws Exception
*/
public static void PictureCircles(float x, float y, PdfContentByte cb) {
cb.SetColorFill(BaseColor.RED);
cb.Circle(x + 70, y + 70, 50);
cb.Fill();
cb.SetColorFill(BaseColor.YELLOW);
cb.Circle(x + 100, y + 130, 50);
cb.Fill();
cb.SetColorFill(BaseColor.BLUE);
cb.Circle(x + 130, y + 70, 50);
cb.Fill();
}
示例9: 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 = code;
if (generateChecksum && checksumText)
fullCode = CalculateChecksum(code);
if (!startStopText)
fullCode = fullCode.Substring(1, fullCode.Length - 2);
float fontX = 0;
if (font != null) {
fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size);
}
byte[] bars = GetBarsCodabar(generateChecksum ? CalculateChecksum(code) : code);
int wide = 0;
for (int k = 0; k < bars.Length; ++k) {
wide += (int)bars[k];
}
int narrow = bars.Length - wide;
float fullWidth = x * (narrow + wide * n);
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;
}
}
bool print = true;
if (barColor != null)
cb.SetColorFill(barColor);
for (int k = 0; k < bars.Length; ++k) {
float w = (bars[k] == 0 ? x : x * n);
if (print)
cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
print = !print;
barStartX += w;
}
cb.Fill();
if (font != null) {
if (textColor != null)
cb.SetColorFill(textColor);
cb.BeginText();
cb.SetFontAndSize(font, size);
cb.SetTextMatrix(textStartX, textStartY);
cb.ShowText(fullCode);
//.........這裏部分代碼省略.........
示例10: PlaceBarcode
public virtual void PlaceBarcode(PdfContentByte cb, BaseColor foreground, float moduleHeight, float moduleWidth) {
PaintCode();
int stride = (bitColumns + 7)/8;
cb.SetColorFill(foreground);
for (int k = 0; k < codeRows; ++k) {
int p = k*stride;
for (int j = 0; j < bitColumns; ++j) {
int b = outBits[p + j/8] & 0xff;
b <<= j%8;
if ((b & 0x80) != 0) {
cb.Rectangle(j*moduleWidth, (codeRows - k - 1)*moduleHeight, moduleWidth, moduleHeight);
}
}
}
cb.Fill();
}
示例11: PictureCircles
/**
* Prints 3 circles in different colors that intersect with eachother.
*
* @param x
* @param y
* @param cb
* @throws Exception
*/
private void PictureCircles(float x, float y, PdfContentByte cb, PdfWriter writer) {
PdfGState gs = new PdfGState();
gs.BlendMode = PdfGState.BM_MULTIPLY;
gs.FillOpacity = 1f;
cb.SetGState(gs);
cb.SetColorFill(BaseColor.LIGHT_GRAY);
cb.Circle(x + 75, y + 75, 70);
cb.Fill();
cb.Circle(x + 75, y + 125, 70);
cb.Fill();
cb.Circle(x + 125, y + 75, 70);
cb.Fill();
cb.Circle(x + 125, y + 125, 70);
cb.Fill();
}
示例12: DrawBoxForCover
/// <summary>
/// Draws the box on the cover page that contains the date
/// </summary>
/// <param name="cb"></param>
/// <param name="doc"></param>
/// <param name="project"></param>
private void DrawBoxForCover(PdfContentByte cb, Document doc)
{
// set the colors
cb.SetColorStroke(_baseColor);
cb.SetColorFill(_baseColor);
// calculate the top left corner of the box
var x = doc.LeftMargin;
var y = doc.BottomMargin + 678;
var height = 60;
// move the cursor to starting position
cb.MoveTo(x, y);
// draw the top line
cb.LineTo(x + _pageWidth, y);
// draw the right line
cb.LineTo(x + _pageWidth, y - height);
// draw the bottom line
cb.LineTo(x, y - height);
// draw the left line
cb.LineTo(x, y);
cb.ClosePathFillStroke();
cb.Stroke();
// add the text inside the box
cb.BeginText();
cb.SetFontAndSize(_dateBaseFont, 26f);
cb.SetColorStroke(BaseColor.WHITE);
cb.SetColorFill(BaseColor.WHITE);
cb.SetTextMatrix(x + 10, y - 40);
cb.ShowText(string.Format("{0:MMMM dd, yyyy}", DateTime.Now));
cb.EndText();
}
示例13: AddColoredRectangle
private void AddColoredRectangle(PdfContentByte canvas, PdfCleanUpLocation cleanUpLocation) {
Rectangle cleanUpRegion = cleanUpLocation.Region;
canvas.SaveState();
canvas.SetColorFill(cleanUpLocation.CleanUpColor);
canvas.MoveTo(cleanUpRegion.Left, cleanUpRegion.Bottom);
canvas.LineTo(cleanUpRegion.Right, cleanUpRegion.Bottom);
canvas.LineTo(cleanUpRegion.Right, cleanUpRegion.Top);
canvas.LineTo(cleanUpRegion.Left, cleanUpRegion.Top);
canvas.ClosePath();
canvas.Fill();
canvas.RestoreState();
}
示例14: 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();
}
示例15: 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);
}