[
https://issues.apache.org/jira/browse/PDFBOX-4375?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16682577#comment-16682577
]
Wiktor Kwapisiewicz commented on PDFBOX-4375:
---------------------------------------------
Hi Tilman,
Yes, now I've seen the mail (I unsubscribed in the meantime due to high volume
and I see I was not CC'ed). No worries, I'm glad that we can finally discuss
and I'll post to {{users}} next time!
As for the code I did 2 adjustments and run it over my overlaying code and it
works.
The adjustments: changing method name to {{overlayDocuments}} (overload won't
work on generic maps due to type erasure :( ) and adding a line to put layout
page, as the original does.
The final code:
{code:java}
public PDDocument overlayDocuments(Map<Integer, PDDocument>
specificPageOverlayDocuments) throws IOException
{
loadPDFs();
for (Map.Entry<Integer, PDDocument> e :
specificPageOverlayDocuments.entrySet())
{
PDDocument doc = e.getValue();
if (doc != null)
{
specificPageOverlay.put(e.getKey(), doc);
specificPageOverlayPage.put(e.getKey(), getLayoutPage(doc));
}
}
processPages(inputPDFDocument);
return inputPDFDocument;
}
{code}
Now, the code is very similar to the original {{overlay}}, the only difference
is String vs PDDocuments and the fact that the original has a "cache" of
overlays (keyed on the String value).
Do you think it would be good to refactor these two methods to use the same
code (in some kind of third, helper method)?
{quote}Changing visibility is a somewhat special request because I have read
the chapter in "Effective Java" that warns about the risks.{quote}
Okay, I just finished reading 3rd edition of Effective Java, a lot of new
interesting stuff since the 2nd!
Have a nice evening!
Wiktor
> Change visibility of Overlay#loadPDF to protected
> -------------------------------------------------
>
> Key: PDFBOX-4375
> URL: https://issues.apache.org/jira/browse/PDFBOX-4375
> Project: PDFBox
> Issue Type: Improvement
> Components: Utilities
> Affects Versions: 2.0.12
> Reporter: Wiktor Kwapisiewicz
> Priority: Minor
> Labels: Overlay
> Attachments:
> 0001-Change-visibility-of-Overlay-loadPDF-to-protected.patch
>
>
> Overriding loadPDF allows subclasses to load overlays from sources different
> than File objects, for example from InputStreams or byte arrays (mostly
> through PDDocument.load overloads).
> For example:
> {code:java}
> Overlay overlay = new Overlay() {
> @Override
> protected PDDocument loadPDF(String pdfName) throws IOException {
> return PDDocument.load(overlayStreams.get(pdfName));
> }
> };
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]