Joseph Michael Pesch
VP Programming

Open Source PDF Generator iTextSharp

by 23. July 2010 17:19

iTextSharp-SampleC#WebSite.zipx (2.49 mb)

itextsharp-5.0.6-dll.zip (1.19 mb)

Sample code to populate form fields in template and save as new document (via C# web page):

using System;

using System.IO;

using iTextSharp.text.pdf;

 

publicpartialclassFillFormFields : System.Web.UI.Page

{

  protectedvoid Page_Load(object sender, EventArgs e)

  {

    GeneratePDF();

  }

 

  protectedvoid GeneratePDF()

  {

    // Setup the output file

    string pdfOutputFilePath = @"Output\FillFormFields-"

      + DateTime.Now.ToString()

      .Replace("/", "_")

      .Replace(":", "_")

      .Replace(" ", "_")

      + ".pdf";

    FileStream pdfOutputFile

      = newFileStream(Server.MapPath(pdfOutputFilePath)

        , FileMode.Create, FileAccess.ReadWrite);

    // Load the template file

    PdfReader pdfReader = newPdfReader(Server.MapPath(@"Templates\FillFormFields.pdf"));

    PdfStamper pdfStamper = null;

    pdfStamper = newPdfStamper(pdfReader, pdfOutputFile);

    // Get the form fields object

    AcroFields pdfForm = pdfStamper.AcroFields;

    // Fill the form fields with data

    pdfForm.SetField("Lead.LastAction.Date", DateTime.Now.ToString("MMMM dd, yyyy"));

    // Close the documents

    pdfStamper.FormFlattening = true;

    pdfStamper.Close();

    pdfReader.Close();

  }

}

 

 

 

Tags:

ASP.Net | C#

jQuery Setting Tab Order

by 22. July 2010 18:58

$(function () {

  var tabindex = 1;

  $('input,select').each(function () {

    if (this.type != "hidden") {

      var $input = $(this);

      $input.attr("tabindex", tabindex);

      tabindex++;

    }

  });

});

Tags:

[None]

jQuery Capture Tab Key

by 22. July 2010 18:57

$('#MyTextBoxID).live('keypress', function (e) {

  if (e.keyCode == 9) {

    e.preventDefault();

    // custom code here...

  }

});

 

Tags:

[None]

Microsoft CRM

by 21. July 2010 19:20

Tags:

[None]

A potentially dangerous Request.Form value was detected from the client

by 3. July 2010 17:30

This post is not about how to properly deal with this issue, it is solely about how to circumvent the error if you are inclined to do so.

Add ValidateRequest="false" attribute to the @Page directive of the page in question.  NOTE: If running .Net framework 4 you may also need to add <httpRuntimerequestValidationMode="2.0" /> to the <system.websection of the Web.config file.

 

Tags:

ASP.Net

SQL Conditional Inner/Outer Join on Foreign Key Table

by 1. July 2010 18:10

createtable

#ForeignKeyParentTable

(

  RecID intidentity(1,1)primarykey

, Bogus bitnotnull

)

 

createtable

#ForeignKeyChildTable

(

  RecID intidentity(1,1)primarykey

, ParentID intnotnull

,constraint fk_ForeignKeyParentChildTable foreignkey

  (ParentID)references #ForeignKeyParentTable(RecID)

)

 

-- Insert five records into parent

insertinto #ForeignKeyParentTable(Bogus)values(1)

insertinto #ForeignKeyParentTable(Bogus)values(1)

insertinto #ForeignKeyParentTable(Bogus)values(1)

insertinto #ForeignKeyParentTable(Bogus)values(1)

insertinto #ForeignKeyParentTable(Bogus)values(1)

 

-- Insert three related records into child

insertinto #ForeignKeyChildTable(ParentID)values(1)

-- skip parent 2

insertinto #ForeignKeyChildTable(ParentID)values(3)

-- skip parent 4

insertinto #ForeignKeyChildTable(ParentID)values(5)

 

-- Perform two select statements

-- once with the @IncludeAll off

-- and then with the @IncludeAll on

declare @IncludeAll int

set @IncludeAll =-1

while @IncludeAll < 1 begin

  set @IncludeAll = @IncludeAll + 1

  select

    p.RecID

  , c.RecID

  from #ForeignKeyParentTable p

  leftjoin #ForeignKeyChildTable c

  on p.RecID = c.ParentID

  where 1 =case

    when @IncludeAll = 1

    then 1 elsecase

      when c.RecID isnull

      then 0 else 1 endend

end

 

droptable #ForeignKeyParentTable

droptable #ForeignKeyChildTable

 

 

 

Tags:

SQL Server