?
Solved

I have a form that was made to populate its values from the db into a pdf form, i want to populate a checkbox value from a db too but i cann't .why?

Posted on 2004-11-20
30
Medium Priority
?
293 Views
Last Modified: 2008-10-17
I have a form that was made to populate its values from the db into a pdf form.
Well everything was fine untill i tried to populate a checkbox value from the db
 into the pdf form.
i don't know what is wrong with me?
 
The name of checkbox is eighta.

any way here is the form that i am trying to populate the checkbox value through.
all the fields here are populated fine but when i added the check box i got an error.

would someone check it and let me know what i am doing wrong with the checkbox.

here is what i have done so far in the form :

<%@ LANGUAGE = VBScript%>
<%

Dim     txtName_of_Firm          '--The name of the text field  "txtName_of_Firm"
Dim txtTelephone               '--The name of the text field  "txtTelephone "
Dim eighta                         '--The name of the Check box field  "eighta"Dim objConn, objRS, strSQL, strConnectionString
         set objConn = server.createobject("adodb.connection")
         objConn.open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("DB1.mdb")

Set objRS = Server.CreateObject("ADODB.Recordset")

  dim M_USERNAME
  M_USERNAME = session("user")
  strSQL = "SELECT * FROM pdf1 where M_USERNAME = '" &M_USERNAME& "'"
  objRS.open strSQL,objConn,3,3
if len(request.form("eighta")) >0 then
                    eighta = true
             else
                       eighta = false
              end if

If Not objRS.EOF Then
     objRS.MoveFirst
     txtName_of_Firm = objRS("txtName_of_Firm")
     txtTelephone  = objRS("txtTelephone")
       
   End If


'-- CLOSE & CLEAN-UP YOUR RECORDSETS, COMMAND OBJECTS, & CONNECTION OBJECT HERE --
objRS.Close

Set objRS = Nothing
'Set objComm = Nothing
Set objConn = Nothing


'-- END DATA COLLECTION, BEGIN FDF FORMATION --
'*****************************************************************************************
' All FDF/PDF Form Fields, no matter their type, are accessed by the Title(Name) (/T)
' followed by the Value (/V) keys. For List Boxes & Combo Boxes, you only need to refer to
' the Option fields when you are populating the boxes with new data with the /Opt key.
' Form field Titles and Values are case sensitive. If you misspell or use incorrect
' casing the form field will be ignored, you will not receive an error. The File (/F)
' key links this ASP (FDF) with a specific PDF file. You must specify a complete absolute
' URL. Unfortunately, relative URLs do not work as intended.
' After the Title (/T), Value (/V), Option (/Opt), and File (/F) keys, you enter the
' respective 'value' within parenthesis. e.g. /T (txtFirstName). You may enter this
' values as literals or as an abbreviated Response.Write.
' e.g. /T (<% = strTitle (closing asp delimiter here)). The following ASP will provide
' examples of this.
%>
<% Response.ContentType = "application/vnd.fdf" %>
%FDF-1.2
1 0 obj
<<
/FDF
<< 
/Fields
[
<< /T (txtName_of_Firm) /V (<% = txtName_of_Firm %>) >> 
<< /T (txtTelephone) /V (<% = txtTelephone %>) >>
<<
/T (8a)
/V (<%    
          if not objRS.eof then
               if objRS("eighta") then
                    response.write(" checked ")
             
                  end if
               
          end if
               %>)
>>
]
/F (http://localhost/pdf1/FormTest.pdf)
>> 
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%EOF
0
Comment
Question by:Melfeky
  • 17
  • 13
30 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12635459
For a checked field, you need this in your FDF file:

<< /T(check1)/V/Yes >>

For an unchecked check box, you would use this:

<< /T(check1)/V/Off >>
0
 

Author Comment

by:Melfeky
ID: 12635499
well this is right , but what i am trying to do is to get the value of the checkbox from the db, so if the user have checked it the pdf form will be checked too and if it is not checked ,it is not checked in the odf too.
If i do what u say ,i will be forcing the form to be either checked or not , i don't wnt to do that i want to get the value from the db like i have done with the other text fields.
I hope that u got the idea.
Thanks.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12635536
You have to dynamically create this line, and use either "/Yes" or "/Off" depending on the setting in your database. I'm not familiar with ASP, so you have to fill in the blanks yourself.
0
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 

Author Comment

by:Melfeky
ID: 12635648
do u have ny example or something on the web that i might look at, as from what i can see no one here knows as much as u in this thing.
Thanks.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12635673
Do you have the full version of Acrobat? If so, you can create these samples yourself: Just create a form with one checkbox. Select "Advanced>Forms>Export Forms Data" once for the checkbox unchecked, and once with the checkbox checked.

if you don't have Acrobat, I can provide a few sample files.
0
 

Author Comment

by:Melfeky
ID: 12635695
i have the full version of acrobat, all i need u to provide is any ASP exmple that populates the data from the db into the pdf form.
Iknow that u are not so familiar with ASP  but i guess u might have seen any example here or there about this.
Thanks
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12635807
Again, I've never written any ASP program, nor do I program in VB. You need to resolve this part yourself. I can help you with the FDF part. I see you are pretty active in the ASP TA, I'm pretty sure that you can find people who can you with the ASP part of the problem over there.

You said that you are getting an error message for the checkbox. What type of error message? Are the two text fields getting assigned correctly? Is the checkbox name in the PDF file really "8a"? If not then this part of your program is not correct:
/T (8a)
/V (<%    
          if not objRS.eof then
               if objRS("eighta") then
                    response.write(" checked ")
             
                  end if
               
          end if
               %>)
>>
]


Here you are assigning a value of either an emtpy string, or " checked " to the field named "8a". As I told you, the valid values for a checkbox are /Off and /Yes. This means that you probably (again, I don't have any experience with this) need something like this:
/V (<%  
          if not objRS.eof then
               if objRS("eighta") then
                    response.write("/Yes")
                  else
                    response.write("/Off")
                  end if
          else
             resonse.write("/Off")
          end if
 %>)




0
 

Author Comment

by:Melfeky
ID: 12635943
Now i am not getting any error message , when run the ASP form the pdf form is populated with the text fields only , but the checkbox is not checked though it is checked in the db.
I have already changed the "8a" to "eighta" to match the value stored in the db and the pdf form.
But i got this result when i stoped the asp from openeing the pdf:
%FDF-1.2 1 0 obj << /FDF << /Fields [ << /T (txtName_of_Firm) /V (dodo) >> << /T (txtTelephone) /V (222) >> << /T (eighta) /V ( checked ) >> ] /F (http://localhost/pdf1/FormTest.pdf) >> >> endobj trailer << /Root 1 0 R >> %%EOF
 
What do u think of this fdf text, can u see something wrong here?
0
 

Author Comment

by:Melfeky
ID: 12635944
I have tried to use the Yes or off , but still the same result the checkbox is empty.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12636067
You need to use /Yes and /Off. What does the FDF look like with these changes?
0
 

Author Comment

by:Melfeky
ID: 12636094
User: dodo - eighta=True %FDF-1.2 1 0 obj << /FDF << /Fields [ << /T (txtName_of_Firm) /V (dodo) >> << /T (txtTelephone) /V (222) >> << /T(check1)/V/Yes >> ] /F (http://localhost/pdf1/FormTest.pdf) >> >> endobj trailer << /Root 1 0 R >> %%EOF
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12636198
If I'm not mistaken, the form field name is "eighta" and not "check1" (this was what I used in my example). Where does the "User: dodo - eighta=True" part come from? This should not be in the FDF.
0
 

Author Comment

by:Melfeky
ID: 12636246
when i tried to use this:
(<%  
          if not objRS.eof then
               if objRS("eighta") then
                    response.write("/Yes")
                  else
                    response.write("/Off")
                  end if
          else
             resonse.write("/Off")
          end if
 %>

i got an error that an object is missing so instead i used this:
<<
/T (eighta)
/V (<%    

if eighta = true then
    response.write("/Yes")
else
     response.write("/Off")
end if
%>)
>>


and the fdf tht i got is :
%FDF-1.2 1 0 obj << /FDF << /Fields [ << /T (txtName_of_Firm) /V (dodo) >> << /T (txtTelephone) /V (222) >> << /T (eighta) /V (/Yes) >> ] /F (http://localhost/pdf1/FormTest.pdf) >> >> endobj trailer << /Root 1 0 R >> %%EOF

so neglect my lst post this is the right one, but the pdf form still opened but the checkbox is not checked.
0
 

Author Comment

by:Melfeky
ID: 12636666
Well everything works fine now,  thank you.
I would like to upload the asp form + the pdf form on the web at www.1asphost.com
should i need to have installed on that server or it don't need anything?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12638157
As far as the FDF generation goes, you don't need anything (besides a web server that supports ASP), but I don't know if you need anything for the database part. Just give it a try.

Do you know what you changed to make it work?
0
 

Author Comment

by:Melfeky
ID: 12638442
When i tried to open this form on the internet i an this error message from what i can see it cannot find or read the FDF file or code.
Here is the message:
"The file that you are attempting to open contains comments or form data that are
supposed to be placed on sbaforms.pdf.This document cannot be found .It might been have move or deleted.
Would you like to browse to attempt to locate this document?"


I guess that this means that i have to install the FDF dlls on the webserver, and if so how would i do that as i am currently hosting it on a third party server"www.1asphost.com"?
0
 

Author Comment

by:Melfeky
ID: 12638457
If you want the code that made my form work here you go:

<% if eighta=True then
   %><< /T (eighta) /V (Yes) >> 
<%else%>
    << /T (eighta) /V (Off) >> 
<%end if
%>
0
 

Author Comment

by:Melfeky
ID: 12638876
would u test this url with me,
http://ccc.1asphost.com/kotty1234/cert/formpdf.asp?M_USERNAME=dodo

as this is the link of the asp form that will open the pdf form , when i try to open it the page is too slow .
would u open it and let me know if the pdf form is opened with values in the fields only in the first page.
thanks
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 2000 total points
ID: 12640172
The value needs to be either "/Off" or "/Yes", and not "(Off)" or "(Yes)". The "(...)" syntax defines a string in PDF (and PostScript). The values Off and Yes are _NOT_ strings, they are names, and therefore need the leading slash.

When I access the URL you've given in your last comment, the PDF file does load, so you are using the correct path. You don't need the FDF Toolkit for this - you are not using it. I downloaded both the FDF file and the PDF file to my local system. I then opened the PDF file and modified the FDF file (to use /Off and /Yes) and then used "Advanced>Forms>Import Forms Data" in Acrobat. This shows that the /Off and /Yes syntax does work. I see how the checkboxes can be checked and unchecked with the modified file.

You need to use this:

<% if eighta=True then
   %><< /T (eighta) /V /Yes >> 
<%else%>
    << /T (eighta) /V /Off >> 
<%end if
%>
0
 

Author Comment

by:Melfeky
ID: 12640199
well thanks i will change this to /Yes and /Off, but it really worked without them.
So when u opened the pdf file it opened not slow and with alll the data saved in the db?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12640711
The file loads. It takes a few seconds, but I guess this is OK. The first time (when Acrobat is not yet running), it takes longer because Acrobat has to be started.
The FDF file only contains empty strings, so no, the data is not in the PDF file.
0
 

Author Comment

by:Melfeky
ID: 12641135
Is there any setting in the adobe acrobat that i can set to avoid the user from editing the pdf form when it is opened, to be read only?The user should not be able to edit any of the information in the PDF form when it opens.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12641177
You can apply document security settings and only allow the "Filling of Form Fields". This way, the contents of your PDF file are protected, and the only operation allowed would be to fill in the form fields. You may also want to allow a few more options (like e.g. printing of the document).
0
 

Author Comment

by:Melfeky
ID: 12643654
I don't want the user to change the values entered in the fields in the pdf form, can this be done?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12643742
If that's the case, you should merge the FDF with the PDF on the server. I already suggested two programs that can do this for you in your other open Acrobat TA question (http://www.experts-exchange.com/Web/Graphics/Adobe_Acrobat/Q_21188422.html) - which BTW you should close before it gets processed by a cleanup volunteer.

The method you are using right now was designed for interactive forms, not for presenting static information. You are better off when you merge the files on the server and only provide a non-interactive PDF to your users.

If you are having trouble with how to call an external program from within your ASP program, look here: http://forums.aspfree.com/t34234/s.html
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12644126
You can also use one of the PDF libraries or toolkits to program your solution in ASP code. One (free) option is iText.NET: http://www.ujihara.jp/iTextdotNET/en/
It's based on the same library that is also used in pdftk (see link in the other tread).
0
 

Author Comment

by:Melfeky
ID: 12668282
Hello khkremer,
you don't get it , i just wnted the fields in the pdf form to be read only so when the user opens this pdf form he won't be able to change the values in the field.
I did this by just changing the properties of the field ,there is an option to make it Read only.
0
 

Author Comment

by:Melfeky
ID: 12668291
Thanks for your help.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12668337
Yes, but everybody with the full version of Acrobat can change the read-only flag back. In this case it's preferable to merge the documents on the server and give your customers access to a non-interactive PDF file.
0
 

Author Comment

by:Melfeky
ID: 12668887
ok now i got it, thanks.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe INTRODUCTION This Article is a follow-up to the Article entitled How To Rename-Move a Batch of PDF Files Based o…
PDF files have been in the limelight due to its unmatched features.  Personal documents, emails, business reports and eBooks are all converted into PDF files owing to peerless features provided by it. Adding watermark to a PDF file is a method to se…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question