iTextSharp垂直签名外观 [英] iTextSharp vertical SignatureAppearance

查看:103
本文介绍了iTextSharp垂直签名外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用令牌证书签名文档:

I'm signing a document with token certificate:

        var cp = new Org.BouncyCastle.X509.X509CertificateParser();
        var chain = new[] { cp.ReadCertificate(cert.RawData) };

        var externalSignature = new X509Certificate2Signature(cert, "SHA-1");

        var pdfReader = new PdfReader(origem);

        var signedPdf = new FileStream(destino, FileMode.Create);

        var pdfStamper = PdfStamper.CreateSignature(pdfReader, signedPdf, '\0');

        var sig = pdfStamper.SignatureAppearance;

        sig.SetVisibleSignature(new Rectangle(50, 0, 500, 50), pdfReader.NumberOfPages, "Signature");
        sig.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.DESCRIPTION;
        sig.Layer2Text = "Assinado digitalmente por " + cert.SubjectName.Name;
        sig.Layer2Font = new Font(Font.FontFamily.TIMES_ROMAN, 7);

        MakeSignature.SignDetached(sig, externalSignature, chain, null, null, null, 0, CryptoStandard.CMS);

签名文本显示在页面底部.如何在文档的右侧,内容边距之外更改为垂直模式?

The signature text is rendered at bottom of the page. How can I change to a vertical mode, in the right part of document, outside the content margins?

谢谢

推荐答案

首先,要获得一些垂直方向的签名,可视化签名的矩形应稍微垂直.因此,代替您的

First of all, to get some vertically oriented signature, the rectangle in which to visualize the signature should be somewhat more vertically oriented. Thus, in place of your

sig.SetVisibleSignature(new Rectangle(50, 0, 500, 50), pdfReader.NumberOfPages, "Signature");

您应该使用类似

sig.SetVisibleSignature(new Rectangle(50, 0, 50, 500), pdfReader.NumberOfPages, "Signature");

现在,您在注释中澄清了,不仅可视化矩形应具有垂直方向,而且文本也应垂直绘制.默认情况下,iText使用水平文本创建可视化效果.因此,您必须使用自定义外观.

Now you clarified in comments that not only the visualization rectangle should have a vertical orientation but that the text also should be drawn vertically. iText by default creates visualizations with horizontal text. Thus, you have to use customized appearances.

由于我经常在家使用iText/Java,因此自定义PdfSignatureAppearance appearance的示例在Java中.不过,转换为iTextSharp/C#应该很容易.

As I am more at home with iText/Java, this example to customize a PdfSignatureAppearance appearance is in Java. It should be easy to transform to iTextSharp/C#, though.

appearance.setVisibleSignature(rectangle, PAGENUMBER, SIGNATURENAME);

// customize appearance layer 2 to display text vertically
PdfTemplate layer2 = appearance.getLayer(2);
layer2.transform(new AffineTransform(0, 1, -1, 0, rectangle.getWidth(), 0));
Font font = new Font();
font.setColor(BaseColor.WHITE);
font.setSize(10);
ColumnText ct2 = new ColumnText(layer2);
ct2.setRunDirection(PdfWriter.RUN_DIRECTION_NO_BIDI);
ct2.setSimpleColumn(new Phrase("Signed by me, myself and I", font), 0, 0, rectangle.getHeight(), rectangle.getWidth(), 15, Element.ALIGN_CENTER);

ct2.go();

此示例在页面区域rectangle中垂直绘制由我,我和我签名".

This example draws "Signed by me, myself and I" vertically in the page area rectangle.

这篇关于iTextSharp垂直签名外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