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.

Monday, October 10, 2011

ClientScript.RegisterStartupScript Not Working?

ClientScript.RegisterStartupScript is used to call javascript in the .net code-behind. Once you learn this nice little trick, you think it is great, until one day years later on another page/project you try it again, but it does not work.

First, please check if the control/page you are trying to update contains an UpdatePanel. If so, keep reading.

This WON'T work with an UpdatePanel (in my experience). You will need to use: ScriptManager.RegisterStartupScript

For example:
ScriptManager.RegisterStartupScript(this, this.GetType(), "saving", "doneSaving();", true);

Also, in VS, it did not seem to recognize ScriptManager, when I right-clicked to "Resolve" it gave me no options. I am not sure why but I had to add "using System.Web.UI;" to my using clauses manually. Maybe that was some quirk with my page though...

Wednesday, September 21, 2011

ScriptManager History UpdatePanel

I just beat my head against the wall for an entire morning trying to figure out why the simple ScriptManager History functionality was not working with my UpdatePanel.

First off, I inherited this code, so I was just working with what was there without paying much attention to it. The previous person had setup an UpdatePanel without putting in a Trigger tag. So that should have been clue NUMBER 1, but I overlooked that so that was a good two hours wasted in just not paying attention to that.

Oh well, so I kept following all the simple steps listed on the 'net for setting up the ScriptManager to keep history points. Brief overview:

1) Add a ScriptManager to the page like this:
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableHistory="True" OnNavigate="MainScriptManager_Navigate" EnableSecureHistoryState="True"/>


2)Add the associated function to the code-behind :
protected void MainScriptManager_Navigate(object sender, HistoryEventArgs e)
{
    string panelName = e.State["S"];

     switch (panelName)
     {
      case "Panel_Store_CC":
      Panel_Store_CC.Visible = true;
      break;
      default:
      break;
     }
}

3) Add history points when needed in code calls (in my example it was a button click):
if (ScriptManager1.IsInAsyncPostBack && !ScriptManager1.IsNavigating)
 ScriptManager.GetCurrent(this).AddHistoryPoint("S", "Panel_Store_CC");


After several hours, history was not being added the browser's back in any browser (Chrome/IE/FireFox)....I began noticing during my debugging I was hitting the Page_Load code on each button click. DUH! This was not right...so I finally figured out that I needed a trigger for the updatepanel. At first I added an Asynchoronous trigger, but that still did not work HOWEVER once I added the PostBackTrigger for the button, it finally worked since the entire page was not being posted back!

<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>

Sunday, August 14, 2011

PHP Pear Spreadsheet Write - File Error: Data may have been lost

I needed to write out data to a spreadsheet file so I installed PHP PEAR's Spreadsheet Excel Writer. It is pretty easy to use. I wrote the code I needed but kept getting the following error upon opening the file:
File Error: Data may have been lost.

So then I went to PHPExcel, however, when I installed the code to production I realized it was still on PHP4, and that only works with PHP5...

So I went back to the Spreadsheet Excel Writer. I noticed that the files opened just fine, and all the data was there, so it really worked, however, I imagined fielding calls from user's asking what the error was...and I felt it would be more credible if I did not have this error popping up.

So along the way I figured out what caused the error for myself. I had several 'for loops' that wrote out data like this:

foreach ($collection as $key => $value)
{
$value = trim($value);

if($value != "")
$sheet->write($index,$cellLetter, $value);

}

So I replaced the 'for loops' with the 'writeCol' function that would write out an entire collection into a column.

$sheet->writeCol (8 , 3 , $collection);

This worked for almost every instance where I was looping thru collections, there was one instance where I could not apply this logic, but since it was only about 10 lines of repeating code, I opted to do that rather than cause the Data Lost error. So I am pretty happy with that.

If we ever upgrade to PHP5, I will consider just using the PHPExcel code since I never had the Data Lost error with it.

Hope that helps!

Saturday, July 9, 2011

Struggling with PHP SMTP/Email?

Well, as I am diving into the world of PHP (coming from a Microsoft world), I have found setting up the PHP environment to be rather frustrating for myself. With MS, you install Visual Studio, use the built in web server or optionally hook up to the local IIS and you're off for the most part.

However, PHP, in my experience, isn't so ready to go. The installation of extra stuff can be quite a headache, but it is open source/free so you learn to just deal with it I suppose.

So I wanted to get a small program to send email. From my reading, I needed to install PEAR. I found this article to be the most helpful, easy instructions for those on a Windows system. http://www.geeksengine.com/article/install-pear-on-windows.html

I later found I needed to two more installs the Net_SMTP and the Net_Socket, it said Net_SMTP is optional, but I think I needed it.

To install these, I follow the same idea, I download the archive file, then unzip it to a local folder, copy the needed file/folder located inside to the PEAR directory which is inside the PHP install directory.

Extra installs:

http://pear.php.net/package/Net_SMTP/

http://pear.php.net/package/Net_Socket/

For the Net_SMTP, I copied SMTP.php to the NET folder (you many need to create the NET folder)

And then for the Net_Socket, I copied the Socket.php to the NET folder.

I can't quite be sure this are the precise/correct instructions, but I do know I was able to successfully send email!

Sunday, June 19, 2011

Migrating Email into Google from existing server

I was testing the migration of email being hosted on Yahoo Business to Google Apps Business. Google has tool in the Account options listed as 'Get mail from other accounts:'. You can use this tool to migrate emails from the existing inbox into the new gmail inbox.

However, in my migration the email addresses were the same name because I wanted to use the same domain and user name and only switch who hosted it. Google gave me an error because I was trying to use the same email address.

