Print Page | Close Window

Empty form field on a PDF

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=841
Printed Date: 10 May 24 at 10:44AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Empty form field on a PDF
Posted By: jabaltie
Subject: Empty form field on a PDF
Date Posted: 26 Nov 07 at 1:56PM
I have a PDF template , which is a PDF with empty form fields.

This PDF template was designed using Open Office Writer.

I suspect this PDF template has some problem, that is, there's a bug on Open Office Writer OR there's some problem with the FlattenFormField function.....


Please take a look at the VBScript below. It loops across the PDF template form fields and flattens them all.

Get the PDF template to use on this VBScript code from here :

http://www.DES.online.unimep.br/au/pub/ag284d.pdf

Follows the source code :

=====================
OPTION EXPLICIT

DIM OBJARGS
DIM OBJQPDF
DIM ARQPDF
DIM LNI
DIM LNT
DIM FORMFIELDNAME

SET OBJARGS=WScript.Arguments

ARQPDF=OBJARGS(0)

SET OBJQPDF=WSCRIPT.CREATEOBJECT("ISED.QUICKPDF")

IF  NOT OBJQPDF.UNLOCKKEY("yourkeyhere") = 1 THEN
    WSCRIPT.ECHO "COULD NOT UNLOCKKEY"
    WSCRIPT.QUIT(1)
END IF

IF  OBJQPDF.LOADFROMFILE(ARQPDF) = 0 THEN
    WSCRIPT.ECHO "COULD NOT LOAD TEMPLATE"
    WSCRIPT.QUIT(1)
END IF

LNT=OBJQPDF.FORMFIELDCOUNT()

FOR LNI=1 TO LNT
  FORMFIELDNAME=OBJQPDF.GETFORMFIELDTITLE(LNI)
  IF  NOT OBJQPDF.FLATTENFORMFIELD(LNI) = 1 THEN
      WSCRIPT.ECHO "ERROR WHILE FLATTENING THIS FORM FIELD '" + FORMFIELDNAME + "' ON " + ARQPDF,LNI
      WSCRIPT.QUIT(1)
  END IF
NEXT

================


Finally, questions are :

Is this PDF template (http://www.DES.online.unimep.br/au/pub/ag284d.pdf) wrong or, is there some problem on FlattenFormField function ?

Where does that empty form field comes from ? Cause it doesnt appear when I open the template using Acrobat Reader....

For those skilled with Adobe PROfessional, are there any tools on it that we can use to find out WHERE is the empty field on this PDF ?

Thanks in advance 4 your support !



Replies:
Posted By: chicks
Date Posted: 26 Nov 07 at 2:20PM
This is the classic changing reference issue. As you flatten the fields, the internal reference numbers of form fields changes. What was FF1 no longer exists, so what was FF2 is now FF1, etc.

Simple solution is to FlattenFormField(1), instead of LNI. Another is to flatten in reverse order, from LNT to 1 step -1

Try this:


Option Explicit

Dim ObjArgs
Dim ObjQpdf
Dim ArQpdf
Dim Lni
Dim Lnt
Dim FormFieldName

Set ObjArgs=Wscript.Arguments

ArQpdf=ObjArgs(0)

Set ObjQpdf=Wscript.CreateObject("ised.quickpdf")

If Not Objqpdf.UnlockKey("MY_KEY") = 1 Then
    Wscript.Echo "could Not Unlockkey"
    Wscript.Quit(1)
End If

If ObjQpdf.LoadFromFile(ArQpdf) = 0 Then
    Wscript.Echo "could Not Load Template"
    Wscript.Quit(1)
End If

Lnt=ObjQpdf.FormFieldCount()

WScript.Echo Lnt & " fields found"

For Lni=lnt To 1 Step -1
FormFieldName=ObjQpdf.GetFormFieldTitle(Lni)
WScript.Echo Lni & Chr(9) & FormFieldName
If Not ObjQpdf.FlattenFormField(lni) = 1 Then
      Wscript.Echo "error While Flattening This Form Field '" & FormFieldName & "' On " & Arqpdf,lni
      Wscript.Quit(1)
End If
Next



Posted By: jabaltie
Date Posted: 27 Nov 07 at 5:15AM
Thanks for your usual help Chicks.

I'm aware of the reference problem and on the REAL , PROduction server side code, it's done in reverse order.

However, back to this topic here, I'm curious about this :

Try to make the loop this way :

FOR LNI=1 TO LNT
  FORMFIELDNAME=OBJQPDF.GETFORMFIELDTITLE(LNI)
  WSCRIPT.ECHO "FIELD #",LNI,": '" + FORMFIELDNAME + "'"
  IF  NOT OBJQPDF.FLATTENFORMFIELD(1) = 1 THEN
      MSGBOX "ERROR WHILE FLATTENING THIS FORM FIELD '" + FORMFIELDNAME + "' ON " + ARQPDF
      WSCRIPT.QUIT(1)
  END IF
NEXT

It looks like after a while, all of the form fields will have a blank name.

Is it supposed to be like that ?

I'm doing it all cause I'm "lost" with a problem posted on another topic, where a damaged PDF is generated, that is, a PDF with wrong field contents....

Thanks again !


Posted By: chicks
Date Posted: 27 Nov 07 at 10:59AM
This is exactly the same issue. You are trying to get the name of fields that don't exist. After half the fields have been flattened, LNI will be greater than the number of remaining fields, so GetFormFieldTitle(LNI) will return null.

Try ObjQpdf.GetFormFieldTitle(1), which should work fine.


Posted By: jabaltie
Date Posted: 29 Nov 07 at 5:32AM
One more question 4 you Chicks :

You said you never had a problem with forms processing.

How do you design your templates ? Do you draw them in Word and convert them using Adobe PRO or do you use something else to design these templates ?


Posted By: chicks
Date Posted: 29 Nov 07 at 11:36AM
I've used http://www.acrosoftware.com/products/formmax/default.asp - FormMax for years with good results. Also use NitroPDF if needing to add form fields to an existing PDF.

BTW, AcroSoftware also has a form filling ActiveX component, but I haven't tried it.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk