Code Monkey home page Code Monkey logo

Comments (6)

JuicyDragon avatar JuicyDragon commented on June 24, 2024

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.

from export-family-pdfs.

ccastillo-id avatar ccastillo-id commented on June 24, 2024

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)

from export-family-pdfs.

ccastillo-id avatar ccastillo-id commented on June 24, 2024

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

from export-family-pdfs.

JuicyDragon avatar JuicyDragon commented on June 24, 2024

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.

from export-family-pdfs.

ccastillo-id avatar ccastillo-id commented on June 24, 2024

This works! Thanks!

from export-family-pdfs.

JuicyDragon avatar JuicyDragon commented on June 24, 2024

Glad to hear it!

from export-family-pdfs.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.