PdfCopyFields.java

1
/*
2
 * Copyright 2004 by Paulo Soares.
3
 *
4
 * The contents of this file are subject to the Mozilla Public License Version 1.1
5
 * (the "License"); you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
7
 *
8
 * Software distributed under the License is distributed on an "AS IS" basis,
9
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10
 * for the specific language governing rights and limitations under the License.
11
 *
12
 * The Original Code is 'iText, a free JAVA-PDF library'.
13
 *
14
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
15
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
16
 * All Rights Reserved.
17
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
18
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
19
 *
20
 * Contributor(s): all the names of the contributors are added in the source code
21
 * where applicable.
22
 *
23
 * Alternatively, the contents of this file may be used under the terms of the
24
 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
25
 * provisions of LGPL are applicable instead of those above.  If you wish to
26
 * allow use of your version of this file only under the terms of the LGPL
27
 * License and not to allow others to use your version of this file under
28
 * the MPL, indicate your decision by deleting the provisions above and
29
 * replace them with the notice and other provisions required by the LGPL.
30
 * If you do not delete the provisions above, a recipient may use your version
31
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
32
 *
33
 * This library is free software; you can redistribute it and/or modify it
34
 * under the terms of the MPL as stated above or under the terms of the GNU
35
 * Library General Public License as published by the Free Software Foundation;
36
 * either version 2 of the License, or any later version.
37
 *
38
 * This library is distributed in the hope that it will be useful, but WITHOUT
39
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
40
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
41
 * details.
42
 *
43
 * If you didn't download this code from the following link, you should check if
44
 * you aren't using an obsolete version:
45
 * http://www.lowagie.com/iText/
46
 */
47
package com.lowagie.text.pdf;
48
49
import java.io.IOException;
50
import java.io.OutputStream;
51
import java.security.cert.Certificate;
52
import java.util.List;
53
54
import com.lowagie.text.DocWriter;
55
import com.lowagie.text.DocumentException;
56
import com.lowagie.text.pdf.interfaces.PdfEncryptionSettings;
57
import com.lowagie.text.pdf.interfaces.PdfViewerPreferences;
58
59
/**
60
 * Concatenates PDF documents including form fields. The rules for the form field
61
 * concatenation are the same as in Acrobat. All the documents are kept in memory unlike
62
 * PdfCopy.
63
 * @author  Paulo Soares (psoares@consiste.pt)
64
 */
65
public class PdfCopyFields
66
    implements PdfViewerPreferences, PdfEncryptionSettings {
67
    
68
    private PdfCopyFieldsImp fc;
69
    
70
    /**
71
     * Creates a new instance.
72
     * @param os the output stream
73
     * @throws DocumentException on error
74
     */    
75
    public PdfCopyFields(OutputStream os) throws DocumentException {
76
        fc = new PdfCopyFieldsImp(os);
77
    }
78
    
79
    /**
80
     * Creates a new instance.
81
     * @param os the output stream
82
     * @param pdfVersion the pdf version the output will have
83
     * @throws DocumentException on error
84
     */    
85
    public PdfCopyFields(OutputStream os, char pdfVersion) throws DocumentException {
86
        fc = new PdfCopyFieldsImp(os, pdfVersion);
87
    }
88
    
89
    /**
90
     * Concatenates a PDF document.
91
     * @param reader the PDF document
92
     * @throws DocumentException on error
93
     */    
94
    public void addDocument(PdfReader reader) throws DocumentException, IOException {
95
        fc.addDocument(reader);
96
    }
97
    
98
    /**
99
     * Concatenates a PDF document selecting the pages to keep. The pages are described as a
100
     * <CODE>List</CODE> of <CODE>Integer</CODE>. The page ordering can be changed but
101
     * no page repetitions are allowed.
102
     * @param reader the PDF document
103
     * @param pagesToKeep the pages to keep
104
     * @throws DocumentException on error
105
     */    
106
    public void addDocument(PdfReader reader, List pagesToKeep) throws DocumentException, IOException {
107
        fc.addDocument(reader, pagesToKeep);
108
    }
109
110
    /**
111
     * Concatenates a PDF document selecting the pages to keep. The pages are described as
112
     * ranges. The page ordering can be changed but
113
     * no page repetitions are allowed.
114
     * @param reader the PDF document
115
     * @param ranges the comma separated ranges as described in {@link SequenceList}
116
     * @throws DocumentException on error
117
     */    
118
    public void addDocument(PdfReader reader, String ranges) throws DocumentException, IOException {
119 1 1. addDocument : removed call to com/lowagie/text/pdf/PdfCopyFieldsImp::addDocument → NO_COVERAGE
        fc.addDocument(reader, SequenceList.expand(ranges, reader.getNumberOfPages()));
120
    }
121
122
    /** Sets the encryption options for this document. The userPassword and the
123
     *  ownerPassword can be null or have zero length. In this case the ownerPassword
124
     *  is replaced by a random string. The open permissions for the document can be
125
     *  AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
126
     *  AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
127
     *  The permissions can be combined by ORing them.
128
     * @param userPassword the user password. Can be null or empty
129
     * @param ownerPassword the owner password. Can be null or empty
130
     * @param permissions the user permissions
131
     * @param strength128Bits <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length
132
     * @throws DocumentException if the document is already open
133
     */
134
    public void setEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits) throws DocumentException {
135 2 1. setEncryption : negated conditional → NO_COVERAGE
2. setEncryption : removed call to com/lowagie/text/pdf/PdfCopyFieldsImp::setEncryption → NO_COVERAGE
        fc.setEncryption(userPassword, ownerPassword, permissions, strength128Bits ? PdfWriter.STANDARD_ENCRYPTION_128 : PdfWriter.STANDARD_ENCRYPTION_40);
136
    }
137
    
138
    /**
139
     * Sets the encryption options for this document. The userPassword and the
140
     *  ownerPassword can be null or have zero length. In this case the ownerPassword
141
     *  is replaced by a random string. The open permissions for the document can be
142
     *  AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
143
     *  AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
144
     *  The permissions can be combined by ORing them.
145
     * @param strength true for 128 bit key length. false for 40 bit key length
146
     * @param userPassword the user password. Can be null or empty
147
     * @param ownerPassword the owner password. Can be null or empty
148
     * @param permissions the user permissions
149
     * @throws DocumentException if the document is already open
150
     */
151
    public void setEncryption(boolean strength, String userPassword, String ownerPassword, int permissions) throws DocumentException {
152 1 1. setEncryption : removed call to com/lowagie/text/pdf/PdfCopyFields::setEncryption → NO_COVERAGE
        setEncryption(DocWriter.getISOBytes(userPassword), DocWriter.getISOBytes(ownerPassword), permissions, strength);
153
    }
154
 
155
    /**
156
     * Closes the output document.
157
     */    
158
    public void close() {
159
        fc.close();
160
    }
161
162
    /**
163
     * Opens the document. This is usually not needed as addDocument() will do it
164
     * automatically.
165
     */    
166
    public void open() {
167
        fc.openDoc();
168
    }
169
170
    /**
171
     * Adds JavaScript to the global document
172
     * @param js the JavaScript
173
     */    
174
    public void addJavaScript(String js) {
175 2 1. addJavaScript : negated conditional → NO_COVERAGE
2. addJavaScript : removed call to com/lowagie/text/pdf/PdfCopyFieldsImp::addJavaScript → NO_COVERAGE
        fc.addJavaScript(js, !PdfEncodings.isPdfDocEncoding(js));
176
    }
177
178
    /**
179
     * Sets the bookmarks. The list structure is defined in
180
     * <CODE>SimpleBookmark#</CODE>.
181
     * @param outlines the bookmarks or <CODE>null</CODE> to remove any
182
     */    
183
    public void setOutlines(List outlines) {
184
        fc.setOutlines(outlines);
185
    }
186
    
187
    /** Gets the underlying PdfWriter.
188
     * @return the underlying PdfWriter
189
     */    
190
    public PdfWriter getWriter() {
191
        return fc;
192
    }
193
194
    /**
195
     * Gets the 1.5 compression status.
196
     * @return <code>true</code> if the 1.5 compression is on
197
     */
198
    public boolean isFullCompression() {
199
        return fc.isFullCompression();
200
    }
201
    
202
    /**
203
     * Sets the document's compression to the new 1.5 mode with object streams and xref
204
     * streams. It can be set at any time but once set it can't be unset.
205
     * <p>
206
     * If set before opening the document it will also set the pdf version to 1.5.
207
     */
208
    public void setFullCompression() {
209
        fc.setFullCompression();
210
    }
211
212
    /**
213
     * @see com.lowagie.text.pdf.interfaces.PdfEncryptionSettings#setEncryption(byte[], byte[], int, int)
214
     */
215
    public void setEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionType) throws DocumentException {
216
        fc.setEncryption(userPassword, ownerPassword, permissions, encryptionType);
217
    }
218
219
    /**
220
     * @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#addViewerPreference(com.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfObject)
221
     */
222
    public void addViewerPreference(PdfName key, PdfObject value) {
223
        fc.addViewerPreference(key, value);    
224
    }
225
226
    /**
227
     * @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#setViewerPreferences(int)
228
     */
229
    public void setViewerPreferences(int preferences) {
230
        fc.setViewerPreferences(preferences);
231
    }
232
233
    /**
234
     * @see com.lowagie.text.pdf.interfaces.PdfEncryptionSettings#setEncryption(java.security.cert.Certificate[], int[], int)
235
     */
236
    public void setEncryption(Certificate[] certs, int[] permissions, int encryptionType) throws DocumentException {
237
        fc.setEncryption(certs, permissions, encryptionType);
238
    }    
239
}

Mutations

119

1.1
Location : addDocument
Killed by : none
removed call to com/lowagie/text/pdf/PdfCopyFieldsImp::addDocument → NO_COVERAGE

135

1.1
Location : setEncryption
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : setEncryption
Killed by : none
removed call to com/lowagie/text/pdf/PdfCopyFieldsImp::setEncryption → NO_COVERAGE

152

1.1
Location : setEncryption
Killed by : none
removed call to com/lowagie/text/pdf/PdfCopyFields::setEncryption → NO_COVERAGE

175

1.1
Location : addJavaScript
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : addJavaScript
Killed by : none
removed call to com/lowagie/text/pdf/PdfCopyFieldsImp::addJavaScript → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2