Discussion:
[itextsharp-questions] Signature Alignment
KrazySmile
2007-11-05 09:22:11 UTC
Permalink
Hey everyone.

Im trying to set the signature alignment to ALIGN_RIGHT.
Paulo Soares
2007-11-05 10:17:31 UTC
Permalink
-----Original Message-----
On Behalf Of KrazySmile
Sent: Monday, November 05, 2007 9:22 AM
Subject: [itextsharp-questions] Signature Alignment
Hey everyone.
Im trying to set the signature alignment to ALIGN_RIGHT.
It can't be done that way. You'll have to create the appearance
yourself. See the source of PdfSignatureApperance.cs.
KrazySmile
2007-11-05 10:54:32 UTC
Permalink
Sorry about that, didnt know about that.
I checked it, and i cant find anything.
Is this explained in the book? i have bought the book last week, but cant
find info about this.

Regards.
Post by Paulo Soares
-----Original Message-----
On Behalf Of KrazySmile
Sent: Monday, November 05, 2007 9:22 AM
Subject: [itextsharp-questions] Signature Alignment
Hey everyone.
Im trying to set the signature alignment to ALIGN_RIGHT.
It can't be done that way. You'll have to create the appearance
yourself. See the source of PdfSignatureApperance.cs.
Paulo Soares
2007-11-05 11:12:06 UTC
Permalink
Use the template returned from PdfSignatureAppearance.GetLayer(2) to
draw whatever you like.

Paulo
-----Original Message-----
On Behalf Of KrazySmile
Sent: Monday, November 05, 2007 10:55 AM
Subject: Re: [itextsharp-questions] Signature Alignment
Sorry about that, didnt know about that.
I checked it, and i cant find anything.
Is this explained in the book? i have bought the book last
week, but cant
find info about this.
Regards.
Post by Paulo Soares
-----Original Message-----
On Behalf Of KrazySmile
Sent: Monday, November 05, 2007 9:22 AM
Subject: [itextsharp-questions] Signature Alignment
Hey everyone.
Im trying to set the signature alignment to ALIGN_RIGHT.
It can't be done that way. You'll have to create the appearance
yourself. See the source of PdfSignatureApperance.cs.
KrazySmile
2007-11-05 12:01:50 UTC
Permalink
Tryed 2 diferent ways:
-------------------------------------------------------------------------
st = PdfStamper.CreateSignature(reader, fs, '\0', null, true);
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
st.SignatureAppearance.GetAppearance().BeginText();
st.SignatureAppearance.GetAppearance().SetFontAndSize(bf, 20);
st.SignatureAppearance.GetAppearance().ShowTextAligned(PdfContentByte.ALIGN_CENTER,
"This text is centered", 250, 700, 0);
st.SignatureAppearance.GetAppearance().EndText();

this one, despite i make SetFontAndSize... says that "before writing any
text you need to set font and size"
-------------------------------------------------------------------------
-------------------------------------------------------------------------
st = PdfStamper.CreateSignature(reader, fs, '\0', null, true);
PdfTemplate t = st.SignatureAppearance.GetLayer(2);
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
t.BeginText();
t.SetFontAndSize(bf, 20);
t.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "This text is centered", 250,
700, 0);
t.EndText();

st.Close();

Debuging the code, when it executes the st.close(), gives out the following:

{System.NullReferenceException: Object reference not set to an instance of
an object.
at iTextSharp.text.pdf.PdfRectangle..ctor(Rectangle rectangle)
at iTextSharp.text.pdf.PdfFormXObject..ctor(PdfTemplate template)
at iTextSharp.text.pdf.PdfTemplate.get_FormXObject()
at iTextSharp.text.pdf.PdfWriter.AddSharedObjectsToBody()
at iTextSharp.text.pdf.PdfStamperImp.Close(Hashtable moreInfo)
at iTextSharp.text.pdf.PdfSignatureAppearance.PreClose(Hashtable
exclusionSizes)
at iTextSharp.text.pdf.PdfSignatureAppearance.PreClose()
at iTextSharp.text.pdf.PdfStamper.Close()
Post by Paulo Soares
Use the template returned from PdfSignatureAppearance.GetLayer(2) to
draw whatever you like.
Paulo
-----Original Message-----
On Behalf Of KrazySmile
Sent: Monday, November 05, 2007 10:55 AM
Subject: Re: [itextsharp-questions] Signature Alignment
Sorry about that, didnt know about that.
I checked it, and i cant find anything.
Is this explained in the book? i have bought the book last
week, but cant
find info about this.
Regards.
Post by Paulo Soares
-----Original Message-----
On Behalf Of KrazySmile
Sent: Monday, November 05, 2007 9:22 AM
Subject: [itextsharp-questions] Signature Alignment
Hey everyone.
Im trying to set the signature alignment to ALIGN_RIGHT.
It can't be done that way. You'll have to create the appearance
yourself. See the source of PdfSignatureApperance.cs.
Paulo Soares
2007-11-05 12:22:32 UTC
Permalink
-----Original Message-----
On Behalf Of KrazySmile
Sent: Monday, November 05, 2007 12:02 PM
Subject: Re: [itextsharp-questions] Signature Alignment
--------------------------------------------------------------
-----------
st = PdfStamper.CreateSignature(reader, fs, '\0', null, true);
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
st.SignatureAppearance.GetAppearance().BeginText();
st.SignatureAppearance.GetAppearance().SetFontAndSize(bf, 20);
st.SignatureAppearance.GetAppearance().ShowTextAligned(PdfCont
entByte.ALIGN_CENTER,
"This text is centered", 250, 700, 0);
st.SignatureAppearance.GetAppearance().EndText();
this one, despite i make SetFontAndSize... says that "before
writing any
text you need to set font and size"
Not what I answered.
--------------------------------------------------------------
-----------
--------------------------------------------------------------
-----------
st = PdfStamper.CreateSignature(reader, fs, '\0', null,
true);
PdfTemplate t = st.SignatureAppearance.GetLayer(2);
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
t.BeginText();
t.SetFontAndSize(bf, 20);
t.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "This text is
centered", 250,
700, 0);
t.EndText();
st.Close();
Where's the signing code?

Paulo
Debuging the code, when it executes the st.close(), gives out
{System.NullReferenceException: Object reference not set to
an instance of
an object.
at iTextSharp.text.pdf.PdfRectangle..ctor(Rectangle rectangle)
at iTextSharp.text.pdf.PdfFormXObject..ctor(PdfTemplate template)
at iTextSharp.text.pdf.PdfTemplate.get_FormXObject()
at iTextSharp.text.pdf.PdfWriter.AddSharedObjectsToBody()
at iTextSharp.text.pdf.PdfStamperImp.Close(Hashtable moreInfo)
at iTextSharp.text.pdf.PdfSignatureAppearance.PreClose(Hashtable
exclusionSizes)
at iTextSharp.text.pdf.PdfSignatureAppearance.PreClose()
at iTextSharp.text.pdf.PdfStamper.Close()
Post by Paulo Soares
Use the template returned from PdfSignatureAppearance.GetLayer(2) to
draw whatever you like.
Paulo
-----Original Message-----
On Behalf Of KrazySmile
Sent: Monday, November 05, 2007 10:55 AM
Subject: Re: [itextsharp-questions] Signature Alignment
Sorry about that, didnt know about that.
I checked it, and i cant find anything.
Is this explained in the book? i have bought the book last
week, but cant
find info about this.
Regards.
Post by Paulo Soares
-----Original Message-----
On Behalf Of KrazySmile
Sent: Monday, November 05, 2007 9:22 AM
Subject: [itextsharp-questions] Signature Alignment
Hey everyone.
Im trying to set the signature alignment to ALIGN_RIGHT.
It can't be done that way. You'll have to create the appearance
yourself. See the source of PdfSignatureApperance.cs.
KrazySmile
2007-11-05 12:40:35 UTC
Permalink
I know it aint what you answer, it was just something i tryed.

with the signing code:

PdfTemplate t = st.SignatureAppearance.GetLayer(2);
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
t.BeginText();
t.SetFontAndSize(bf, 20);
t.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "This text is centered", 250,
700, 0);
t.EndText();

st.SignatureAppearance.GetAppearance().SetFontAndSize(bf, 20);
st.SignatureAppearance.GetAppearance().ShowTextAligned(PdfContentByte.ALIGN_CENTER,
"This text is centered", 250, 700, 0);
st.SignatureAppearance.GetAppearance().EndText();

sap.SetCrypto(this.myCert.Akp, this.myCert.Chain, null,
PdfSignatureAppearance.WINCER_SIGNED);
if (visible)
sap.SetVisibleSignature(new
iTextSharp.text.Rectangle(((float)400), ((float)135), ((float)600),
((float)165)), 1, null);

st.Close();
Post by Paulo Soares
-----Original Message-----
On Behalf Of KrazySmile
Sent: Monday, November 05, 2007 12:02 PM
Subject: Re: [itextsharp-questions] Signature Alignment
--------------------------------------------------------------
-----------
st = PdfStamper.CreateSignature(reader, fs, '\0', null, true);
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
st.SignatureAppearance.GetAppearance().BeginText();
st.SignatureAppearance.GetAppearance().SetFontAndSize(bf, 20);
st.SignatureAppearance.GetAppearance().ShowTextAligned(PdfCont
entByte.ALIGN_CENTER,
"This text is centered", 250, 700, 0);
st.SignatureAppearance.GetAppearance().EndText();
this one, despite i make SetFontAndSize... says that "before
writing any
text you need to set font and size"
Not what I answered.
--------------------------------------------------------------
-----------
--------------------------------------------------------------
-----------
st = PdfStamper.CreateSignature(reader, fs, '\0', null,
true);
PdfTemplate t = st.SignatureAppearance.GetLayer(2);
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
t.BeginText();
t.SetFontAndSize(bf, 20);
t.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "This text is
centered", 250,
700, 0);
t.EndText();
st.Close();
Where's the signing code?
Paulo
Debuging the code, when it executes the st.close(), gives out
{System.NullReferenceException: Object reference not set to
an instance of
an object.
at iTextSharp.text.pdf.PdfRectangle..ctor(Rectangle rectangle)
at iTextSharp.text.pdf.PdfFormXObject..ctor(PdfTemplate template)
at iTextSharp.text.pdf.PdfTemplate.get_FormXObject()
at iTextSharp.text.pdf.PdfWriter.AddSharedObjectsToBody()
at iTextSharp.text.pdf.PdfStamperImp.Close(Hashtable moreInfo)
at iTextSharp.text.pdf.PdfSignatureAppearance.PreClose(Hashtable
exclusionSizes)
at iTextSharp.text.pdf.PdfSignatureAppearance.PreClose()
at iTextSharp.text.pdf.PdfStamper.Close()
Post by Paulo Soares
Use the template returned from PdfSignatureAppearance.GetLayer(2) to
draw whatever you like.
Paulo
-----Original Message-----
On Behalf Of KrazySmile
Sent: Monday, November 05, 2007 10:55 AM
Subject: Re: [itextsharp-questions] Signature Alignment
Sorry about that, didnt know about that.
I checked it, and i cant find anything.
Is this explained in the book? i have bought the book last
week, but cant
find info about this.
Regards.
Post by Paulo Soares
-----Original Message-----
On Behalf Of KrazySmile
Sent: Monday, November 05, 2007 9:22 AM
Subject: [itextsharp-questions] Signature Alignment
Hey everyone.
Im trying to set the signature alignment to ALIGN_RIGHT.
It can't be done that way. You'll have to create the appearance
yourself. See the source of PdfSignatureApperance.cs.
KrazySmile
2007-11-05 17:45:45 UTC
Permalink
humm, i tryed to put the code after the signing process, dont give me any
errors, but also dont show the text on the pdf (only that text, everything
else is ok)

this is what i got:

PdfReader reader = new PdfReader(this.nome);
fs = new FileStream(this.nome1, FileMode.Create, FileAccess.Write);
st = PdfStamper.CreateSignature(reader, fs, '\0', null, true);

st.MoreInfo = this.metadata.getMetaData();
st.XmpMetadata = this.metadata.getStreamedMetaData();
PdfSignatureAppearance sap = st.SignatureAppearance;

Font fontSig = FontFactory.GetFont(FontFactory.HELVETICA, (float)7,
Font.NORMAL);
sap.Layer2Font = fontSig;

sap.SetCrypto(this.myCert.Akp, this.myCert.Chain, null,
PdfSignatureAppearance.WINCER_SIGNED);
if (visible)
sap.SetVisibleSignature(new iTextSharp.text.Rectangle(((float)400),
((float)134.5), ((float)600), ((float)164.5)), 1, null);

st.Close();

PdfTemplate t = st.SignatureAppearance.GetLayer(2);
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
t.BeginText();
t.SetFontAndSize(bf, 20);
t.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "This text is centered", 250,
700, 0);
t.EndText();

