Overlay.java (pdfbox-2.0.23-src) | : | Overlay.java (pdfbox-2.0.24-src) | ||
---|---|---|---|---|
skipping to change at line 41 | skipping to change at line 41 | |||
import java.util.Set; | import java.util.Set; | |||
import org.apache.pdfbox.cos.COSArray; | import org.apache.pdfbox.cos.COSArray; | |||
import org.apache.pdfbox.cos.COSBase; | import org.apache.pdfbox.cos.COSBase; | |||
import org.apache.pdfbox.cos.COSDictionary; | import org.apache.pdfbox.cos.COSDictionary; | |||
import org.apache.pdfbox.cos.COSName; | import org.apache.pdfbox.cos.COSName; | |||
import org.apache.pdfbox.cos.COSObject; | import org.apache.pdfbox.cos.COSObject; | |||
import org.apache.pdfbox.cos.COSStream; | import org.apache.pdfbox.cos.COSStream; | |||
import org.apache.pdfbox.io.IOUtils; | import org.apache.pdfbox.io.IOUtils; | |||
import org.apache.pdfbox.pdmodel.PDDocument; | import org.apache.pdfbox.pdmodel.PDDocument; | |||
import org.apache.pdfbox.pdmodel.PDPage; | import org.apache.pdfbox.pdmodel.PDPage; | |||
import org.apache.pdfbox.pdmodel.PDPageTree; | ||||
import org.apache.pdfbox.pdmodel.PDResources; | import org.apache.pdfbox.pdmodel.PDResources; | |||
import org.apache.pdfbox.pdmodel.common.PDRectangle; | import org.apache.pdfbox.pdmodel.common.PDRectangle; | |||
import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject; | import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject; | |||
/** | /** | |||
* Adds an overlay to an existing PDF document. | * Adds an overlay to an existing PDF document. | |||
* | * | |||
* Based on code contributed by Balazs Jerk. | * Based on code contributed by Balazs Jerk. | |||
* | * | |||
*/ | */ | |||
skipping to change at line 369 | skipping to change at line 370 | |||
else | else | |||
{ | { | |||
throw new IOException("Unknown content type: " + contents.getClass() .getName()); | throw new IOException("Unknown content type: " + contents.getClass() .getName()); | |||
} | } | |||
return contentStreams; | return contentStreams; | |||
} | } | |||
private void processPages(PDDocument document) throws IOException | private void processPages(PDDocument document) throws IOException | |||
{ | { | |||
int pageCounter = 0; | int pageCounter = 0; | |||
for (PDPage page : document.getPages()) | PDPageTree pageTree = document.getPages(); | |||
int numberOfPages = pageTree.getCount(); | ||||
for (PDPage page : pageTree) | ||||
{ | { | |||
pageCounter++; | pageCounter++; | |||
COSDictionary pageDictionary = page.getCOSObject(); | LayoutPage layoutPage = getLayoutPage(pageCounter, numberOfPages); | |||
COSBase originalContent = pageDictionary.getDictionaryObject(COSName | ||||
.CONTENTS); | ||||
COSArray newContentArray = new COSArray(); | ||||
LayoutPage layoutPage = getLayoutPage(pageCounter, document.getNumbe | ||||
rOfPages()); | ||||
if (layoutPage == null) | if (layoutPage == null) | |||
{ | { | |||
continue; | continue; | |||
} | } | |||
COSDictionary pageDictionary = page.getCOSObject(); | ||||
COSBase originalContent = pageDictionary.getDictionaryObject(COSName | ||||
.CONTENTS); | ||||
COSArray newContentArray = new COSArray(); | ||||
switch (position) | switch (position) | |||
{ | { | |||
case FOREGROUND: | case FOREGROUND: | |||
// save state | // save state | |||
newContentArray.add(createStream("q\n")); | newContentArray.add(createStream("q\n")); | |||
addOriginalContent(originalContent, newContentArray); | addOriginalContent(originalContent, newContentArray); | |||
// restore state | // restore state | |||
newContentArray.add(createStream("Q\n")); | newContentArray.add(createStream("Q\n")); | |||
// overlay content last | // overlay content last | |||
overlayPage(page, layoutPage, newContentArray); | overlayPage(page, layoutPage, newContentArray); | |||
End of changes. 4 change blocks. | ||||
7 lines changed or deleted | 9 lines changed or added |