本文整理匯總了C#中iTextSharp.text.pdf.PdfTemplate.AddTemplate方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfTemplate.AddTemplate方法的具體用法?C# PdfTemplate.AddTemplate怎麽用?C# PdfTemplate.AddTemplate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfTemplate
的用法示例。
在下文中一共展示了PdfTemplate.AddTemplate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetAppearance
//.........這裏部分代碼省略.........
ColumnText ct2 = new ColumnText(t);
ct2.RunDirection = runDirection;
ct2.SetSimpleColumn(new Phrase(signedBy, font), signatureRect.Left, signatureRect.Bottom, signatureRect.Right, signatureRect.Top, signedSize, Element.ALIGN_LEFT);
ct2.Go();
}
else if (Render == SignatureRender.GraphicAndDescription) {
ColumnText ct2 = new ColumnText(t);
ct2.RunDirection = runDirection;
ct2.SetSimpleColumn(signatureRect.Left, signatureRect.Bottom, signatureRect.Right, signatureRect.Top, 0, Element.ALIGN_RIGHT);
Image im = Image.GetInstance(SignatureGraphic);
im.ScaleToFit(signatureRect.Width, signatureRect.Height);
Paragraph p = new Paragraph();
// must calculate the point to draw from to make image appear in middle of column
float x = 0;
// experimentation found this magic number to counteract Adobe's signature graphic, which
// offsets the y co-ordinate by 15 units
float y = -im.ScaledHeight + 15;
x = x + (signatureRect.Width - im.ScaledWidth) / 2;
y = y - (signatureRect.Height - im.ScaledHeight) / 2;
p.Add(new Chunk(im, x + (signatureRect.Width - im.ScaledWidth) / 2, y, false));
ct2.AddElement(p);
ct2.Go();
}
if (size <= 0) {
Rectangle sr = new Rectangle(dataRect.Width, dataRect.Height);
size = FitText(font, text, sr, 12, runDirection);
}
ColumnText ct = new ColumnText(t);
ct.RunDirection = runDirection;
ct.SetSimpleColumn(new Phrase(text, font), dataRect.Left, dataRect.Bottom, dataRect.Right, dataRect.Top, size, Element.ALIGN_LEFT);
ct.Go();
}
if (app[3] == null && !acro6Layers) {
PdfTemplate t = app[3] = new PdfTemplate(writer);
t.BoundingBox = new Rectangle(100, 100);
writer.AddDirectTemplateSimple(t, new PdfName("n3"));
t.SetLiteral("% DSBlank\n");
}
if (app[4] == null && !acro6Layers) {
PdfTemplate t = app[4] = new PdfTemplate(writer);
t.BoundingBox = new Rectangle(0, rect.Height * (1 - TOP_SECTION), rect.Right, rect.Top);
writer.AddDirectTemplateSimple(t, new PdfName("n4"));
Font font;
if (layer2Font == null)
font = new Font();
else
font = new Font(layer2Font);
float size = font.Size;
String text = "Signature Not Verified";
if (layer4Text != null)
text = layer4Text;
Rectangle sr = new Rectangle(rect.Width - 2 * MARGIN, rect.Height * TOP_SECTION - 2 * MARGIN);
size = FitText(font, text, sr, 15, runDirection);
ColumnText ct = new ColumnText(t);
ct.RunDirection = runDirection;
ct.SetSimpleColumn(new Phrase(text, font), MARGIN, 0, rect.Width - MARGIN, rect.Height - MARGIN, size, Element.ALIGN_LEFT);
ct.Go();
}
int rotation = writer.reader.GetPageRotation(page);
Rectangle rotated = new Rectangle(rect);
int n = rotation;
while (n > 0) {
rotated = rotated.Rotate();
n -= 90;
}
if (frm == null) {
frm = new PdfTemplate(writer);
frm.BoundingBox = rotated;
writer.AddDirectTemplateSimple(frm, new PdfName("FRM"));
float scale = Math.Min(rect.Width, rect.Height) * 0.9f;
float x = (rect.Width - scale) / 2;
float y = (rect.Height - scale) / 2;
scale /= 100;
if (rotation == 90)
frm.ConcatCTM(0, 1, -1, 0, rect.Height, 0);
else if (rotation == 180)
frm.ConcatCTM(-1, 0, 0, -1, rect.Width, rect.Height);
else if (rotation == 270)
frm.ConcatCTM(0, -1, 1, 0, 0, rect.Width);
frm.AddTemplate(app[0], 0, 0);
if (!acro6Layers)
frm.AddTemplate(app[1], scale, 0, 0, scale, x, y);
frm.AddTemplate(app[2], 0, 0);
if (!acro6Layers) {
frm.AddTemplate(app[3], scale, 0, 0, scale, x, y);
frm.AddTemplate(app[4], 0, 0);
}
}
PdfTemplate napp = new PdfTemplate(writer);
napp.BoundingBox = rotated;
writer.AddDirectTemplateSimple(napp, null);
napp.AddTemplate(frm, 0, 0);
return napp;
}
示例2: GetAppearance
//.........這裏部分代碼省略.........
Image im = Image.GetInstance(signatureGraphic);
im.ScaleToFit(signatureRect.Width, signatureRect.Height);
Paragraph p = new Paragraph(signatureRect.Height);
// must calculate the point to draw from to make image appear in middle of column
float x = (signatureRect.Width - im.ScaledWidth) / 2;
float y = (signatureRect.Height - im.ScaledHeight) / 2;
p.Add(new Chunk(im, x, y, false));
ct2.AddElement(p);
ct2.Go();
}
if (renderingMode != RenderingMode.GRAPHIC) {
if (size <= 0) {
Rectangle sr = new Rectangle(dataRect.Width, dataRect.Height);
size = ColumnText.FitText(font, text, sr, 12, runDirection);
}
ColumnText ct = new ColumnText(t);
ct.RunDirection = runDirection;
ct.SetSimpleColumn(new Phrase(text, font), dataRect.Left, dataRect.Bottom, dataRect.Right, dataRect.Top, size, Element.ALIGN_LEFT);
ct.Go();
}
}
if (app[3] == null && !acro6Layers) {
PdfTemplate t = app[3] = new PdfTemplate(writer);
t.BoundingBox = new Rectangle(100, 100);
writer.AddDirectTemplateSimple(t, new PdfName("n3"));
t.SetLiteral("% DSBlank\n");
}
if (app[4] == null && !acro6Layers) {
PdfTemplate t = app[4] = new PdfTemplate(writer);
t.BoundingBox = new Rectangle(0, rect.Height * (1 - TOP_SECTION), rect.Right, rect.Top);
writer.AddDirectTemplateSimple(t, new PdfName("n4"));
Font font;
if (layer2Font == null)
font = new Font();
else
font = new Font(layer2Font);
float size = font.Size;
String text = "Signature Not Verified";
if (layer4Text != null)
text = layer4Text;
Rectangle sr = new Rectangle(rect.Width - 2 * MARGIN, rect.Height * TOP_SECTION - 2 * MARGIN);
size = ColumnText.FitText(font, text, sr, 15, runDirection);
ColumnText ct = new ColumnText(t);
ct.RunDirection = runDirection;
ct.SetSimpleColumn(new Phrase(text, font), MARGIN, 0, rect.Width - MARGIN, rect.Height - MARGIN, size, Element.ALIGN_LEFT);
ct.Go();
}
int rotation = writer.reader.GetPageRotation(page);
Rectangle rotated = new Rectangle(rect);
int n = rotation;
while (n > 0) {
rotated = rotated.Rotate();
n -= 90;
}
if (frm == null) {
frm = new PdfTemplate(writer);
frm.BoundingBox = rotated;
writer.AddDirectTemplateSimple(frm, new PdfName("FRM"));
float scale = Math.Min(rect.Width, rect.Height) * 0.9f;
float x = (rect.Width - scale) / 2;
float y = (rect.Height - scale) / 2;
scale /= 100;
if (rotation == 90)
frm.ConcatCTM(0, 1, -1, 0, rect.Height, 0);
else if (rotation == 180)
frm.ConcatCTM(-1, 0, 0, -1, rect.Width, rect.Height);
else if (rotation == 270)
frm.ConcatCTM(0, -1, 1, 0, 0, rect.Width);
if (reuseAppearance) {
AcroFields af = writer.GetAcroFields();
PdfIndirectReference refe = af.GetNormalAppearance(FieldName);
if (refe != null) {
frm.AddTemplateReference(refe, new PdfName("n0"), 1, 0, 0, 1, 0, 0);
}
else {
reuseAppearance = false;
if (app[0] == null) {
CreateBlankN0();
}
}
}
if (!reuseAppearance) {
frm.AddTemplate(app[0], 0, 0);
}
if (!acro6Layers)
frm.AddTemplate(app[1], scale, 0, 0, scale, x, y);
frm.AddTemplate(app[2], 0, 0);
if (!acro6Layers) {
frm.AddTemplate(app[3], scale, 0, 0, scale, x, y);
frm.AddTemplate(app[4], 0, 0);
}
}
PdfTemplate napp = new PdfTemplate(writer);
napp.BoundingBox = rotated;
writer.AddDirectTemplateSimple(napp, null);
napp.AddTemplate(frm, 0, 0);
return napp;
}
示例3: GetAppearance
//.........這裏部分代碼省略.........
nlayout = LAYOUT_LABEL_ONLY;
fsize = fontSize;
continue;
}
textX = box.Width - ufont.GetWidthPoint(text, fsize) - offX - 1;
textY = (box.Height - ufont.GetFontDescriptor(BaseFont.ASCENT, fsize)) / 2;
iconBox = new Rectangle(box.Left + adj, box.Bottom + adj, textX - 1, box.Top - adj);
break;
}
break;
}
if (textY < box.Bottom + offX)
textY = box.Bottom + offX;
if (iconBox != null && (iconBox.Width <= 0 || iconBox.Height <= 0))
iconBox = null;
bool haveIcon = false;
float boundingBoxWidth = 0;
float boundingBoxHeight = 0;
PdfArray matrix = null;
if (iconBox != null) {
if (image != null) {
tp = new PdfTemplate(writer);
tp.BoundingBox = new Rectangle(image);
writer.AddDirectTemplateSimple(tp, PdfName.FRM);
tp.AddImage(image, image.Width, 0, 0, image.Height, 0, 0);
haveIcon = true;
boundingBoxWidth = tp.BoundingBox.Width;
boundingBoxHeight = tp.BoundingBox.Height;
}
else if (template != null) {
tp = new PdfTemplate(writer);
tp.BoundingBox = new Rectangle(template.Width, template.Height);
writer.AddDirectTemplateSimple(tp, PdfName.FRM);
tp.AddTemplate(template, template.BoundingBox.Left, template.BoundingBox.Bottom);
haveIcon = true;
boundingBoxWidth = tp.BoundingBox.Width;
boundingBoxHeight = tp.BoundingBox.Height;
}
else if (iconReference != null) {
PdfDictionary dic = (PdfDictionary)PdfReader.GetPdfObject(iconReference);
if (dic != null) {
Rectangle r2 = PdfReader.GetNormalizedRectangle(dic.GetAsArray(PdfName.BBOX));
matrix = dic.GetAsArray(PdfName.MATRIX);
haveIcon = true;
boundingBoxWidth = r2.Width;
boundingBoxHeight = r2.Height;
}
}
}
if (haveIcon) {
float icx = iconBox.Width / boundingBoxWidth;
float icy = iconBox.Height / boundingBoxHeight;
if (proportionalIcon) {
switch (scaleIcon) {
case SCALE_ICON_IS_TOO_BIG:
icx = Math.Min(icx, icy);
icx = Math.Min(icx, 1);
break;
case SCALE_ICON_IS_TOO_SMALL:
icx = Math.Min(icx, icy);
icx = Math.Max(icx, 1);
break;
case SCALE_ICON_NEVER:
icx = 1;
break;
default: