Print Page | Close Window

After Merging, form fields are lost

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: General Discussion
Forum Description: Discussion board for Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=238
Printed Date: 17 May 24 at 7:44AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: After Merging, form fields are lost
Posted By: jabaltie
Subject: After Merging, form fields are lost
Date Posted: 05 Jan 06 at 8:20AM
I'm trying to merge several PDF files with empty form fields (templates) into a single one.

It happens that after the merging process, the form fields are lost. Only the form fields of the firstly added file are left.

My guess is this is a bug on QuickPDF itself.

I inserted below a VBScript that shows the problem.

What do I need after all ?

I need to add several templates, that is PDFs with form fields, each one corresponding to a page. Then I need to substitute each field content with data. Of course, I need to substitute ALL of the fields, from all the pages. I can do this substitution process either doing it page per page, that is replacing the fields while I add the pages, or at once, at the end of the merging process. But I do need to replace ALL of the fields.

Finally, here's the script :

---------------------------------------------------

OPTION EXPLICIT

DIM objPDF1,objPDF2,objPDF3,lni,mykey

mykey="mykey"

Set objPDF1 = WScript.CreateObject("ISED.QUICKPDF")

WScript.Echo objPDF1.LibraryVersion

WScript.Echo "UnlockKey     ",objPDF1.unlockkey(mykey)

WScript.Echo "Load File   A ",objPDF1.LoadFromFile("FILEA.PDF")
'You may get a copy of this template from here : 'http://www.DES.online.unimep.br/au/FILEA.PDF

for lni=1 to objPDF1.FormFieldCount
    WScript.Echo "Field #",lni," from A ",objPDF1.GetFormFieldTitle(lni)
next

WScript.Echo "Load File   B ",objPDF1.LoadFromFile("FILEB.PDF")
'You may get a copy of this template from here : 'http://www.DES.online.unimep.br/au/FILEB.PDF

for lni=1 to objPDF1.FormFieldCount
    WScript.Echo "Field #",lni," from B ",objPDF1.GetFormFieldTitle(lni)
next

WScript.Echo "***SO FAR SO GOOD ! FILES ARE LOADED OK AND FIELDS DISPLAYED AS EXPECTED"
WScript.Echo "------------------------------------------------------------------------"

' LET THE PROBLEMS BEGIN NOW BY MERGING BOTH FILES...

Set objPDF2 = WScript.CreateObject("ISED.QUICKPDF")


WScript.Echo "UnlockKey ",objPDF2.unlockkey(mykey)

WScript.Echo "Add File A",objPDF2.AddToFileList("mfl","FILEA.PDF")
WScript.Echo "Add File B",objPDF2.AddToFileList("mfl","FILEB.PDF")
WScript.Echo "Merge to C",objPDF2.MergeFileList("mfl","FILEC.PDF")
WScript.Echo "Clear     ",objPDF2.ClearFileList("mfl")

WScript.Echo "***MERGING PROCESS HAS BEEN COMPLETED OK..."
WScript.Echo "------------------------------------------------------------------------"

Set objPDF3 = WScript.CreateObject("ISED.QUICKPDF")

WScript.Echo "UnlockKey     ",objPDF3.unlockkey(mykey)

WScript.Echo "Load File   C ",objPDF3.LoadFromFile("FILEC.PDF")
WScript.Echo "Field Count C ",objPDF3.FormFieldCount

for lni=1 to objPDF3.FormFieldCount
    WScript.Echo "Field #",lni," from A ",objPDF3.GetFormFieldTitle(lni)
next

WScript.Echo "***OPS - WHERE ARE THE FORM FIELDS FROM FILE B ?"


When I execute the script above on my machine, it says :


5.11
UnlockKey      1
Load File   A 1
Field # 1 from A FIELD1FROMFILEA
Load File   B 1
Field # 1 from B FIELD1FROMFILEB
Field # 2 from B FIELD2FROMFILEB
***SO FAR SO GOOD ! FILES ARE LOADED OK AND FIELDS DISPLAYED AS EXPECTED
------------------------------------------------------------------------
UnlockKey 1
Add File A 1
Add File B 1
Merge to C 2
Clear      1
***MERGING PROCESS HAS BEEN COMPLETED OK...
------------------------------------------------------------------------
UnlockKey      1
Load File   C 1
Field Count C 1
Field # 1 from A FIELD1FROMFILEA
***OPS - WHERE ARE THE FORM FIELDS FROM FILE B ?



Replies:
Posted By: Ingo
Date Posted: 05 Jan 06 at 9:53AM
Hi!
Have this behavior something to do with documents and files? You know the library offers functions like DocumentCount and DocumentID. I think your new file has two documents and you have to select (one after the other) the two documents and document for document you can work with your formfields...
I don't know if it's so ... i think it's so ;-)


-------------
Cheers,
Ingo



Posted By: jabaltie
Date Posted: 05 Jan 06 at 11:07AM
Hi Ingo

Thanks again 4 your support !

I had thought about this before and had also unsucessfully tried it.

Anyway, I tried it again, in another way and now it's WORKING !

Below is another script, which is working.

What I disliked :

- I had to delete page # 1 because it is a blank page
- I'm afraid that the performance may not be so nice


The Script, after all :


OPTION EXPLICIT

DIM objPDF,docFinalPDF,docPDF2beMerged,lni

Set objPDF = WScript.CreateObject("ISED.QUICKPDF")
WScript.Echo "UnlockKey ",objPDF.unlockkey("mykey")

docFinalPDF=objPDF.NewDocument()
WScript.Echo "New       ",docFinalPDF

WScript.Echo "Load File ",objPDF.LoadFromFile("FILEA.PDF")
                          docPDF2beMerged=objPDF.DocumentID(3)
WScript.Echo "doc id M ",docPDF2beMerged

WScript.Echo "field CNT ",objPDF.FormFieldCount
for lni=1 to objPDF.FormFieldCount
    WScript.Echo objPDF.GetFormFieldTitle(lni)
next
WScript.Echo "set form f",objPDF.SetFormFieldValueByTitle("FIELD1FROMFILEA","*field1fromfilea*")

WScript.Echo "Selected ",objPDF.SelectDocument(docFinalPDF)
WScript.Echo "Merge     ",objPDF.MergeDocument(docPDF2beMerged)


WScript.Echo "Load File ",objPDF.LoadFromFile("FILEB.PDF")
                          docPDF2beMerged=objPDF.DocumentID(3)
WScript.Echo "doc id M ",docPDF2beMerged

WScript.Echo "field CNT ",objPDF.FormFieldCount
for lni=1 to objPDF.FormFieldCount
    WScript.Echo objPDF.GetFormFieldTitle(lni)
next
WScript.Echo "set form f",objPDF.SetFormFieldValueByTitle("FIELD1FROMFILEB","*field1fromfileb*")
WScript.Echo "set form f",objPDF.SetFormFieldValueByTitle("FIELD2FROMFILEB","*field2fromfileb*")

WScript.Echo "Selected ",objPDF.SelectDocument(docFinalPDF)
WScript.Echo "Merge     ",objPDF.MergeDocument(docPDF2beMerged)


WScript.Echo "Deletepage",objPDF.DeletePages(1,1)
WScript.Echo "save      ",objPDF.SaveToFile("C:\TEMP\TEST.PDF")



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