Wednesday, November 30, 2011

iTextSharp AcroField Font Size

While working with iTextSharp to fill AcroFields in a PDF, I noticed the font size of the text fields were a little larger than I wanted.

I found this great post that helped me out http://www.keithnordstrom.com/?tag=/itextsharp

which boils down to this:

AcroFields fields = stamper.AcroFields;
bool set = fields.SetFieldProperty(fieldName, "textsize", 12.0f, null);

The only thing to note is that you must set the form field size before putting text into the field otherwise it won't work...

Sunday, November 13, 2011

PHP PEAR Spreadsheet

I had my PHP/PEAR Spreadsheet writing working for several months on GoDaddy, however, GoDaddy did an upgrade of Apache to 1.3.33 without me knowing. So I found out a month later that my spreadsheet writer was no longer working. I found that the OLE was erroring out that is could not create a temp file.(after days of debugging).

To fix this error, I added a temp directory to the code like this:

$excel = new Spreadsheet_Excel_Writer($name);

//needed for upgrade to apache 1.3
$excel->setTempDir('temp');


Of course, I added the folder to the server, and it is working...after days and days of head-banging....

Wednesday, November 2, 2011

DocuSign Missing Form Field Data

So I have been testing out DocuSign to see if it will fit a need I have for documents to be electronically signed. I have been using the Embedded signing and I've like it so far. It took some tinkering to get the CreateEnvelopeFromTemplatesAndForms to work with an inline template but once it worked it was great.

Here is my short sample:

// Configure the envelope information
DocuSignAPI.EnvelopeInformation envelopeInfo = new DocuSignAPI.EnvelopeInformation();
envelopeInfo.AccountId = "XX";
envelopeInfo.EmailBlurb = "You sign this.";
envelopeInfo.Subject = "Please sign!";

DocuSignAPI.CompositeTemplate template = new DocuSignAPI.CompositeTemplate();

DocuSignAPI.Recipient[] signers = ConstructRecipients();

DocuSignAPI.InlineTemplate inlineTemplate = new DocuSignAPI.InlineTemplate();
inlineTemplate.Sequence = "1";
inlineTemplate.Envelope = new DocuSignAPI.Envelope();
inlineTemplate.Envelope.Recipients = signers;
inlineTemplate.Envelope.AccountId = ConfigurationManager.AppSettings["DSAPIAccountID"].ToString();

Tab tab = new Tab();
tab.DocumentID = "1";
tab.RecipientID = randomId;
tab.Type = TabTypeCode.SignHere;
tab.PageNumber = "9";
tab.AnchorTabItem = new AnchorTab();
tab.AnchorTabItem.AnchorTabString = "Person Signature Line";
tab.AnchorTabItem.Unit = UnitTypeCode.Pixels;
tab.AnchorTabItem.UnitSpecified = true;
tab.AnchorTabItem.XOffset = -10;
tab.AnchorTabItem.YOffset = -20;

inlineTemplate.Envelope.Tabs = new DocuSignAPI.Tab[] { tab };

template.InlineTemplates = new InlineTemplate[] { inlineTemplate };

// Configure the document
template.Document = new DocuSignAPI.Document();

template.Document.ID = "1";
template.Document.Name = "Document Name";

PDFGenerator generator = new PDFGenerator();
byte[] documentBytes = generator.DownloadFile();

template.Document.PDFBytes = documentBytes;

template.Document.TransformPdfFields = true;
template.Document.FileExtension = "pdf";

status = client.CreateEnvelopeFromTemplatesAndForms(envelopeInfo, new DocuSignAPI.CompositeTemplate[] { template }, true);

if (status.SentSpecified)
{
base.AddEnvelopeID(status.EnvelopeID);
// Start the first signer
SignFirst(status);
}
...

Ok. Although I could run the code, make the document show up in the iframe and have the little "Sign Here" block show up in the right spot, the BIG problem I had was my form field data that I was populating was missing when it was uploaded to DocuSign.

After hours and hours of testing, looking at my PDF's...blah blah blah..I noticed that sometimes that data did show up in a couple of my documents. And after more testing, I found that if my form fields first showed up on page 6, I was good to go. However, if they showed up on page 7, they were blank..and what good is signing off on document when the data is blank? (this was in the API and online console)

Anyhow, so I contacted DocuSign. They said this was an issue with the Chrome browser. So I tried out uploading thru the online console using IE. And sure enough that did work. So they recommended I user IE/FireFox. However when I tried again thru the API in IE/FF it was no go.

So being frustrated over this for many days, I FINALLY had a crazy thought - put a dummy field on page 4 (could be 1,2,3,4,5,or 6) but I had room on 4. I made it invisible too.

And viola...it worked! Relief...now I can move on in life. I do hope DocuSign does get that resolved though. If a difference of a single page can make or break it, I think you might have some coding problems. Hehe.