For example you are trying to move 'junk@junk.com' on yahoo to 'junk@junk.com' now hosted on gmail. For me, I received an error trying to do this. So to get around this error, type that you are migrating 'junk1@junk.com' then proceed to give it the correct Login credentials for the account. That should work! It did for me.

Actually, I am not really sure why this error happens, it may be totally legit. Maybe Gmail just wants the stuff coming in to be uniquely name or just that account move uniquely named. I have no idea and there was not info in the error message....

Hope that helps!

Monday, June 13, 2011

VS 2010 Report runs locally, but not on server

Last week, I attempted to work with the VS 2010 reporting component. It took a bit of time to figure out setting up a data source...getting a decent layout, etc. All I really needed was a basic report that allowed the user the option of exporting the data to Excel. The VS built-in tool did everything I needed.

Once I got it running on my local server, I moved it up to the production server that was provided by a third party vendor. However, once I moved out there, I received the error: 'Local report processing requires FullTrust Code Access Security permissions, which is unavailable to the calling code. Grant the application FullTrust permissions or use ServerReport to execute the report remotely.'

After modifying various reporting options inside the reporting component and then in the code-behind, nothing seemed to work. Until I found a post that mentioned the web.config settings. And that resolved it. Make sure you have moved all of the related reporting web.config items (I did not have everything initially...) then try adding the following tag in the <system.web> section:

<trust level="Full" />

This change did it for me. Hope that helps!

Wednesday, May 18, 2011

Blackberry Curve - PC can't read Micro SD

After updating my Blackberry Desktop software, my pc could no longer read my mirco sd card via the USB via the Blackberry, although I had no problems with it before.

After doing all the usual stuff, reboot, reload software, pull battery out, verify card can be read by other means. i finally found this post: http://forums.pinstack.com/f59/mass_storage_issues_heres_the_fix-96938/

and it worked! i used the first option of extracting the rar files, i had tried the calfix executable but that did not seem to work.

hope this helps!

Wednesday, May 4, 2011

ASP.NET URL Routing

I have been hesitant to setup URL Rewriting using IIS. Previously, I setup simple redirects that never seem to work correctly. Plus figuring out the right Regex is a pain.

So I thought I might try again by setting up a single url call to be URL Friendly. I used the IIS URL Rewrite module. I was able to get the URL to accept and process my friendly url but, I had issues with post backs and then the required validators quit working.

So after a little research, I decided to try ASP.NET URL Routing available to for web form in 4.0. It turned out to be pretty easy for what I needed. Here are my steps:

Set up ASP.NET URL Routing in web.config

ASP.NET Development Server:
<httpModules>
<add name="RoutingModule"
type="System.Web.Routing.UrlRoutingModule,
System.Web.Routing,
Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<!-- ... -->
</httpModules>

IIS 7:
<modules runAllManagedModulesForAllRequests="true">
....
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>

<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>

I wanted the url look like this:
http:/mysite.com/program/submit/12356789

But act like this:
http:/mysite.com/program/submit/page.aspx?key=12356789

I wanted to pick up the 'key' query string and then go my merry way with it.

So with the URL routing I needed to setup some code in the Global.asax to tell it how to set up the identify and use the url:

void Application_Start(object sender, EventArgs e)
 {
   ....
   RegisterRoutes(System.Web.Routing.RouteTable.Routes);
 }

void RegisterRoutes(System.Web.Routing.RouteCollection routes)
 {

   routes.MapPageRoute(
   "View Page", // Route name
   "program/submit/{key}", // Route URL
   "~/program/submit/page.aspx" // Web page to handle route
   );
 }

Inside the Page.aspx Page_load I can pick up the 'key' value like this:

protected void Page_Load(object sender, EventArgs e)
 {
   if (IsPostBack)
    return;

   if (Page.RouteData.Values["key"] != null || Page.RouteData.Values["key"] != string.Empty)
 {
   string key = Page.RouteData.Values["key"].ToString();    //Request.QueryString["key"].ToString();
...
 }

Also, in pages that produce the user friendly url, I was able to build the url using the GetRouteUrl method:

string guid = "XXXX";
string url = Page.GetRouteUrl("View CIK", new { key = guid }); //returns: program/submit/1234567

So far it seems like I am not having any post back issues. So I think I'm liking this feature! So maybe I will set up a few more links as friendly urls sometime soon.

Thursday, April 7, 2011

Having Trouble with TabIndex in ASP.NET?

I have had some trouble with my TabIndex on a couple of ASP.NET forms for a long while now. I just recently decided to investigate further on this annoying issue (really who has time for that stuff?!).

For the most part, this property does work correctly, however, inside of Wizard or ASP.NET pre-made controls (Login), it seems to not function as you would expect?

Let's start with the first check, make sure that you set the first TabIndex to 1 (TabIndex="1"). Supposedly browsers default the address bar to 0 so you are supposed to set yours to 1. If that does not fix your issue, continue.

If you are using a Wizard control or Login control, set the Wizard or Login control to TabIndex="1", then proceed to number the rest of your TextBoxes and stuff from there. That should fix it.

Amazingly, this solution was my own idea, I couldn't find anything on the 'net that covered this issue! So now I'm posting to help some poor busy programmer left to solve such an annoying problem.

Hope that helps someone.

Friday, March 4, 2011

Gmail - Email Blast - Fix Ugly Table Gap with Images

I recently changed my email blast code which then began creating gaps in between images in a table, however, the problem only seemed to be in Gmail. Everything else looked ok.

The fix was easy. I just had to add style="display:block" to the image tag. And it was good to go!

I took the tip from this site: http://www.nurulam.in/2010/06/email-newsletter-extra-table-row-gap-in-gmail/

Thought I would share just in case someone else needed to know.