Debian Codegraph @

sejda-sambox/src/test/java/org/sejda/impl/sambox/component/DocBuilder.java

raw
1 /*
2 * Copyright 2018 by Eduard Weissmann ([email protected]).
3 *
4 * This file is part of the Sejda source code
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package org.sejda.impl.sambox.component;
21
22 import java.io.IOException;
23
24 import org.sejda.sambox.pdmodel.PDDocument;
25 import org.sejda.sambox.pdmodel.PDPage;
26 import org.sejda.sambox.pdmodel.common.PDPageLabelRange;
27 import org.sejda.sambox.pdmodel.common.PDPageLabels;
28
29 /**
30 * Build a doc on the fly (and test with it)
31 */
32 public class DocBuilder {
33 private PDDocument doc = new PDDocument();
34
35 public PDDocument get() {
36 return doc;
37 }
38
39 public DocBuilder withPages(int numOfPages) {
40 for(int i = 0; i < numOfPages; i++) {
41 PDPage page = new PDPage();
42 doc.addPage(page);
43 }
44
45 return this;
46 }
47
48 public DocBuilder withPageLabelRange(int index, String style) {
49 return withPageLabelRange(index, style, null, null);
50 }
51
52 public DocBuilder withPageLabelRange(int index, String style, String prefix) {
53 return withPageLabelRange(index, style, prefix, null);
54 }
55
56
57 public DocBuilder withPageLabelRange(int index, String style, String prefix, Integer start) {
58 try {
59 PDPageLabels labels = doc.getDocumentCatalog().getPageLabels();
60 if (labels == null) {
61 labels = new PDPageLabels();
62 }
63
64 labels.setLabelItem(index, new PDPageLabelRange(style, prefix, start));
65 doc.getDocumentCatalog().setPageLabels(labels);
66 return this;
67
68 } catch (IOException e) {
69 throw new RuntimeException(e);
70 }
71 }
72 }