Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to add DocIDs as bookmark names? #2

Closed
ccastillo-id opened this issue Apr 30, 2021 · 6 comments
Closed

Possible to add DocIDs as bookmark names? #2

ccastillo-id opened this issue Apr 30, 2021 · 6 comments

Comments

@ccastillo-id
Copy link

There is a Add Bookmarks checkbox that will add bookmark of the attachment's file name. is there a way to use the attachment's docid instead as well?

I tried altering the ExportFamilyPDFs.rb file from

Old
PdfMerger.merge(final_output_file,input_files,add_bookmarks,group.map{|i|i.getLocalisedName})

Attempt
productionSetItems = group.map{|i|i.get_production_set_items}
PdfMerger.merge(final_output_file,input_files,add_bookmarks,productionSetItems.map { |i| i.getDocumentNumber }.join(""))

But no avail

@JuicyDragon
Copy link
Contributor

JuicyDragon commented Apr 30, 2021

Hello @ccastillo-id,

I think you are really close. The issue I believe stems from this line in your version:

productionSetItems = group.map{|i|i.get_production_set_items}

For each item, that returns a Set<ProductionSetItem>. While your logic is treating it as though the result is this:

productionSetItems = [
  ProductionSetItem,
  ProductionSetItem,
  ProductionSetItem,
  ProductionSetItem,
]

I believe conceptually it's more like this:

productionSetItems = [
  [ProductionSetItem],
  [ProductionSetItem],
  [ProductionSetItem],
  [ProductionSetItem],
]

Or it could even possibly be more like this if some items have no production set items and others have more than 1:

productionSetItems = [
  [ProductionSetItem,ProductionSetItem],
  [],
  [ProductionSetItem],
  [ProductionSetItem],
]

I believe if you modify it a bit to the following you should get the result you are looking for:

bookmark_titles = group.map do |item|
	psis = item.getProductionSetItems
	doc_nums = psis.map{|psi| psi.getDocumentNumber.toString }
	next doc_nums.join(";")
end

PdfMerger.merge(final_output_file,input_files,add_bookmarks,bookmark_titles)

Let me know if you have questions about that. I know I had to think about it a bit myself and even re-write it once as my first attempt didn't quite approach it right.

@ccastillo-id
Copy link
Author

ccastillo-id commented May 3, 2021

The error I'm getting with changing it to this is...

Export Directory: C:\Users\srvnuix\Desktop\OUTPUT
Exporting temporary PDFs: native
Exporting temporary PDFs: native
Exporting temporary PDFs: pdf
Exporting temporary PDFs: pdf
Exporting temporary PDFs: pdf
Exporting temporary PDFs: pdf
Exporting temporary PDFs: stamping
Exporting temporary PDFs: stamping
Exporting temporary PDFs: digest
Family Groups: 234
Generating combined PDFs...
Merging 1 PDFs into single PDF: REV00000001.pdf
Error occured in provided block:
(RuntimeError) Error while creating output file directories: undefined method mkdirs' for nil:NilClass output_file: REV00000001.pdf input_files: C:\Users\srvnuix\Desktop\OUTPUT\_Temp_\PDFs\e59\e595afc8-fb4f-46d7-9a2a-023b3d8919b9.pdf org.jruby.exceptions.RuntimeError: (RuntimeError) Error while creating output file directories: undefined method mkdirs' for nil:NilClass
output_file: REV00000001.pdf
input_files: C:\Users\srvnuix\Desktop\OUTPUT_Temp_\PDFs\e59\e595afc8-fb4f-46d7-9a2a-023b3d8919b9.pdf
at RUBY.merge(C:/ProgramData/Nuix/Scripts/ExportFamilyPDFs_v1.14.0/ExportFamilyPDFs.nuixscript/PdfMerger.rb:19)
at RUBY.

(C:\ProgramData\Nuix\Scripts\ExportFamilyPDFs_v1.14.0\ExportFamilyPDFs.nuixscript\ExportFamilyPDFs.rb:564)
at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1809)
at org.jruby.RubyEnumerable.each_with_index(org/jruby/RubyEnumerable.java:1258)
at RUBY.(C:\ProgramData\Nuix\Scripts\ExportFamilyPDFs_v1.14.0\ExportFamilyPDFs.nuixscript\ExportFamilyPDFs.rb:475)
at RUBY.(C:\ProgramData\Nuix\Scripts\ExportFamilyPDFs_v1.14.0\ExportFamilyPDFs.nuixscript\ExportFamilyPDFs.rb:281)

NEW CODE

			# Merge the PDFs
			# Depending on whether we used DAT for paths or found them manually we
			# determine the paths a little differently
			input_files = nil
			if export_dat
				input_files = group.map{|i|"#{temp_directory}\\#{pdf_lookup[i.getGuid]}"}
			else
				input_files = group.map{|i|pdf_lookup[i.getGuid]}
			end
			pd.logMessage("Merging #{group.size} PDFs into single PDF: #{final_output_file}")
			pd.logMessage("\tOutput filename modified to prevent overwriting existing combined PDF.") if final_output_file != output_file
			
			bookmark_titles = group.map do |item|
				psis = item.getProductionSetItems
				doc_nums = psis.map{|psi| psi.getDocumentNumber.toString }
				next doc_nums.join(";")
			end				
			
			PdfMerger.merge(final_output_file,input_files,add_bookmarks,bookmark_titles)

@ccastillo-id
Copy link
Author

Interesting... when I add a slash in the File Name Template
image
I get an Access is Denied error

@JuicyDragon
Copy link
Contributor

JuicyDragon commented May 3, 2021

I was just looking into what could cause this, but I see the issue now that you've included a screenshot. Change it from

\{docid}.pdf

to

{export_directory}\{docid}.pdf

The error message was happening on this line:

java.io.File.new(output_file).getParentFile.mkdirs

When the template was resolving, it was just a file name without a directory, which causes getParentFile to return null and the mkdirs call to throw that error.

@ccastillo-id
Copy link
Author

This works! Thanks!

@JuicyDragon
Copy link
Contributor

Glad to hear it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants