NK-Inc.com
PDF Programming Tutorials

PDF Programming Tutorials

Programming Dynamic PDF forms using FDFToolkit.net

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

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

Basic Principles of programming. How to send an email from a PDF form submission. Send either Flattened PDF, Editable PDF, or FDF Data to any recipient using 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 type.

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

Imports FDFApp
Imports FDFApp.FDFApp_Class
Imports FDFApp.FDFDoc_Class
Imports FDFApp.Mail
Imports System.Web.Mail
Imports System.Web.Mail.MailFormat
Imports System.Web.Mail.SmtpMail

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.mBody = strBody
            FDFMail.mSubject = strSubj
            FDFMail.mBodyFormat = Mail.MailFormat.Text
            FDFMail.mFrom = "Webmaster (webmaster@domain.com)"
            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.SMTPUseAuthentication = FDFSMTP.SMTPAuthenticate.cdoBasic
                FDFSMTP.SMTPServerPort = 25
            Else
                FDFSMTP.SMTPServerName = "localhost"
                FDFSMTP.SMTPServerPort = 25
                FDFSMTP.SMTPUseAuthentication = FDFSMTP.SMTPAuthenticate.cdoNone
            End If
            FDFDoc = FDFApp.FDFCreate
            'FDFDoc.FDFSetValuesFromDataRow(CType(Session("drData"), DataRow))            FDFDoc = FDFApp.FDFOpenFromStream(Request.InputStream)            'FDFDoc.FDFSetFile(URLPath & "PDFs/filename.pdf")
            Select Case AttachmentType
                Case 1 ' FDF
                    FDFDoc.FDFSetTargetFrame = "_self" 'Request("target") & ""
                    If FDFSMTP.FDFSendEmail(FDFMail, FDFDoc, Server.MapPath("Data/"), True, FDFSMTP.FDFType.FDF) = True Then
                        FDFDoc.FDFSetStatus("Thank you, your email was sent.") 
                    Else
                        FDFDoc.FDFSetStatus("Sorry, your email not was sent.") 
                    End If
                Case 2 ' PDF Flattened
                    FDFDoc.PDFData = FDFDoc.PDFMergeFDF2Buf(URLPath & "PDFs/filename.pdf", True)
                    If FDFSMTP.PDFSendEmail(FDFMail, FDFDoc.PDFData, Server.MapPath("Data/"), True, FDFSMTP.FDFType.PDF) = True Then
                        FDFDoc.FDFSetStatus("Thank you, your email was sent.")
                     Else
                        FDFDoc.FDFSetStatus("Sorry, your email not was sent.") 
                    End If
                Case 3 ' PDF Editable
                    FDFDoc.PDFData = FDFDoc.PDFMergeFDF2Buf(URLPath & "PDFs/filename.pdf", False)
                    If FDFSMTP.PDFSendEmail(FDFMail, FDFDoc.PDFData, Server.MapPath("Data/"), True, FDFSMTP.FDFType.PDF) = True Then
                        FDFDoc.FDFSetStatus("Thank you, your email was sent.")
                     Else
                        FDFDoc.FDFSetStatus("Sorry, your email not was sent.") 
                    End If
                Case Else
                        FDFDoc.FDFSetStatus("Sorry, your email not was sent.")
             End Select
            Exit Function
        Catch ex As Exception
                        FDFDoc.FDFSetStatus("Sorry, your email not was sent.") 
        End Try
    Response.Clear()
        Response.ContentType = FDFApp.MIMEFDF
        Response.BinaryWrite(FDFDoc.FDFSavetoBuf)

End Function 

 

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

Basic principles of populating or updating a database with Adobe Acrobat PDF Form data using VB.net, ASP.net, and the FDF Toolkit .net component.

Scenerio: User fills out a PDF form online, and clicks submit. The form is sent to a server side script, see code, and the script parses the field information and stores it into a database.

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.

 

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.ToString
    Try
        Update_Data(Request.QueryString("id") & "")
    Catch Ex as Exception
        Response.Write("Error: " & Ex.Message)
        Response.End
    End Try
End Sub
Public Function Update_Data(ByVal form_id As Integer) As Boolean
Try
    Dim FDFApp As New FDFApp.FDFApp_Class
    Dim FDFDoc As New FDFApp.FDFDoc_Class
    'FDFDoc = FDFApp.FDFOpenFromBuf(Request.BinaryRead(Request.TotalBytes), True, True)
    FDFDoc = FDFApp.FDFOpenFromStream(Request.InputStream, True, True)
    'Response.ContentType = FDFApp.MimeFDF
    Dim dr As DataRow, ds As New DataSet
    Dim da As New OleDbDataAdapter, sSQL(2) As String
    sSQL(0) = "SELECT * FROM TableName WHERE "
    sSQL(1) = "ID = " & form_id & ";"
    sSQL(2) = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " & Server.MapPath("Data/Database_Name.mdb") & ";"
    da = New OleDbDataAdapter(sSQL(0) & sSQL(1), sSQL(2))
    Dim cmd As New OleDbCommandBuilder(da)
    da.Fill(ds, "TableName")
    Try
        If ds.Tables("TableName").Rows.Count = 1 Then
            dr = ds.Tables("TableName").Rows(0)
            dr = FDFDoc.FDFSetDataRowFromValues(dr)
            da.Update(ds, "TableName")
            Response.ContentType = FDFApp.MimeFDF
            FDFDoc.FDFSetStatus("Success! Updated Database", True)
            Response.BinaryWrite(FDFDoc.FDFSavetoBuf(FDFApp.FDFType.FDF, False))
            Return True
        Else
            FDFDoc.FDFSetStatus("ERROR: This form did not update a record!", True)
            Response.ContentType = FDFApp.MimeFDF
            Response.BinaryWrite(FDFDoc.FDFSavetoBuf(FDFApp.FDFType.FDF, True))
            Return False
            Exit Function
        End If
    Catch ex As Exception
        FDFDoc.FDFSetStatus("ERROR: This form did not update a record!", True)
        Response.ContentType = FDFApp.MimeFDF
        Response.BinaryWrite(FDFDoc.FDFSavetoBuf(FDFApp.FDFType.FDF, True))
        Return False
        Exit Function
    End Try
Catch ex As Exception
    FDFDoc.FDFSetStatus("ERROR: This form did not update a record!", True)
        Response.Clear()
        Response.ContentType = FDFApp.MimeFDF
    Response.BinaryWrite(FDFDoc.FDFSavetoBuf(FDFApp.FDFType.FDF, True))
    Return False
    Exit Function
End Try 
Tags: | Posted by NicK on 7/27/2008 12:37 PM | Comments (0)

BASIC PDF PROGRAMMING PRINCIPLES - MICROSOFT .NET VERSION

Principles of Merging Adobe Acrobat PDF Form and data, and forcing the web browser to save the file with VB.net

Rules: Make sure when posting PDF Data to a buffer, do not post any HTML along with PDF Data. Remove any header information except for the declaration of the code behind or remove everything below the first line of the .ASPX web page. Also, PDF MIME has to be setup on the web server.

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

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.ToString
    Try
        DownloadFile(Export_PDF_Flattened)
    Catch Ex as Exception
        Response.Write("Error: " & Ex.Message)
        Response.End
    End Try
End Sub

Sub DownloadFile(ByVal xFile As Byte())
    Try
          Dim FileName As String = "PDFFile.pdf"
            If xFile.Length > 0 Then
                Response.Clear()
                Response.ContentType = "application/pdf"
                'Response.ContentType = "application/octet-stream";
                Response.AppendHeader("Content-Disposition", "attachment; filename=""" & FileName & """")
                Response.BinaryWrite(xFile)
                Response.Flush()
            End If
        Catch ex As Exception
                Response.Write("Error: " & Ex.Message)
                Response.End
        End Try
End Sub

Public Function Export_PDF_Flattened() As Byte()
        Try
            Dim FDFApp As New FDFApp.FDFApp_Class
            Dim FDFDoc As New FDFApp.FDFDoc_Class
            FDFDoc = FDFApp.FDFCreate
            FDFDoc = Load_FDF(FDFDoc)
            FDFDoc.PDFData = FDFDoc.PDFMergeFDF2Buf(FDFDoc, True)
            Return FDFDoc.PDFData
        Catch ex As Exception
                Response.Write("Error: " & Ex.Message)
                Response.End
        End Try
End Function

Public Function Load_FDF(FDFDoc As FDFApp.FDFDoc_Class) As FDFApp.FDFDoc_Class
    ' INITIALIZE THE COMPONENTS
    FDFDoc = FDFApp.FDFCreate
    Response.ContentType = FDFApp.MimePDF

    ' SET TEXT, CHECKBOX, AND OPTION FIELD VALUES
    FDFDoc.FDFSetValue("txtForm_Field1","Field_Value1")
    FDFDoc.FDFSetValue("chkForm_Field2","Field_Value2")
    FDFDoc.FDFSetValue("optForm_Field3","Field_Value3")
    ' SET LIST FIELD NAME ,DISPLAY NAME, AND VALUES
    FDFDoc.FDFSetOpt("lstForm_Field",New String() _{"lst_Value01","lst_Value02","lst_Value03","lst_Value04"},New String() _{"DisplayName_01","DisplayName_02","DisplayName_03","DisplayName_04"})
    'FDFDoc.FDFSetValues("lstForm_Field",New String(){"lst_Value02","lst_Value03")
    'FDFDoc.FDFSetValue("lstForm_Field","lst_Value02")
    
    ' SET PDF LOCATION
    FDFDoc.FDFSetFile(URLPath & "PDFs/sample.pdf")

    Return FDFDoc
End Function

End Class 
Tags: | Categories: PDF Programming Posted by NicK on 7/27/2008 12:37 PM | Comments (0)

Principles to Loading a PDF with Data with ASP.net

Rules: Make sure when posting FDF Data to a buffer, do not post any HTML along with FDF Data, using VB.net, ASP.net, and the FDF Toolkit .net component. Remove any header information by declaring "Response.Clear()" before posting any PDF or PDF data MIME content.

 

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.ToString
    Try
        Load_FDF()
    Catch Ex as Exception
        Response.Write("Error: " & Ex.Message)
        Response.End
    End Try
End Sub

Public Function Load_FDF()
    ' DECLARE THE COMPONENTS
    Dim FDFApp As New FDFApp.FDFApp_Class
    Dim FDFDoc As New FDFApp.FDFDoc_Class
    ' INITIALIZE THE COMPONENTS
    FDFDoc = FDFApp.FDFCreate
Response.Clear()
Response.ContentType = FDFApp.MimeFDF

    ' SET TEXT FIELD VALUES
    FDFDoc.FDFSetValue("txtForm_Field1","Field_Value")
    FDFDoc.FDFSetValue("txtForm_Field2","Field_Value")
    FDFDoc.FDFSetValue("txtForm_Field3","Field_Value")

    ' SET OPTION OR LIST FIELD NAMES AND VALUES
    FDFDoc.FDFSetOpt("lstForm_Field",New String() _{"lst_Value01","lst_Value02","lst_Value03","lst_Value04"},New String() _{"DisplayName_01","DisplayName_02","DisplayName_03","DisplayName_04"})
    
    FDFDoc.FDFSetValues("lstForm_Field",New String(){"lst_Value02","lst_Value03")
    'FDFDoc.FDFSetValue("lst_Form_Field","lst_Value02")
    
    ' SET PDF LOCATION
    FDFDoc.FDFSetFile(URLPath & "PDFs/sample.pdf")

    ' WRITE THE FDF TO THE BUFFER
    Response.BinaryWrite(FDFDoc.FDFSavetoBuf(FDFApp.FDFType.FDF, False))

    ' BROWSER READS THE FDF DATA AND ADOBE PLUG-IN MERGES PDF WITH FDF DATA
    '
End Function

End Class 
Tags: | Categories: PDF Programming Posted by NicK on 7/27/2008 12:37 PM | Comments (0)

Principles of Merging PDF and Data with VB.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 using the FDF Toolkit .net component.

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.ToString
    Try
        Load_FDF()
    Catch Ex as Exception
        Response.Write("Error: " & Ex.Message)
        Response.End
    End Try
End Sub

Public Function Load_FDF()
    ' DECLARE THE COMPONENTS
    Dim FDFApp As New FDFApp.FDFApp_Class
    Dim FDFDoc As New FDFApp.FDFDoc_Class
    ' INITIALIZE THE COMPONENTS
    FDFDoc = FDFApp.FDFCreate
        Response.Clear()
        Response.ContentType = FDFApp.MimePDF

    ' SET TEXT FIELD VALUES
    FDFDoc.FDFSetValue("txtForm_Field1","Field_Value")
    FDFDoc.FDFSetValue("txtForm_Field2","Field_Value")
    FDFDoc.FDFSetValue("txtForm_Field3","Field_Value")

    ' SET OPTION OR LIST FIELD NAMES AND VALUES
    FDFDoc.FDFSetOpt("optForm_Field",New String() _{"Opt_Value01","Opt_Value02","Opt_Value03","Opt_Value04"},New String() _{"DisplayName_01","DisplayName_02","DisplayName_03","DisplayName_04"})
    
    FDFDoc.FDFSetValues("optForm_Field",New String(){"Opt_Value02","Opt_Value03")
    'FDFDoc.FDFSetValue("optForm_Field","Opt_Value02")
    
    ' SET PDF LOCATION
    FDFDoc.FDFSetFile(URLPath & "PDFs/sample.pdf")
    ' MERGE PDF WITH FDF DATA AND FLATTEN
    FDFDoc.PDFData = FDFDoc.PDFMergeFDF2Buf(FDFDoc, True)     ' WRITE THE FDF TO THE BUFFER
    Response.BinaryWrite(FDFDoc.PDFData)

    ' BROWSER READS THE PDF DOCUMENT AND ADOBE PLUG-IN OPENS
    '
End Function

End Class 
Tags: | Categories: PDF Programming Posted by NicK on 7/27/2008 12:35 PM | Comments (0)

BASIC PDF PROGRAMMING PRINCIPLES - MICROSOFT .NET VERSION

Principles of Merging Adobe Acrobat PDF Form and data, and forcing the web browser to save the file with VB.net

Rules: Make sure when posting PDF Data to a buffer, do not post any HTML along with PDF Data. Remove any header information except for the declaration of the code behind or remove everything below the first line of the .ASPX web page. Also, PDF MIME has to be setup on the web server.

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

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.ToString
    Try
        DownloadFile(Export_PDF_Flattened)
    Catch Ex as Exception
        Response.Write("Error: " & Ex.Message)
        Response.End
    End Try
End Sub

Sub DownloadFile(ByVal xFile As Byte())
    Try
          Dim FileName As String = "PDFFile.pdf"
            If xFile.Length > 0 Then
                Response.Clear()
                Response.ContentType = "application/pdf"
                'Response.ContentType = "application/octet-stream";
                Response.AppendHeader("Content-Disposition", "attachment; filename=""" & FileName & """")
                Response.BinaryWrite(xFile)
                Response.Flush()
            End If
        Catch ex As Exception
                Response.Write("Error: " & Ex.Message)
                Response.End
        End Try
End Sub

Public Function Export_PDF_Flattened() As Byte()
        Try
            Dim FDFApp As New FDFApp.FDFApp_Class
            Dim FDFDoc As New FDFApp.FDFDoc_Class
            FDFDoc = FDFApp.FDFCreate
            FDFDoc = Load_FDF(FDFDoc)
            FDFDoc.PDFData = FDFDoc.PDFMergeFDF2Buf(FDFDoc, True)
            Return FDFDoc.PDFData
        Catch ex As Exception
                Response.Write("Error: " & Ex.Message)
                Response.End
        End Try
End Function

Public Function Load_FDF(FDFDoc As FDFApp.FDFDoc_Class) As FDFApp.FDFDoc_Class
    ' INITIALIZE THE COMPONENTS
    FDFDoc = FDFApp.FDFCreate
        Response.Clear()
        Response.ContentType = FDFApp.MimePDF

    ' SET TEXT, CHECKBOX, AND OPTION FIELD VALUES
    FDFDoc.FDFSetValue("txtForm_Field1","Field_Value1")
    FDFDoc.FDFSetValue("chkForm_Field2","Field_Value2")
    FDFDoc.FDFSetValue("optForm_Field3","Field_Value3")
    ' SET LIST FIELD NAME ,DISPLAY NAME, AND VALUES
    FDFDoc.FDFSetOpt("lstForm_Field",New String() _{"lst_Value01","lst_Value02","lst_Value03","lst_Value04"},New String() _{"DisplayName_01","DisplayName_02","DisplayName_03","DisplayName_04"})
    'FDFDoc.FDFSetValues("lstForm_Field",New String(){"lst_Value02","lst_Value03")
    'FDFDoc.FDFSetValue("lstForm_Field","lst_Value02")
    
    ' SET PDF LOCATION
    FDFDoc.FDFSetFile(URLPath & "PDFs/sample.pdf")

    Return FDFDoc
End Function

End Class