You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2022/05/27 13:06:01 UTC
svn commit: r1901328 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java
Author: tilman
Date: Fri May 27 13:06:01 2022
New Revision: 1901328
URL: http://svn.apache.org/viewvc?rev=1901328&view=rev
Log:
PDFBOX-4892: simplify, as suggested by Valery Bokov; improve javadoc
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java?rev=1901328&r1=1901327&r2=1901328&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java Fri May 27 13:06:01 2022
@@ -100,8 +100,9 @@ public class Overlay implements Closeabl
/**
* This will add overlays to a document.
*
- * @param specificPageOverlayFile Optional map of overlay files for specific pages. The page
- * numbers are 1-based. The map must be empty (but not null) if no specific mappings are used.
+ * @param specificPageOverlayFile Optional map of overlay files of which the first page will be
+ * used for specific pages of the input document. The page numbers are 1-based. The map must be
+ * empty (but not null) if no specific mappings are used.
*
* @return The modified input PDF document, which has to be saved and closed by the caller. If
* the input document was passed by {@link #setInputPDF(PDDocument) setInputPDF(PDDocument)}
@@ -111,20 +112,20 @@ public class Overlay implements Closeabl
*/
public PDDocument overlay(Map<Integer, String> specificPageOverlayFile) throws IOException
{
- Map<String, PDDocument> loadedDocuments = new HashMap<>();
- Map<PDDocument, LayoutPage> layouts = new HashMap<>();
+ Map<String, LayoutPage> layouts = new HashMap<>();
+ String path;
loadPDFs();
for (Map.Entry<Integer, String> e : specificPageOverlayFile.entrySet())
{
- PDDocument doc = loadedDocuments.get(e.getValue());
- if (doc == null)
+ path = e.getValue();
+ LayoutPage layoutPage = layouts.get(path);
+ if (layoutPage == null)
{
- doc = loadPDF(e.getValue());
- loadedDocuments.put(e.getValue(), doc);
- layouts.put(doc, getLayoutPage(doc));
+ PDDocument doc = loadPDF(path);
+ layouts.put(path, getLayoutPage(doc));
openDocuments.add(doc);
}
- specificPageOverlayPage.put(e.getKey(), layouts.get(doc));
+ specificPageOverlayPage.put(e.getKey(), layoutPage);
}
processPages(inputPDFDocument);
return inputPDFDocument;
@@ -288,11 +289,25 @@ public class Overlay implements Closeabl
}
}
+ /**
+ * Create a LayoutPage object from the first page of the given document.
+ *
+ * @param doc
+ * @return
+ * @throws IOException
+ */
private LayoutPage getLayoutPage(PDDocument doc) throws IOException
{
return createLayoutPage(doc.getPage(0));
}
+ /**
+ * Create a LayoutPage object from given PDPage object.
+ *
+ * @param doc
+ * @return
+ * @throws IOException
+ */
private LayoutPage createLayoutPage(PDPage page) throws IOException
{
COSBase contents = page.getCOSObject().getDictionaryObject(COSName.CONTENTS);