NK-Inc.com
PDF Programming Tutorials

PDF Programming Tutorials

Programming Dynamic PDF forms using FDFToolkit.net

Tags: | Categories: PDF Programming Posted by NicK on 1/28/2010 8:54 AM | Comments (0)
This method demonstrates how to populate an image field in a LiveCycle form using FDF Toolkit .net and VB.net.
Private Sub ImageFieldManipulations()
        ' INSERTS IMAGE IN IMAGE FIELD ON LIVECYCLE FORMS
        Dim cFDFApp As New FDFApp_Class()
        Dim cFDFDoc As New FDFDoc_Class()
        cFDFDoc = cFDFApp.FDFCreate
        cFDFDoc.XDPAddForm("subform1", Server.MapPath("test_livecycle-image1.pdf"))
        cFDFDoc.XDPAddField("FullName", "Bo Duke", "subform1", FDFDoc_Class.FieldType.FldTextual)
        cFDFDoc.XDP_Add_ImageField("Image1", "subform1", Server.MapPath("Signature_01_Small.jpg"), True)
        Response.Clear()

        ' WRITE XDP DATA TO BUFFER
        Response.ContentType = cFDFApp.MimeXDP
        Response.BinaryWrite(cFDFDoc.FDFSavetoBuf(FDFDoc_Class.FDFType.XDP, True))

        ' WRITE MERGED XDP/PDF TO BUFFER
        'Response.ContentType = cFDFApp.MimePDF
        'Response.BinaryWrite(cFDFDoc.PDFMergeXDP2Buf(Server.MapPath("test_livecycle-image1.pdf"), False, ""))

        ' WRITE MERGED XDP/PDF TO FILE
        'cFDFDoc.PDFMergeXDP2File(Server.MapPath("test_livecycle-image-MERGED.pdf"), Server.MapPath("test_livecycle-image1.pdf"), False, "")

        Response.End()
    End Sub
Categories: PDF Programming Posted by NicK on 10/21/2009 9:30 AM | Comments (0)

        Dim cFDFApp As New FDFApp.FDFApp_Class
        Dim cFDFDoc As New FDFApp.FDFDoc_Class
        cFDFDoc = cFDFApp.FDFCreate
        'cFDFDoc.XDPAddForm("subform1", Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.LastIndexOf("/") + 1) & "test_livecycle.pdf")
        ' !IMPORTANT ADD FORM (IF SINGLE PAGE THEN JUST ENTER "subform1"),PATH TO BLANK PDF
        cFDFDoc.XDPAddForm("subform1", Server.MapPath("test_livecycle.pdf"))
        ' ADD FIELDS
	  'cFDFDoc.XDPSetValue(FieldName, FieldValue)
        cFDFDoc.XDPSetValue("FullName", "Nick")
        cFDFDoc.XDPSetValue("Email", "no-reply@nk-inc.com")
        cFDFDoc.XDPSetValue("StreetAddress", "111 Easy Street")
        cFDFDoc.XDPSetValue("City", "Clinton Township")
        cFDFDoc.XDPSetValue("State", "MI")
        cFDFDoc.XDPSetValue("Country", "United States")
        cFDFDoc.XDPSetValue("PhoneNumber", "(586)-555-1111")
        cFDFDoc.XDPSetValue("FaxNumber", "(586)-555-1212")
        cFDFDoc.XDPSetValue("ZipCode", "48000")
        ' CLEAR RESPONSE (HTML CODE)
        Response.Clear()
        ' SET MIME BEFORE SENDING TO BUFFER
        Response.ContentType = cFDFApp.MimePDF
        'sends pdf to buffer (Flattens = False)
        Response.BinaryWrite(cFDFDoc.PDFMergeFDF2Buf(Server.MapPath("test_livecycle.pdf"), False, ""))

        'merges to fil
        'cFDFDoc.PDFMergeXDP2File(Server.MapPath("test_livecycle_new.pdf"), Server.MapPath("test_livecycle.pdf"), False, "")
        'sends pdf to buffer (Flattens = Tru)
        'Response.BinaryWrite(cFDFDoc.PDFMergeFDF2Buf(Server.MapPath("test_livecycle.pdf"), True, ""))
        'sends xdp to buffer
        'Response.BinaryWrite(cFDFDoc.FDFSavetoBuf(FDFDoc_Class.FDFType.XDP, True))
        Response.End()
Categories: PDF Programming Posted by NicK on 10/21/2009 9:30 AM | Comments (0)
        Dim cFDFApp As New FDFApp.FDFApp_Class
        Dim cFDFDoc As New FDFApp.FDFDoc_Class
        cFDFDoc = cFDFApp.FDFCreate
        'cFDFDoc.XDPAddForm("subform1", Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.LastIndexOf("/") + 1) & "test_livecycle.pdf")
        ' !IMPORTANT ADD FORM (IF SINGLE PAGE THEN JUST ENTER "subform1"),PATH TO BLANK PDF
        cFDFDoc.XDPAddForm("subform1", Server.MapPath("test_livecycle.pdf"))
        ' ADD FIELDS
	  'cFDFDoc.XDPSetValue(FieldName, FieldValue)
        cFDFDoc.XDPSetValue("FullName", "Nick")
        cFDFDoc.XDPSetValue("Email", "no-reply@nk-inc.com")
        cFDFDoc.XDPSetValue("StreetAddress", "111 Easy Street")
        cFDFDoc.XDPSetValue("City", "Clinton Township")
        cFDFDoc.XDPSetValue("State", "MI")
        cFDFDoc.XDPSetValue("Country", "United States")
        cFDFDoc.XDPSetValue("PhoneNumber", "(586)-555-1111")
        cFDFDoc.XDPSetValue("FaxNumber", "(586)-555-1212")
        cFDFDoc.XDPSetValue("ZipCode", "48000")
        ' CLEAR RESPONSE (HTML CODE)
        Response.Clear()
        ' SET MIME BEFORE SENDING TO BUFFER
        Response.ContentType = cFDFApp.MimePDF
        'sends pdf to buffer (Flattens = False)
        'Response.BinaryWrite(cFDFDoc.PDFMergeXDP2Buf(Server.MapPath("test_livecycle.pdf"), False, ""))

        'merges to fil
        'cFDFDoc.PDFMergeXDP2File(Server.MapPath("test_livecycle_new.pdf"), Server.MapPath("test_livecycle.pdf"), False, "")
        'sends pdf to buffer (Flattens = True)
        'Response.BinaryWrite(cFDFDoc.PDFMergeXDP2Buf(Server.MapPath("test_livecycle.pdf"), True, ""))
        'sends xdp to buffer
        'Response.BinaryWrite(cFDFDoc.FDFSavetoBuf(FDFDoc_Class.FDFType.XDP, True))
        Response.End()
Posted by NicK on 8/27/2009 12:35 PM | Comments (0)
Imports FDFApp
Imports FDFApp.FDFApp_Class
Imports FDFApp.FDFDoc_Class
Partial Public Class testForm1
    Inherits System.Web.UI.Page
    Private URLPath As String = ""
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        URLPath = Request.Url.AbsoluteUri.ToString & ""
        URLPath = URLPath.Substring(0, URLPath.LastIndexOf("/") + 1) & ""
        Try
	  Load_Data(URLPath & "PDFFormName.pdf", Request("id") + 0, FDFApp.FDFDoc_Class.FDFType.PDF)
        Catch Ex As Exception
	  Response.Write("Error: " & Ex.Message)
	  Response.End()
        End Try
    End Sub
    Public Sub Load_Data(ByVal PDFFile As String, ByVal ID As Integer, ByVal OutPutMIMEType As FDFApp.FDFDoc_Class.FDFType)
        ' DECLARE THE COMPONENTS
        Dim FDFApp As New FDFApp.FDFApp_Class
        Dim FDFDoc As New FDFApp.FDFDoc_Class
        ' INITIALIZE THE COMPONENTS
        FDFDoc = FDFApp.FDFCreate
        FDFDoc.FDFSetFile(PDFFile)
        Dim myDA As New OleDb.OleDbDataAdapter("SELECT * FROM [TABLENAME] WHERE ID=" & ID & ";", "PROVIDER=MICROSOFT.JET.OLEDB.4.0; DATA SOURCE=" & Server.MapPath("/APP_DATA/myDATABASE.mdb") & ";")
        Dim myDS As New DataSet
        myDA.Fill(myDS, "TABLENAME")
        ' SETS VALUES FROM TABLE ROW TO FDF
        FDFDoc.FDFSetValuesFromDataRow(myDS.Tables(0).Rows(0))
        ' WRITE THE FDF TO THE BUFFER
        Response.Clear()
        Select Case OutPutMIMEType
	  Case Global.FDFApp.FDFDoc_Class.FDFType.FDF
	      Response.ContentType = FDFApp.MimeFDF
	      Response.BinaryWrite(FDFDoc.FDFSavetoBuf(Global.FDFApp.FDFDoc_Class.FDFType.FDF, False))
	  Case Global.FDFApp.FDFDoc_Class.FDFType.PDF
	      Response.ContentType = FDFApp.MimePDF
	      Response.BinaryWrite(FDFDoc.PDFMergeFDF2Buf(PDFFile, False, ""))
	  Case Global.FDFApp.FDFDoc_Class.FDFType.XDP
	      Response.ContentType = FDFApp.MimeXDP
	      Response.BinaryWrite(FDFDoc.FDFSavetoBuf(Global.FDFApp.FDFDoc_Class.FDFType.XDP, True))
        End Select
        Response.End()
    End Sub

End Class
Categories: PDF Programming Posted by NicK on 3/27/2009 4:43 PM | Comments (0)

LiveCycle Setup Part I

Here are the setting in order to parse LiveCycle Form data (XDP) with FDF Toolkit .net.

  1. Select "Button"
  2. Select "Submit"
  3. Click "Button" Tab
  4. Provide URL to script
  5. Select XDP Data Package
  6. Uncheck Annotations
  7. Uncheck PDF
  8. Select UTF-8
LiveCycle Setup

LiveCycle Setup Part II

Here are the setting to use when saving LiveCycle Forms to in order to merge XDP data with LiveCycle forms using FDF Toolkit .net.

  1. Select Acrobat 6,7,8 "Static"
LiveCycle Setup: SaveAs - Static Only
 
Tags: , | Categories: Web Presence Posted by NicK on 8/17/2008 3:57 AM | Comments (0)

We recently ran into a situation where a client was unable to use the FDFToolkit.net 2.0 component on a remote server. It worked fine on the testing server.

The error was:

System.Security.SecurityException: That assembly does not allow partially trusted callers

I looked up the error, and found out how to allow the server to trust our component.

SOLUTION: 

Since we have the source to our component, as well as the iTextSharp component all we had to do is make some minor changes and recompile.

We opened our sources, and inserted the following line into the AssemblyInfo.vb files for both FDFToolkit.net and iTextSharp:

< Assembly: System.Security.AllowPartiallyTrustedCallers() >

And we made sure the component has the full version information hardcoded in the assemblies.

< Assembly: AssemblyVersion("2.0.0.0") >

Recompiled both components, and the error message dissapeared.

Here's a link to iTextSharp & Partially Trusted web hosts solution: 

http://www.jwc3.net/2008/07/itextsharp-will-not-run-in-partially.html

Tags: , | Categories: Web Presence Posted by NicK on 8/6/2008 2:26 PM | Comments (0)

I recently had a project, using ASP.net 2.0, and manually submitted the site to Yahoo!, MSN, Google. The whole domain placed well on Google, and MSN, but, it seemed we were lacking placement on Yahoo!'s search engine results.

We purchased a paid subscription to Yahoo! Submit express, $50 per domain per year, to diagnose the problem, but we were still lacking hits. I ran a search at Yahoo! for the whole site, it came up with the correct titles, but, the descriptions were not our META descriptions, they were just random text from the content of the pages. I looked at our META information from the HTML page, and the server side META tags were creating an extra parameter, "ID", since it was set to runat="server". I was doing this so I can control the TITLE, DESCRIPTION, and KEYWORDS from within the modules.

Anyway, I fixed the problem, by creating each META tag on the page itself, instead of loading it from the code behind.

The site is now ranking very well on Google, MSN, as well as Yahoo!

Useful links:

 

Tags: , | Categories: Web Presence Posted by NicK on 7/28/2008 3:07 AM | Comments (0)
Search Engine Web master tools
Other Web Master Tools

 

The most useful tools would be the Meta Anayzer, in conjunction with Google Tools. The Meta Analyzer can ultimately inform you if the web site content and meta information are not relevent. Google's web master tools can easily help determine help submission to Google.

Yahoo's paid submission is good, but I recommend only submitting the home page. Yahoo's paid submission crawls your url every two days, and it costs $50 per url / per year. Yahoo's tools allow you to see your web page's META information as Yahoo sees it. This is useful if your site isn't being crawled correctly. You can submit a maximum of only 5 urls per domain using Yahoo's paid submission.

Live's free submission tool, and Google's submission tool allow you to submit a site map, but Live's site map submission only allows you to submit a sitemap XML url in your home directory of your domain.

Beware, over use of keywords can lead to penalized rankings. Use keywords in normal sentences, and do not bloat your TITLE tag with multiple instances of one keyword. Use only one keyword instance in the TITLE. Overuse of keywords, whether in the body or META data, can cause search engines to lower your rankings. Also, make sure all your keywords are listed in the description, and body content of your web page.

Categories: PDF Programming Posted by NicK on 7/27/2008 12:40 PM | Comments (0)

Principles to Loading an Adobe Acrobat PDF Form with XML Data with FDF Toolkit .net with ASP.net

Rules: Make sure when posting FDF Data to a buffer, write "Response.Clear()" before you post any FDF Data to remove any HTML in your ASPX pages, and then write your "Response.ContentType=" line.

Imports FDFApp
Imports FDFApp.FDFApp_Class
Imports FDFApp.FDFDoc_Class

Public Class loadform
        Inherits System.Web.UI.Page
Private URLPath as String = ""
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        URLPath = Request.Url.AbsoluteUri.ToString & ""
URLPath = URLPath.SubString( 0, URLPath.LastIndexOf("/")+1 ) & ""
    Try
        Import_XML()
    Catch Ex as Exception
        Response.Write("Error: " & Ex.Message)
        Response.End
    End Try
End Sub

Public Sub Import_XML()        
     ' INITIALIZE THE COMPONENTS
     Dim FDFApp As New FDFApp.FDFApp_Class
     Dim FDFDoc As New FDFApp.FDFDoc_Class        
     ' IMPORT XML DATA
     FDFDoc = FDFApp.FDFOpenFromURL(URLPath & "report.xml", True, True)        
     ' SET THE MIME TYPE TO FDF
Response.Clear()
     Response.ContentType = FDFApp.MimeFDF        
     ' SET THE URL TO THE PDF FILE         
     FDFDoc.FDFSetFile(URLPath & "PDFs/sample_report.pdf")        
     ' WRITE CONTENTS TO BUFFER
     Response.BinaryWrite(FDFDoc.FDFSavetoBuf(FDFDoc.FDFType.FDF, False))
End Sub 
End Class 
Tags: | Categories: PDF Programming Posted by NicK on 7/27/2008 12:39 PM | Comments (0)
ASP.net 2.0

Principles of Sending Email with a Editable or Flattened PDF or FDF Attachment with ASP.net and the FDF Toolkit .net component.

Rules: Make sure when posting PDF Data to a buffer, do not post any HTML along with PDF Data. Remove any header information by declaring "Response.Clear()" before posting any PDF or PDF data MIME content.

Notes: Flattening the pdf form can be set with the true or false switch in the FDFDoc.PDFMergeFDF2Buf function in the FDF Toolkit .net component.

Imports FDFApp
Imports FDFApp.FDFApp_Class
Imports FDFApp.FDFDoc_Class
Imports FDFApp.Mail
Imports System.Net.Mail
Imports System.Net.Mail.SmtpClient

Partial Public Class sendmail_01

    Inherits System.Web.UI.Page
    Private URLPath As String = Request.Url.ToString
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim action As String = Request("act") & ""
        Select Case action.ToLower
	  Case "fdf"
	      Send_Email(1)
	  Case "pdflat"
	      Send_Email(2)
	  Case "pdfedit"
	      Send_Email(3)
	  Case Else
	      Send_Email(1)
        End Select
    End Sub
    Private Function Send_Email(Optional ByVal AttachmentType As Integer = 1, Optional ByVal Use_Remote_SMTP As Boolean = False) As Boolean
        Try
	  Dim FDFApp As New FDFApp.FDFApp_Class
	  Dim FDFDoc As New FDFApp.FDFDoc_Class
	  Dim FDFMail As New FDFApp.Mail.MailMessage
	  Dim FDFSMTP As New FDFApp.Mail.SMTPServer
	  Dim FDFEmail As New FDFApp.Mail
	  FDFMail.Add_Recipient("user@domain.com", "A. Recipient")
	  Dim strSubj As String = "", strBody As String = "", strFrom As String = "", strTo As String = ""
	  strSubj = "FDF Attachment"
	  strBody = "Dear User," & Chr(10) & Chr(10) & _
	    "See attachment for details." & Chr(10) & Chr(10) & _
	    "You may need Adobe Reader to view this file." & Chr(10) & _
	    "http://www.adobe.com/reader/" & Chr(10) & Chr(10) & _
	    "Regards," & Chr(10) & Chr(10) & "Webmaster@domain.com"
	  FDFMail.msgBody = strBody
	  FDFMail.msgSubject = strSubj
	  'FDFMail.mCc = "User2 (user2@domain.com), User3 (user3@domain.com)"
	  'FDFMail.mCc = "User4 (user4@domain.com),User5 (user5@domain.com)"
	  FDFMail.msgBodyFormatIsHTML = False
	  FDFMail.msgFromAddress = New Net.Mail.MailAddress("webmaster@domain.com", "Webmaster")
	  FDFSMTP.SMTPConnectionTimeOut = 100
	  Dim dr As DataRow
	  If Use_Remote_SMTP Then
	      FDFSMTP.SMTPPassword = "password"
	      FDFSMTP.SMTPUserName = "webmaster@domain.com"
	      FDFSMTP.SMTPServerName = "smtp.domain.com"
	      FDFSMTP.SMTPServerPort = 25
	  Else
	      FDFSMTP.SMTPServerName = "localhost"
	      FDFSMTP.SMTPServerPort = 25
	  End If
	  FDFDoc = FDFApp.FDFCreate
	  'FDFDoc.FDFSetValuesFromDataRow(CType(Session("drData"), DataRow))
	  FDFDoc.FDFSetValue("Field_01", "Field_Value_A")
	  FDFDoc.FDFSetValue("Field_02", "Field_Value_B")
	  FDFDoc.FDFSetFile(URLPath & "PDFs/filename.pdf")
	  Select Case AttachmentType
	      Case 1 ' FDF
		FDFDoc.FDFSetTargetFrame = "_self" 'Request("target") & ""
		If FDFSMTP.PDFSendEmail(FDFMail.msgMailMessage, FDFDoc.PDFData, "PDFAttachment.fdf", SMTPServer.FDFType.FDF, False) = True Then
		    Return True
		Else
		    Return False
		    Exit Function
		End If
	      Case 2 ' PDF Flattened
		FDFDoc.PDFData = FDFDoc.PDFMergeFDF2Buf(URLPath & "PDFs/filename.pdf", True)
		If FDFSMTP.PDFSendEmail(FDFMail.msgMailMessage, FDFDoc.PDFData, "PDFAttachment.pdf", SMTPServer.FDFType.PDF, True) = True Then
		    Return True
		Else
		    Return False
		    Exit Function
		End If
	      Case 3 ' PDF Editable
		FDFDoc.PDFData = FDFDoc.PDFMergeFDF2Buf(URLPath & "PDFs/filename.pdf", False)
		If FDFSMTP.PDFSendEmail(FDFMail.msgMailMessage, FDFDoc.PDFData, "PDFAttachment.[df", SMTPServer.FDFType.PDF, False) = True Then
		    Return True
		Else
		    Return False
		    Exit Function
		End If
	      Case Else
		Return False
	  End Select
	  Exit Function
        Catch ex As Exception
	  Return False
        End Try
    End Function

End Class