Forum How do I...?

How to add a list of graphs as a separate page?

ThePrintingSquirrel
I have the following scenario:

Established PowerShell script that processes HTML pages and calls Prince to create individual PDFs for each HTML page ("chapter"). After this is complete I use PdfBox to merge all chapter PDFs.

I am now investigating how to add a "List of graphs" of all chapters as a new page to the end of the merged PDF.

I have found the Box tracking API and can successfully generate a list of graphs for one HTML document inside the JS script I pass to Prince via the "script=" parameter, however, I cannot figure out how to pass this list back to the PowerShell script, or run a new Prince job to generate a PDF page from that list.

I looked into using Prince.convertToFile but keep getting an "invalid this value" error and am not sure if this is a feasible path to go with.

What would be my options?

Thank you!
mikeday
The convertToFile API only works when running Prince in shell mode rather than during regular document conversion. I think you would need to log the relevant information to the console and collect it in your script and then pass it to a new Prince job, but I'm not sure how best to do that in PowerShell. Passing data between multiple Prince invocations like this to generate a new PDF is a bit advanced and may be easier to do when calling Prince through one of the server wrappers (Java, C#, etc.)
ThePrintingSquirrel
Hi Mike,
that's exactly the path I went down:

1) Added Javascript code to the pre-flight script that I hand over to Prince to prepare my HTML documents, where I console.log LI elements with the graph name and page number

2) Added PowerShell code which takes Prince's output and parses it to create the list.

Multiple lists (graphs, figures, tables) can be output in the same chunk, so I've added start and end keywords for each category to be able to properly parse.

I'm also using a JSON file that PowerShell writes where it stores which of the lists are currently requested. The Javascript code reads it and only parses for those elements.
mikeday
Sounds like quite a sophisticated operation!