Tags: blog |
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
d479e8f6-ba62-4324-927d-f1f8b5632621|0|.0