Any thoughts?

Regards
--
View this message in context: http://www.nabble.com/Signature-Alignment-tf4750392.html#a13591898
Sent from the itextsharp-questions mailing list archive at Nabble.com.
Paulo Soares
2007-11-06 08:53:58 UTC
Permalink
You must get the template after setting the field but before closing the
stamper. You must use the template dimensions.

Paulo

----- Original Message -----
From: "KrazySmile" <***@gmail.com>
To: <itextsharp-***@lists.sourceforge.net>
Sent: Monday, November 05, 2007 5:45 PM
Subject: Re: [itextsharp-questions] Signature Alignment
Post by KrazySmile
humm, i tryed to put the code after the signing process, dont give me any
errors, but also dont show the text on the pdf (only that text, everything
else is ok)
PdfReader reader = new PdfReader(this.nome);
fs = new FileStream(this.nome1, FileMode.Create, FileAccess.Write);
st = PdfStamper.CreateSignature(reader, fs, '\0', null, true);
st.MoreInfo = this.metadata.getMetaData();
st.XmpMetadata = this.metadata.getStreamedMetaData();
PdfSignatureAppearance sap = st.SignatureAppearance;
Font fontSig = FontFactory.GetFont(FontFactory.HELVETICA, (float)7,
Font.NORMAL);
sap.Layer2Font = fontSig;
sap.SetCrypto(this.myCert.Akp, this.myCert.Chain, null,
PdfSignatureAppearance.WINCER_SIGNED);
if (visible)
sap.SetVisibleSignature(new iTextSharp.text.Rectangle(((float)400),
((float)134.5), ((float)600), ((float)164.5)), 1, null);
st.Close();
PdfTemplate t = st.SignatureAppearance.GetLayer(2);
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
t.BeginText();
t.SetFontAndSize(bf, 20);
t.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "This text is centered", 250,
700, 0);
t.EndText();
Any thoughts?
Regards
KrazySmile
2007-11-06 10:38:20 UTC
Permalink
Ok, thank you, it worked. I was just doing it the wrong order.
Bellow is the code for others to reference.

I got one last question:
Before i sign, i have already filled st.MoreInfo and st.XmpMetadata
with the correct values.
If i dont make the code below, meaning , just sign and close stamper, on the
signature, it will apear:
"Digitally signed by ME ... Date... 2007.11.06...."

When i make the code below, this information desapears, and it shows on the
stamp the text i tell to write.
My question is:
when i make the code bellow, all the other info in st.MoreInfo and
st.XmpMetadata disapear on the stamp.
what i wanted to affect in the first place, was preciselly information.

So, is there a way to affect that, or on the template, i've got to "build"
my own text to show?

Regards, and thanks for the help.



sap.SetCrypto(this.myCert.Akp, this.myCert.Chain, null,
PdfSignatureAppearance.WINCER_SIGNED);
if (visible)
sap.SetVisibleSignature(new iTextSharp.text.Rectangle(((float)300),
((float)134.5), ((float)500), ((float)164.5)), 1, null);

PdfTemplate template = st.SignatureAppearance.GetLayer(2);
template.MoveTo(0, 200);
template.LineTo(500, 0);
template.Stroke();
template.BeginText();
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
template.SetFontAndSize(bf, 7);
template.SetTextMatrix(0, 0);
template.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "This text is lefted",
0, 0, 0);
template.EndText();
st.Close();
--
View this message in context: http://www.nabble.com/Signature-Alignment-tf4750392.html#a13604114
Sent from the itextsharp-questions mailing list archive at Nabble.com.
Continue reading on narkive:
Loading...