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

Print multiple recordsheets to the same file as multiple pages? #91

Closed
mhjacks opened this issue Oct 3, 2017 · 9 comments
Closed

Print multiple recordsheets to the same file as multiple pages? #91

mhjacks opened this issue Oct 3, 2017 · 9 comments
Assignees

Comments

@mhjacks
Copy link
Contributor

mhjacks commented Oct 3, 2017

Occasionally I like to print PDFs of recordsheets, to validate how things will look before committing to paper. It seems that MML outputs a new job for every page, instead of generating the whole print job and outputting that to a file.

On Linux, printing to cups-pdf doesn't give you the option to save each output job to a new file, as the Microsoft Print to PDF option does on Windows. I was wondering what was happening to the rest of my company, since no matter how many units were in my MUL, there was only one character sheet.

Still, I would prefer a single file with a bunch of character sheets, as I can be selective about which units I print from PDF inside a PDF viewer.

@arlith
Copy link
Member

arlith commented Oct 3, 2017

You're right, and I noticed this while working on warships. I've got an uncommitted fix for it, but I haven't had time to update all of the printing classes yet.

@mhjacks
Copy link
Contributor Author

mhjacks commented Oct 3, 2017

What needs to be done? I could take a swipe at it and submit a PR.

@arlith
Copy link
Member

arlith commented Oct 3, 2017

Here's the diff. You won't have the PrintWarship class unless you checkout the printingWork branch, but from what I remember all of the Print<X> classes are basically copy/pastes of each other.

What you need to pay attention to are:
https://docs.oracle.com/javase/8/docs/api/java/awt/print/PrinterJob.html
https://docs.oracle.com/javase/8/docs/api/index.html?java/awt/print/Printable.html
http://docs.oracle.com/javase/7/docs/api/java/awt/print/Pageable.html

And here's some example code with pagination: https://docs.oracle.com/javase/tutorial/2d/printing/examples/PaginationExample.java

I think this fix is basically done, except propagating it to all of the other classes. I wanted to finish the Warship printing changes, then make this fix as a separate branch, but I haven't gotten back to warship printing yet.

print.txt

@mhjacks
Copy link
Contributor Author

mhjacks commented Oct 3, 2017

OK, let me have a go at this. Thanks!

@mhjacks
Copy link
Contributor Author

mhjacks commented Oct 4, 2017

OK, I've looked at the code a bit, and I'm wondering...will this approach fix the underlying problem, if the MUL (for example) to be printed contains different types of units? (e.g. Tanks, Mechs, BattleArmor)? If I read it correctly, the print job size will be the number of units of that type to be printed, as the master list is compiled in UnitPrintManager.java. Would it help to set the unknown number of pages constant? I'm still a little shaky about the semantics of print jobs and the master print job.

@arlith
Copy link
Member

arlith commented Oct 4, 2017

I'd have to go back and review the documentation, but I think you're right. I didn't consider this because I only ever wrote the code to handle one unit type, but if you've got multiple unit types, there needs to be some mechanism to know the total number of units to print, and also where they are in the process. Additionally, it would probably be good to allow units to potentially have multiple pages (there's at least one official Warships RS that has two pages....).

None of that seems particularly complicated to add, you just need the methods to compute that information (potentially a static int getNumPages(Entity), then total up the number of pages, and pass that information in. You may also need to know the starting page too.

@neoancient
Copy link
Member

I forgot where I had seen this conversation. When I couldn't find it on Slack I just went ahead and implemented this, then just before committing I checked to see if there was an issue open, and here was the conversation I was looking for.

I used the Book class, which is a simple implementation of the Pageable interface. You use it by appending Printable objects then call PrintJob.setPageable(Book). Book.append() has an optional parameter that allows you to allot multiple pages to a Printable when adding it, which would allow multi-page record sheets. If you passed the current page count (Book.getNumberOfPages()) as a parameter to PrintWarship() it would be able to compare the pageIndex passed to print() to determine which page of the record sheet is being requested.

@neoancient neoancient changed the title Should MML print multiple recordsheets to the same file as multiple pages? Print multiple recordsheets to the same file as multiple pages? Nov 15, 2017
@neoancient neoancient self-assigned this Nov 15, 2017
@mhjacks
Copy link
Contributor Author

mhjacks commented Nov 15, 2017

No sweat. I haven't had as much time IRL to work on this as I'd hoped. I'm excited to see this implemented!

@neoancient
Copy link
Member

Implemented in 1b61a11

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

No branches or pull requests

3 participants