Код: Выделить всё
Rectangle rect = new Rectangle(x, y, width, height);
SignerProperties signerProperties = new SignerProperties()
.SetReason(reason)
.SetLocation(location)
.SetPageNumber(1)
.SetPageRect(rect);
// Create a signature field (visible signature)
var field = new SignatureFormFieldBuilder(signer.GetDocument(), "SignatureField")
.SetWidgetRectangle(rect)
.CreateSignature();
PdfAcroForm form = PdfFormCreator.GetAcroForm(signer.GetDocument(), true);
form.AddField(field);
Div appearanceContent = GenerateAppearanceContent(rect);
// Build signature appearance
SignatureFieldAppearance appearance =
new SignatureFieldAppearance("SignatureField")
.SetContent(appearanceContent);
// Attach to signer properties
signerProperties.SetSignatureAppearance(appearance);
signer.SetSignerProperties(signerProperties);
Код: Выделить всё
public Div GenerateAppearanceContent(Rectangle rect)
{
var div = new Div();
Image img = new Image(ImageDataFactory.Create(HostingEnvironment.MapPath(ConfigurationManager.AppSettings["ImagePath"])));
var signingText = "..."
var textRect = new Rectangle(MARGIN, MARGIN, 2 * rect.GetWidth() / 3 - 2 * MARGIN, rect.GetHeight() - 2 * MARGIN);
var imageRect = new Rectangle(rect.GetX() + 2 * rect.GetWidth() / 3 + MARGIN / 2, rect.GetY() + MARGIN, rect.GetWidth() / 3 - MARGIN, rect.GetHeight() - 2 * MARGIN);
var paragraph = new Paragraph(signingText).SetFont(font).SetMargin(paragraphMargin).SetMultipliedLeading(0.9f).SetFontSize(paragraphFontSize);
var textDiv = new Div();
textDiv.SetHeight(textRect.GetHeight());
textDiv.SetWidth(textRect.GetWidth());
textDiv.SetVerticalAlignment(VerticalAlignment.TOP);
textDiv.Add(paragraph).SetBorder(new SolidBorder(ColorConstants.YELLOW, 1));
var imageDiv = new Div();
imageDiv.SetHeight(imageRect.GetHeight());
imageDiv.SetWidth(imageRect.GetWidth());
imageDiv.SetVerticalAlignment(iText.Layout.Properties.VerticalAlignment.TOP);
imageDiv.SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER);
imageDiv.Add.SetBorder(new SolidBorder(ColorConstants.BLUE, 1));
var flexContainer = new Div();
flexContainer.SetProperty(Property.FLEX_WRAP, FlexWrapPropertyValue.WRAP);
flexContainer.SetProperty(Property.FLEX_DIRECTION, FlexDirectionPropertyValue.ROW);
flexContainer.SetProperty(Property.ALIGN_ITEMS, AlignmentPropertyValue.FLEX_START);
flexContainer.Add(textDiv.SetBorder(new SolidBorder(ColorConstants.BLUE, 1)))
.Add(imageDiv)
.SetBorder(new SolidBorder(ColorConstants.GREEN, 1));
flexContainer.SetNextRenderer(new FlexContainerRenderer(flexContainer));
div.SetPadding(0).SetMargin(0);
div.Add(flexContainer);
div.SetBorder(new SolidBorder(ColorConstants.RED, 1));
return div;
}
Подробнее здесь: https://stackoverflow.com/questions/799 ... text-9-0-5
Мобильная версия