NK-Inc.com
PDF Programming Tutorials

PDF Programming Tutorials

Programming Dynamic PDF forms using FDFToolkit.net

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