Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 4438 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hello,

 

I'm using ScriptMaster to combine two PDFs.  I can combine the two PDFs just fine if they do not contain any form fields.  As soon as I use a PDF that contains form fields, I receive an error that the two PDFs were unable to be combined.

 

I've encountered this on FMP12v3 running on OSX 10.6.8

 

If you need additional information from me, please let me know and I will provide it.

Posted

Can you post your code?

it is POSSIBLE but ONLY with AcroForms

 

>> from SO

Fields in PDFs have an Unusual Property: All fields with the same name are the same field. They share a value. This is handy when the form refers to the same person and you have a nice naming scheme across forms. It's Not Handy when you want to put 20 instances of a single form into a single PDF.

There's a class in iText called PdfCopyFields, and it will correctly copy fields from one document to another... it will also merge fields with the same name correctly, such that they really share a single value and Acrobat/Reader doesn't have to do a bunch of extra work on the file to get it that way before displaying it to a user.

Posted

Perhaps I should clarify what I'm attempting to do.

I have a generic document that needs to be merged with any variety of PDFs that I'm handling.  This generic PDF doesn't contain any form fields on it.

 

If I try to combine that PDF with another, it will work fine, unless the second PDF contains even a single form field.

I don't see any issue where the two PDFs contain form fields that have the same name.

 

As far as the code goes, what code are you asking for?

Posted

I'm using itextpdf-5.3.2.jar

Code is:

 

RegisterGroovy( "catPDF( filelist ; fm_fileOut ; preserve )" ; "// catPDF ( filelist ; fm_fileOut ; preserve )¶
// 11_08_12 JR¶
// v3.0¶
// concatenate list of PDF files¶
// correctly moves any bookmarks to new pages¶
// preserve is null removes bookmarks¶
// throws PASSWORD ERROR if a file is protected¶
import com.itextpdf.text.pdf.PdfConcatenate¶
import com.itextpdf.text.pdf.PdfReader¶
import com.itextpdf.text.pdf.SimpleBookmark¶
files = filelist.split('n')¶
offset = 0¶
bookmarks = []¶
copy = new PdfConcatenate(new FileOutputStream(fm_fileOut), true) ¶
try {¶
files.each{item ->¶
  reader = new PdfReader("${item}")¶
  tmp = SimpleBookmark.getBookmark(reader)¶
  added = copy.addPages(reader)¶
  if (tmp){¶
   if ( offset != 0) {¶
        SimpleBookmark.shiftPageNumbers(tmp, offset, null)¶
   } //end if¶
   bookmarks.addAll(tmp)¶
  } //end if¶
  offset = offset + added¶
  } //end each¶
  if (preserve) {¶
   copy.getWriter().setOutlines(bookmarks)¶
  } //end if¶
copy.close()¶
} catch(Exception e) {¶
copy.close()¶
if (e.toString().contains('BadPassword')) { ¶
  f = new File(fm_fileOut)¶
  f.delete()¶
  return 'PASSWORD ERROR'¶
} else {¶
  return 'ERROR'¶
} //end if¶
} //end try¶
return true; isGui = false " )
 
The method used was taken by Matt Petrowsky's demo, which is here:
Posted

So, how exactly are you combining the PDF's? Where did you get the function from? Which libraries are you using to do this?

If you are using iText to do this then just combining PDF files without using the right method will give you exactly the result you are experiencing.

 

Could you post some example PDF's and the Scriptmaster code you are using as the function to add them together, then we might be able to help - at the moment all we can do is say 'yes, that is expected behaviour'

 

edited as you posted while I was writing...

That is indeed based on Matts demo but is in fact my example - I am JR.....

Posted

Ah, well small world. :)

 

Do you still need any more info/code for this?  I've attached two sample files to this reply.  If you try to combine two copies of "About Stacks," it will combine fine.  If you try to combine "About Stacks" with "About Stacks Form," it will produce an error.

 

About Stacks Form.pdf

About Stacks.pdf

Posted

Code attached, only does concatenation, no bookmarks and does not check for non Acrofields, which WILL not work this way.

 

Am using 5.3.4

 

// catPDFforms ( filelist ; fm_fileOut )
// 12_11_27 JR
// v1.0
// simple concatenate list of PDF files including files with Acrofields
// assumes fields do NOT have the same names
// throws PASSWORD ERROR if a file is protected

import com.itextpdf.text.pdf.PdfReader
import com.itextpdf.text.pdf.PdfCopyFields

files = filelist.split('n')
copy = new PdfCopyFields(new FileOutputStream(fm_fileOut)) 
try {
	files.each{item ->
		reader = new PdfReader("${item}")
		added = copy.addDocument(reader)
	} //end each
	copy.close()
} catch(Exception e) {
	copy.close()
	if (e.toString().contains('BadPassword')) { 
		f = new File(fm_fileOut)
		f.delete()
		return 'PASSWORD ERROR'
	} else {
		return 'ERROR'
	} //end if
} //end try

return true

 

edit:

and works with your examples..

 

And the error depends in the version of Reader you are using

With Acrobat X and the old function no error is given, the form opens but is no longer really a form but a flattened version with 'fields' removed

 

What will cause problems is that your form field is called 'Form Field' - always better to use underlines 'Form_Field' - many sleepless hours before that got figured out.

  • Like 1
Posted

I have quick follow-up question.  It appears as if this function will fail if there are offending characters in the filenames that you are attempting to concatenate.  (Specifically, spaces).  Do you have a list of offending characters names that will cause this function to fail?

Posted

James

Does it work if you remove the spaces in the names??

Can't see why it should make a difference.

 

If not can you post an example list of filenames..

 

John

This topic is 4438 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.