diff --git a/openpdf/src/main/java/com/lowagie/text/Annotation.java b/openpdf/src/main/java/com/lowagie/text/Annotation.java
index 8ea274ba44..a30db914aa 100644
--- a/openpdf/src/main/java/com/lowagie/text/Annotation.java
+++ b/openpdf/src/main/java/com/lowagie/text/Annotation.java
@@ -577,6 +577,16 @@ public String content() {
return s;
}
+ /**
+ * Gets the content of this Annotation
.
+ * @deprecated use {@link #getAttributes()}
+ * @return a reference
+ */
+ @Deprecated
+ public HashMap attributes() {
+ return (HashMap) annotationAttributes;
+ }
+
/**
* Gets the content of this Annotation
.
*
diff --git a/openpdf/src/main/java/com/lowagie/text/Cell.java b/openpdf/src/main/java/com/lowagie/text/Cell.java
index faef3bd37b..8207261281 100644
--- a/openpdf/src/main/java/com/lowagie/text/Cell.java
+++ b/openpdf/src/main/java/com/lowagie/text/Cell.java
@@ -272,6 +272,29 @@ public int getHorizontalAlignment() {
return horizontalAlignment;
}
+ /**
+ * Sets the horizontal alignment.
+ * @param value the new value
+ * @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
+ * use {@link Cell#setHorizontalAlignment(HorizontalAlignment)} instead
+ */
+ @Deprecated
+ public void setHorizontalAlignment(int value) {
+ horizontalAlignment = value;
+ }
+
+ /**
+ * Sets the alignment of this cell.
+ * This methods allows you to set the alignment as a String.
+ * @param alignment the new alignment as a String
+ * @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
+ * use {@link Cell#setHorizontalAlignment(HorizontalAlignment)} instead
+ */
+ @Deprecated
+ public void setHorizontalAlignment(String alignment) {
+ setHorizontalAlignment(ElementTags.alignmentValue(alignment));
+ }
+
/**
* Gets the vertical alignment.
* @return a value
@@ -280,6 +303,29 @@ public int getVerticalAlignment() {
return verticalAlignment;
}
+ /**
+ * Sets the vertical alignment.
+ * @param value the new value
+ * @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
+ * use {@link Cell#setVerticalAlignment(VerticalAlignment)} instead
+ */
+ @Deprecated
+ public void setVerticalAlignment(int value) {
+ verticalAlignment = value;
+ }
+
+ /**
+ * Sets the alignment of this paragraph.
+ *
+ * @param alignment the new alignment as a String
+ * @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
+ * use {@link Cell#setVerticalAlignment(VerticalAlignment)} instead
+ */
+ @Deprecated
+ public void setVerticalAlignment(String alignment) {
+ setVerticalAlignment(ElementTags.alignmentValue(alignment));
+ }
+
/**
* Sets the width.
*
diff --git a/openpdf/src/main/java/com/lowagie/text/Chunk.java b/openpdf/src/main/java/com/lowagie/text/Chunk.java
index 16011fe6db..70983355da 100644
--- a/openpdf/src/main/java/com/lowagie/text/Chunk.java
+++ b/openpdf/src/main/java/com/lowagie/text/Chunk.java
@@ -414,6 +414,18 @@ public boolean hasAttributes() {
return attributes != null;
}
+ /**
+ * Gets the attributes for this Chunk
.
+ *
+ * It may be null.
+ * @deprecated use {@link #getChunkAttributes()}
+ * @return the attributes for this Chunk
+ */
+ @Deprecated
+ public HashMap getAttributes() {
+ return (HashMap) attributes;
+ }
+
/**
* Gets the attributes for this Chunk
.
*
@@ -426,6 +438,17 @@ public Map getChunkAttributes() {
return attributes;
}
+ /**
+ * Sets the attributes all at once.
+ * @param attributes the attributes of a Chunk
+ * @deprecated use {@link #setChunkAttributes(Map)}
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void setAttributes(HashMap attributes) {
+ this.attributes = attributes;
+ }
+
/**
* Sets the attributes all at once.
* @param attributes the attributes of a Chunk
diff --git a/openpdf/src/main/java/com/lowagie/text/ImageLoader.java b/openpdf/src/main/java/com/lowagie/text/ImageLoader.java
index 9ba90db933..2f63fabcf0 100644
--- a/openpdf/src/main/java/com/lowagie/text/ImageLoader.java
+++ b/openpdf/src/main/java/com/lowagie/text/ImageLoader.java
@@ -162,6 +162,12 @@ public static Image getBmpImage(byte[] imageData) {
/**
* Creates an Image from an array of tiff image bytes.
+ * For JRE < 9, `ImageIO.read()` requires a supporting library in the classpath to read tiffs.
+ * Options are:
+ * - https://github.com/jai-imageio/jai-imageio-core
+ * - https://github.com/haraldk/TwelveMonkeys
+ *
+ * see: https://openjdk.java.net/jeps/262
*
* @param imageData bytes of the tiff image
* @return an objet of type Image
diff --git a/openpdf/src/main/java/com/lowagie/text/Paragraph.java b/openpdf/src/main/java/com/lowagie/text/Paragraph.java
index ad2ed02b3e..f1e0da349b 100644
--- a/openpdf/src/main/java/com/lowagie/text/Paragraph.java
+++ b/openpdf/src/main/java/com/lowagie/text/Paragraph.java
@@ -480,6 +480,32 @@ public float getExtraParagraphSpace() {
public void setExtraParagraphSpace(float extraParagraphSpace) {
this.extraParagraphSpace = extraParagraphSpace;
}
+
+ // scheduled for removal
+
+ /**
+ * Gets the spacing before this paragraph.
+ *
+ * @return the spacing
+ * @deprecated As of iText 2.1.5, replaced by {@link #getSpacingBefore()},
+ * scheduled for removal at 2.3.0
+ */
+ @Deprecated
+ public float spacingBefore() {
+ return getSpacingBefore();
+ }
+
+ /**
+ * Gets the spacing after this paragraph.
+ *
+ * @return the spacing
+ * @deprecated As of iText 2.1.5, replaced by {@link #getSpacingAfter()},
+ * scheduled for removal at 2.3.0
+ */
+ @Deprecated
+ public float spacingAfter() {
+ return spacingAfter;
+ }
public int getRunDirection() {
return runDirection;
diff --git a/openpdf/src/main/java/com/lowagie/text/Row.java b/openpdf/src/main/java/com/lowagie/text/Row.java
index b4528fe92e..bc0524e43b 100644
--- a/openpdf/src/main/java/com/lowagie/text/Row.java
+++ b/openpdf/src/main/java/com/lowagie/text/Row.java
@@ -365,6 +365,18 @@ public int getColumns() {
return columns;
}
+ /**
+ * Sets the horizontal alignment.
+ *
+ * @param value the new value
+ * @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
+ * use {@link Row#setHorizontalAlignment(HorizontalAlignment)} instead
+ */
+ @Deprecated
+ public void setHorizontalAlignment(int value) {
+ horizontalAlignment = value;
+ }
+
/**
* Gets the horizontal alignment.
*
diff --git a/openpdf/src/main/java/com/lowagie/text/StandardFonts.java b/openpdf/src/main/java/com/lowagie/text/StandardFonts.java
index 933880c4f6..7e914be5d1 100644
--- a/openpdf/src/main/java/com/lowagie/text/StandardFonts.java
+++ b/openpdf/src/main/java/com/lowagie/text/StandardFonts.java
@@ -13,7 +13,6 @@ public enum StandardFonts {
HELVETICA_ITALIC(Font.HELVETICA, Font.ITALIC),
HELVETICA_BOLD(Font.HELVETICA, Font.BOLD),
HELVETICA_BOLDITALIC(Font.HELVETICA, Font.BOLDITALIC),
-
// Times
TIMES(Font.TIMES_ROMAN, Font.NORMAL),
TIMES_ITALIC(Font.TIMES_ROMAN, Font.ITALIC),
@@ -26,19 +25,36 @@ public enum StandardFonts {
private int family;
private int style;
+ /**
+ * @deprecated Use Liberation
+ */
+ @Deprecated
+ private String trueTypeFile;
StandardFonts(int family, int style) {
this.family = family;
this.style = style;
}
+ /**
+ * @deprecated Use Liberation
+ */
+ @Deprecated
+ StandardFonts(String trueTypeFile) {
+ this.trueTypeFile = trueTypeFile;
+ }
+
public Font create() throws IOException {
return create(Font.DEFAULTSIZE);
}
public Font create(int size) throws IOException {
final Font font;
- if (style == -1) {
+ if (trueTypeFile != null) {
+ final String message = String
+ .format("%s: Please use fonts from openpdf-fonts-extra (Liberation)", this);
+ throw new IOException(message);
+ } else if (style == -1) {
font = new Font(family, size);
} else {
font = new Font(family, size, style);
@@ -47,6 +63,6 @@ public Font create(int size) throws IOException {
}
public boolean isDeprecated() {
- return false;
+ return trueTypeFile != null;
}
}
diff --git a/openpdf/src/main/java/com/lowagie/text/Table.java b/openpdf/src/main/java/com/lowagie/text/Table.java
index e805887dca..e5a1b230c6 100644
--- a/openpdf/src/main/java/com/lowagie/text/Table.java
+++ b/openpdf/src/main/java/com/lowagie/text/Table.java
@@ -428,6 +428,39 @@ public int endHeaders() {
public int getAlignment() {
return alignment;
}
+
+ /**
+ * Sets the horizontal alignment.
+ *
+ * @param value the new value
+ * @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
+ * use {@link Table#setHorizontalAlignment(HorizontalAlignment)} instead
+ *
+ */
+ @Deprecated
+ public void setAlignment(int value) {
+ alignment = value;
+ }
+
+ /**
+ * Sets the alignment of this paragraph.
+ *
+ * @param alignment the new alignment as a String
+ * @deprecated Setting alignment through unconstrained types is non-obvious and error-prone,
+ * use {@link Table#setHorizontalAlignment(HorizontalAlignment)} instead
+ */
+ @Deprecated
+ public void setAlignment(String alignment) {
+ if (ElementTags.ALIGN_LEFT.equalsIgnoreCase(alignment)) {
+ this.alignment = Element.ALIGN_LEFT;
+ return;
+ }
+ if (ElementTags.RIGHT.equalsIgnoreCase(alignment)) {
+ this.alignment = Element.ALIGN_RIGHT;
+ return;
+ }
+ this.alignment = Element.ALIGN_CENTER;
+ }
@Override
public void setHorizontalAlignment(final HorizontalAlignment alignment) {
@@ -1469,5 +1502,27 @@ public boolean isComplete() {
public void setComplete(boolean complete) {
this.complete = complete;
}
-
+
+ /**
+ * Gets the default layout of the Table.
+ * @return a cell with all the defaults
+ * @deprecated As of iText 2.0.7, replaced by {@link #getDefaultCell()},
+ * scheduled for removal at 2.2.0
+ */
+ @Deprecated
+ public Cell getDefaultLayout() {
+ return getDefaultCell();
+ }
+
+ /**
+ * Sets the default layout of the Table to
+ * the provided Cell
+ * @param value a cell with all the defaults
+ * @deprecated As of iText 2.0.7, replaced by {@link #setDefaultCell(Cell)},
+ * scheduled for removal at 2.2.0
+ */
+ @Deprecated
+ public void setDefaultLayout(Cell value) {
+ defaultCell = value;
+ }
}
diff --git a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/ChainedProperties.java b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/ChainedProperties.java
index e09d078382..970a5fdf30 100755
--- a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/ChainedProperties.java
+++ b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/ChainedProperties.java
@@ -63,7 +63,8 @@ public class ChainedProperties {
/**
* Will be replaced with types alternative
*/
- public ArrayList chain = new ArrayList<>();
+ @Deprecated
+ public ArrayList chain = new ArrayList<>();
/**
* Creates a new instance of ChainedProperties
@@ -84,7 +85,7 @@ public String getProperty(String key) {
*/
public Optional findProperty(String key) {
for (int k = chain.size() - 1; k >= 0; --k) {
- Object[] obj = chain.get(k);
+ Object[] obj = (Object[]) chain.get(k);
HashMap prop = (HashMap) obj[1];
String ret = (String) prop.get(key);
if (ret != null) {
@@ -115,6 +116,17 @@ public boolean hasProperty(String key) {
return false;
}
+ /**
+ * @deprecated use {@link ChainedProperties#addToChain(String, HashMap)}
+ * @param key the key
+ * @param prop the properties
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void addToChain(String key, HashMap prop) {
+ addToChain(key, (Map) prop);
+ }
+
public void addToChain(String key, Map prop) {
// adjust the font size
String value = prop.get(ElementTags.SIZE);
diff --git a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/FactoryProperties.java b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/FactoryProperties.java
index 222d9b7778..de22b70897 100755
--- a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/FactoryProperties.java
+++ b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/FactoryProperties.java
@@ -219,7 +219,23 @@ public static HyphenationEvent getHyphenation(String s) {
return new HyphenationAuto(lang, country, leftMin, rightMin);
}
+ /**
+ * This method isn't used by iText, but you can use it to analyze
+ * the value of a style attribute inside a HashMap.
+ * The different elements of the style attribute are added to the
+ * HashMap as key-value pairs.
+ *
+ * @param h a HashMap that should have at least a key named
+ * style. After this method is invoked, more keys could be added.
+ *
+ * @deprecated use {@link FactoryProperties#insertStyle(Map)} instead. (since 1.2.22)
+ */
+ @SuppressWarnings("unchecked")
@Deprecated // this method is nor called anywhere. But it is public so theoretically it could be called by consumers of OpenPdf, but why?
+ public static void insertStyle(HashMap h) {
+ insertStyle((Map) h);
+ }
+
public static void insertStyle(Map h) {
String style = h.get("style");
if (style == null)
@@ -339,10 +355,10 @@ public static void insertStyle(Map h, ChainedProperties cprops)
case Markup.CSS_KEY_BG: {
for(String attribute: prop.getProperty(key).split(" ")) {
Color c = Markup.decodeColor(attribute.trim());
- if (c != null) {
+ if (c != null) {
h.put(Markup.CSS_KEY_BGCOLOR, attribute.trim());
break;
- }
+ }
}
break;
}
diff --git a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/HTMLWorker.java b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/HTMLWorker.java
index 6b0675fc2c..4053ea07db 100755
--- a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/HTMLWorker.java
+++ b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/HTMLWorker.java
@@ -126,6 +126,21 @@ public static ArrayList parseToList(Reader reader, StyleSheet style) th
return parseToList(reader, style, interfaceProps);
}
+ /**
+ * @deprecated use {@link HTMLWorker#parseToList(Reader, StyleSheet, Map)} since 1.2.22
+ * @param reader the Reader
+ * @param style the StyleSheet
+ * @param interfaceProps the interface properties
+ * @return an ArrayList
+ * @throws IOException on error
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public static ArrayList parseToList(Reader reader, StyleSheet style, HashMap interfaceProps)
+ throws IOException {
+ return parseToList(reader, style, (Map) interfaceProps);
+ }
+
public static ArrayList parseToList(Reader reader, StyleSheet style, Map interfaceProps)
throws IOException {
HTMLWorker worker = new HTMLWorker(null);
@@ -151,6 +166,17 @@ public Map getInterfaceProps() {
return interfaceProps;
}
+ /**
+ *
+ * @deprecated use {@link HTMLWorker#setInterfaceProps(Map)} since 1.2.22
+ * @param interfaceProps the properties of the interface
+ */
+ @SuppressWarnings("unchecked")
+ @Deprecated
+ public void setInterfaceProps(HashMap interfaceProps) {
+ setInterfaceProps((Map) interfaceProps);
+ }
+
public void setInterfaceProps(Map interfaceProps) {
this.interfaceProps = interfaceProps;
FontProvider ff = null;
@@ -182,6 +208,15 @@ public void startDocument() {
cprops.addToChain("body", h);
}
+ /**
+ * @deprecated use {@link HTMLWorker#startElement(String, Map)} } since 1.2.22
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void startElement(String tag, HashMap h) {
+ startElement(tag, (Map) h);
+ }
+
public void startElement(String tag, Map style) {
if (!tagsSupported.containsKey(tag)) {
return;
diff --git a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/IncTable.java b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/IncTable.java
index a2d4370dfd..6ffee4df1b 100755
--- a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/IncTable.java
+++ b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/IncTable.java
@@ -64,6 +64,15 @@ public class IncTable {
private Map props = new HashMap<>();
private List> rows = new ArrayList<>();
private List cols;
+ /** Creates a new instance of IncTable
+ * @param props a HashMap of the properties
+ */
+
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public IncTable(HashMap props) {
+ this.props.putAll(props);
+ }
public IncTable(Map props) {
this.props.putAll(props);
@@ -74,6 +83,15 @@ public void addCol(PdfPCell cell) {
cols = new ArrayList<>();
cols.add(cell);
}
+
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void addCols(ArrayList ncols) {
+ if (cols == null)
+ cols = (List)ncols;
+ else
+ cols.addAll(ncols);
+ }
public void addCols(List ncols) {
if (cols == null)
@@ -89,6 +107,15 @@ public void endRow() {
cols = null;
}
}
+
+ /**
+ * @deprecated use {@link #getTableRows()}
+ * @return an ArrayList of the Rows
+ */
+ @Deprecated
+ public ArrayList getRows() {
+ return (ArrayList) rows;
+ }
public List> getTableRows() {
return rows;
diff --git a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/StyleSheet.java b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/StyleSheet.java
index 09e9d6ba70..979ef00eab 100755
--- a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/StyleSheet.java
+++ b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/StyleSheet.java
@@ -60,6 +60,18 @@ public class StyleSheet {
private final Map> classMap = new HashMap<>();
private final Map> tagMap = new HashMap<>();
+ /**
+ * @deprecated please use #applyStyle(String tag, Map<String, String> props) this method will be
+ * removed in 2.0
+ * @param props a HashMap
+ * @param tag the tag
+ */
+ @Deprecated
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public void applyStyle(String tag, HashMap props) {
+ applyStyle(tag, (Map) props);
+ }
+
public void applyStyle(String tag, Map props) {
Map map = tagMap.get(tag.toLowerCase());
if (map != null) {
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/AcroFields.java b/openpdf/src/main/java/com/lowagie/text/pdf/AcroFields.java
index 4e3984e8d7..6be6b7a959 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/AcroFields.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/AcroFields.java
@@ -1827,6 +1827,19 @@ boolean isInAP(PdfDictionary dic, PdfName check) {
return (NDic != null && NDic.get(check) != null);
}
+ /**
+ * Gets all the fields. The fields are keyed by the fully qualified field name and the value is an instance of
+ * AcroFields.Item
.
+ *
+ * @deprecated use {@link AcroFields#getAllFields()}
+ *
+ * @return all the fields
+ */
+ @Deprecated
+ public HashMap getFields() {
+ return (HashMap) fields;
+ }
+
/**
* Gets all the fields. The fields are keyed by the fully qualified field name and the value is an instance of
* AcroFields.Item
.
@@ -2160,37 +2173,49 @@ public void markUsed(AcroFields parentFields, int writeFlags) {
/**
* An array of PdfDictionary
where the value tag /V is present.
*
+ * @deprecated (will remove ' public ' in the future)
*/
- ArrayList values = new ArrayList<>();
+ @Deprecated
+ public ArrayList values = new ArrayList<>();
/**
* An array of PdfDictionary
with the widgets.
*
+ * @deprecated (will remove ' public ' in the future)
*/
- ArrayList widgets = new ArrayList<>();
+ @Deprecated
+ public ArrayList widgets = new ArrayList<>();
/**
* An array of PdfDictionary
with the widget references.
*
+ * @deprecated (will remove ' public ' in the future)
*/
- ArrayList widgetRefs = new ArrayList<>();
+ @Deprecated
+ public ArrayList widgetRefs = new ArrayList<>();
/**
* An array of PdfDictionary
with all the field and widget tags merged.
*
+ * @deprecated (will remove ' public ' in the future)
*/
- ArrayList merged = new ArrayList<>();
+ @Deprecated
+ public ArrayList merged = new ArrayList<>();
/**
* An array of Integer
with the page numbers where the widgets are displayed.
*
+ * @deprecated (will remove ' public ' in the future)
*/
- ArrayList page = new ArrayList<>();
+ @Deprecated
+ public ArrayList page = new ArrayList<>();
/**
* An array of Integer
with the tab order of the field in the page.
*
+ * @deprecated (will remove ' public ' in the future)
*/
- ArrayList tabOrder = new ArrayList<>();
+ @Deprecated
+ public ArrayList tabOrder = new ArrayList<>();
/**
* The indirect reference of the item itself
@@ -2384,6 +2409,19 @@ public boolean isHit(int n) {
}
}
+ /**
+ * Gets the field names that have signatures and are signed.
+ *
+ * @deprecated user {@link AcroFields#getSignedFieldNames()}
+ *
+ * @return the field names that have signatures and are signed
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public ArrayList getSignatureNames() {
+ return (ArrayList) getSignedFieldNames();
+ }
+
/**
* Gets the field names that have signatures and are signed.
*
@@ -2542,6 +2580,19 @@ else if(name.equals(PdfName.UR3)) {
}
return this.sigTypes;
}
+
+ /**
+ * Gets the field names that have blank signatures.
+ *
+ * @deprecated use {@link AcroFields#getFieldNamesWithBlankSignatures()}
+ *
+ * @return the field names that have blank signatures
+ */
+ @Deprecated
+ public ArrayList getBlankSignatureNames() {
+ return (ArrayList) getFieldNamesWithBlankSignatures();
+ }
+
/**
* Gets the field names that have blank signatures.
*
@@ -2796,6 +2847,17 @@ public boolean isAppend() {
return this.append;
}
+ /**
+ * Gets the appearances cache.
+ * @deprecated use {@link AcroFields#getFieldCacheMap()}
+ * @return the appearances cache
+ * @since 2.1.5 this method used to return a HashMap
+ */
+ @Deprecated
+ public Map getFieldCache() {
+ return fieldCache;
+ }
+
/**
* Gets the appearances cache.
*
@@ -2805,6 +2867,38 @@ public Map getFieldCacheMap() {
return fieldCache;
}
+ /**
+ * Sets a cache for field appearances. Parsing the existing PDF to create a new TextField is time expensive. For those tasks that
+ * repeatedly fill the same PDF with different field values the use of the cache has dramatic speed advantages. An example usage:
+ *
+ *
+ * String pdfFile = ...;// the pdf file used as template
+ * ArrayList xfdfFiles = ...;// the xfdf file names
+ * ArrayList pdfOutFiles = ...;// the output file names, one for each element in xpdfFiles
+ * HashMap cache = new HashMap();// the appearances cache
+ * PdfReader originalReader = new PdfReader(pdfFile);
+ * for (int k = 0; k < xfdfFiles.size(); ++k) {
+ * PdfReader reader = new PdfReader(originalReader);
+ * XfdfReader xfdf = new XfdfReader((String)xfdfFiles.get(k));
+ * PdfStamper stp = new PdfStamper(reader, new FileOutputStream((String)pdfOutFiles.get(k)));
+ * AcroFields af = stp.getAcroFields();
+ * af.setFieldCache(cache);
+ * af.setFields(xfdf);
+ * stp.close();
+ * }
+ *
+ *
+ * @deprecated use {@link AcroFields#setFieldCacheMap(Map)}
+ *
+ * @param fieldCache a Map that will carry the cached appearances
+ * @since 2.1.5 this method used to take a HashMap as parameter
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void setFieldCache(Map fieldCache) {
+ this.fieldCache = fieldCache;
+ }
+
/**
* Sets a cache for field appearances. Parsing the existing PDF to create a new TextField is time expensive. For those tasks that
* repeatedly fill the same PDF with different field values the use of the cache has dramatic speed advantages. An example usage:
@@ -2950,6 +3044,18 @@ public int compare(Object[] o1, Object[] o2) {
}
}
+ /**
+ * Gets the list of substitution fonts. The list is composed of BaseFont
and can be null
. The fonts in this list
+ * will be used if the original font doesn't contain the needed glyphs.
+ *
+ * @deprecated use {@link AcroFields#getAllSubstitutionFonts()}
+ * @return the list
+ */
+ @Deprecated
+ public ArrayList getSubstitutionFonts() {
+ return (ArrayList) substitutionFonts;
+ }
+
/**
* Gets the list of substitution fonts. The list is composed of BaseFont
and can be null
. The fonts in this list
* will be used if the original font doesn't contain the needed glyphs.
@@ -2960,6 +3066,19 @@ public List getAllSubstitutionFonts() {
return substitutionFonts;
}
+ /**
+ * Sets a list of substitution fonts. The list is composed of BaseFont
and can also be null
. The fonts in this
+ * list will be used if the original font doesn't contain the needed glyphs.
+ *
+ * @deprecated use {@link AcroFields#setAllSubstitutionFonts(List)}
+ * @param substitutionFonts the list
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void setSubstitutionFonts(ArrayList substitutionFonts) {
+ this.substitutionFonts = substitutionFonts;
+ }
+
/**
* Sets a list of substitution fonts. The list is composed of BaseFont
and can also be null
. The fonts in this
* list will be used if the original font doesn't contain the needed glyphs.
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/BaseField.java b/openpdf/src/main/java/com/lowagie/text/pdf/BaseField.java
index 1d67025a23..dc9a3ad140 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/BaseField.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/BaseField.java
@@ -281,6 +281,16 @@ else if (borderStyle == PdfBorderDictionary.STYLE_INSET) {
return app;
}
+ /**
+ * @param text text
+ * @return an {@link ArrayList} of {@link String}
+ * @deprecated use {@link BaseField#getAllHardBreaks(String)}
+ */
+ @Deprecated
+ protected static ArrayList getHardBreaks(String text) {
+ return (ArrayList) getAllHardBreaks(text);
+ }
+
protected static List getAllHardBreaks(String text) {
List arr = new ArrayList<>();
char[] cs = text.toCharArray();
@@ -316,6 +326,12 @@ protected static void trimRight(StringBuffer buf) {
}
}
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ protected static ArrayList breakLines(ArrayList breaks, BaseFont font, float fontSize, float width) {
+ return (ArrayList) breakLines((List) breaks, font, fontSize, width);
+ }
+
protected static List breakLines(List breaks, BaseFont font, float fontSize, float width) {
List lines = new ArrayList<>();
StringBuffer buf = new StringBuffer();
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/BidiLine.java b/openpdf/src/main/java/com/lowagie/text/pdf/BidiLine.java
index a6b419c82e..0f23b7162b 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/BidiLine.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/BidiLine.java
@@ -206,6 +206,16 @@ public void addChunk(PdfChunk chunk) {
chunks.add(chunk);
}
+ /**
+ * @param chunks an {@link ArrayList} of {@link PdfChunk}
+ * @deprecated use {@link BidiLine#addChunks(List)}, since 1.2.22
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void addChunks(ArrayList chunks) {
+ addChunks((List)chunks);
+ }
+
public void addChunks(List chunks) {
this.chunks.addAll(chunks);
}
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/CMapAwareDocumentFont.java b/openpdf/src/main/java/com/lowagie/text/pdf/CMapAwareDocumentFont.java
index bae199a29d..2fc731f129 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/CMapAwareDocumentFont.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/CMapAwareDocumentFont.java
@@ -305,4 +305,23 @@ public String decode(char c) throws Error {
}
return result;
}
+
+ /**
+ * Encodes bytes to a String.
+ *
+ * @param bytes
+ * the bytes from a stream
+ * @param offset
+ * an offset
+ * @param len
+ * a length
+ * @return a String encoded taking into account if the bytes are in unicode
+ * or not.
+ * @deprecated method name is not indicative of what it does. Use
+ * decode
instead.
+ */
+ @Deprecated
+ public String encode(byte[] bytes, int offset, int len) {
+ return decode(bytes, offset, len);
+ }
}
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/FdfReader.java b/openpdf/src/main/java/com/lowagie/text/pdf/FdfReader.java
index fdad2eb1c2..86ffb648c7 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/FdfReader.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/FdfReader.java
@@ -114,7 +114,7 @@ protected void readPdf() throws IOException {
protected void kidNode(PdfDictionary merged, String name) {
PdfArray kids = merged.getAsArray(PdfName.KIDS);
if (kids == null || kids.isEmpty()) {
- if (!name.isEmpty())
+ if (name.isEmpty())
name = name.substring(1);
fields.put(name, merged);
}
@@ -152,6 +152,17 @@ protected void readFields() {
kidNode(merged, "");
}
+ /** Gets all the fields. The map is keyed by the fully qualified
+ * field name and the value is a merged PdfDictionary
+ * with the field content.
+ * @deprecated use {@link #getAllFields()}
+ * @return all the fields
+ */
+ @Deprecated
+ public HashMap getFields() {
+ return (HashMap) fields;
+ }
+
/** Gets all the fields. The map is keyed by the fully qualified
* field name and the value is a merged PdfDictionary
* with the field content.
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/FieldReader.java b/openpdf/src/main/java/com/lowagie/text/pdf/FieldReader.java
index ab60053e0c..7e906634e6 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/FieldReader.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/FieldReader.java
@@ -1,5 +1,6 @@
package com.lowagie.text.pdf;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -8,6 +9,9 @@
*/
public interface FieldReader {
+ @Deprecated
+ HashMap getFields();
+
Map getAllFields();
String getFieldValue(String fieldKey);
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/MappedRandomAccessFile.java b/openpdf/src/main/java/com/lowagie/text/pdf/MappedRandomAccessFile.java
index e4c4244e84..274349e15c 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/MappedRandomAccessFile.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/MappedRandomAccessFile.java
@@ -66,32 +66,32 @@
* @author Joakim Sandstroem Created on 6.9.2006
*/
public class MappedRandomAccessFile implements AutoCloseable {
-
+
private MappedByteBuffer mappedByteBuffer = null;
private FileChannel channel = null;
-
+
/**
* Constructs a new MappedRandomAccessFile instance
*
* @param filename String
- * @param mode String r, w or rw
+ * @param mode String r, w or rw
* @throws FileNotFoundException on error
- * @throws IOException on error
+ * @throws IOException on error
*/
public MappedRandomAccessFile(String filename, String mode) throws IOException {
-
+
if (mode.equals("rw")) {
init(
- new java.io.RandomAccessFile(filename, mode).getChannel(),
- FileChannel.MapMode.READ_WRITE);
+ new java.io.RandomAccessFile(filename, mode).getChannel(),
+ FileChannel.MapMode.READ_WRITE);
} else {
init(
- new FileInputStream(filename).getChannel(),
- FileChannel.MapMode.READ_ONLY);
+ new FileInputStream(filename).getChannel(),
+ FileChannel.MapMode.READ_ONLY);
}
-
+
}
-
+
/**
* initializes the channel and mapped bytebuffer
*
@@ -100,7 +100,7 @@ public MappedRandomAccessFile(String filename, String mode) throws IOException {
* @throws IOException
*/
private void init(FileChannel channel, FileChannel.MapMode mapMode)
- throws IOException {
+ throws IOException {
if (channel.size() > Integer.MAX_VALUE) {
throw new PdfException("The PDF file is too large. Max 2GB. Size: " + channel.size());
@@ -112,13 +112,13 @@ private void init(FileChannel channel, FileChannel.MapMode mapMode)
}
/**
- * @return FileChannel
+ * @return FileChannel
* @since 2.0.8
*/
public FileChannel getChannel() {
return channel;
}
-
+
/**
* @return int next integer or -1 on EOF
* @see java.io.RandomAccessFile#read()
@@ -126,17 +126,17 @@ public FileChannel getChannel() {
public int read() {
try {
byte b = mappedByteBuffer.get();
-
+
return b & 0xff;
} catch (BufferUnderflowException e) {
return -1; // EOF
}
}
-
+
/**
* @param bytes byte[]
- * @param off int offset
- * @param len int length
+ * @param off int offset
+ * @param len int length
* @return int bytes read or -1 on EOF
* @see java.io.RandomAccessFile#read(byte[], int, int)
*/
@@ -153,7 +153,7 @@ public int read(byte[] bytes, int off, int len) {
mappedByteBuffer.get(bytes, off, len);
return len;
}
-
+
/**
* @return long
* @see java.io.RandomAccessFile#getFilePointer()
@@ -161,7 +161,7 @@ public int read(byte[] bytes, int off, int len) {
public long getFilePointer() {
return mappedByteBuffer.position();
}
-
+
/**
* @param pos long position
* @see java.io.RandomAccessFile#seek(long)
@@ -169,7 +169,7 @@ public long getFilePointer() {
public void seek(long pos) {
mappedByteBuffer.position((int) pos);
}
-
+
/**
* @return long length
* @see java.io.RandomAccessFile#length()
@@ -177,13 +177,14 @@ public void seek(long pos) {
public long length() {
return mappedByteBuffer.limit();
}
-
+
/**
* Cleans the mapped bytebuffer and closes the channel
*
* @throws IOException on error
* @see java.io.RandomAccessFile#close()
*/
+ @Override
public void close() throws IOException {
clean(mappedByteBuffer);
mappedByteBuffer = null;
@@ -192,17 +193,18 @@ public void close() throws IOException {
}
channel = null;
}
-
+
/**
* invokes the close method
*
* @see java.lang.Object#finalize()
*/
+ @Override
protected void finalize() throws Throwable {
close();
super.finalize();
}
-
+
/**
* invokes the clean method on the ByteBuffer's cleaner
@@ -217,7 +219,6 @@ public static boolean clean(final java.nio.ByteBuffer buffer) {
if (cleanJava9(buffer)) {
return true;
-
}
return cleanOldsJDK(buffer);
}
@@ -245,20 +246,20 @@ private static boolean cleanOldsJDK(final java.nio.ByteBuffer buffer) {
private static boolean cleanJava9(final java.nio.ByteBuffer buffer) {
return AccessController.doPrivileged((PrivilegedAction) () -> {
- Boolean success = Boolean.FALSE;
- try {
+ Boolean success = Boolean.FALSE;
+ try {
final Class> unsafeClass = Class.forName("sun.misc.Unsafe");
final Field theUnsafeField = unsafeClass.getDeclaredField("theUnsafe");
theUnsafeField.setAccessible(true);
final Object theUnsafe = theUnsafeField.get(null);
final Method invokeCleanerMethod = unsafeClass
.getMethod("invokeCleaner", ByteBuffer.class);
- invokeCleanerMethod.invoke(theUnsafe, buffer);
- success = Boolean.TRUE;
+ invokeCleanerMethod.invoke(theUnsafe, buffer);
+ success = Boolean.TRUE;
} catch (Exception ignore) {
- // Ignore
- }
- return success;
+ // Ignore
+ }
+ return success;
});
}
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfAcroForm.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfAcroForm.java
index 4b48eae498..74f43a59ef 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfAcroForm.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfAcroForm.java
@@ -88,6 +88,16 @@ public void setNeedAppearances(boolean value) {
put(PdfName.NEEDAPPEARANCES, new PdfBoolean(value));
}
+ /**
+ * Adds fieldTemplates.
+ * @param ft field templates
+ * @deprecated use {@link #addFieldTemplates(Map)}
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void addFieldTemplates(HashMap ft) {
+ fieldTemplates.putAll(ft);
+ }
/**
* Adds fieldTemplates.
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfArray.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfArray.java
index 9818220054..03d8e5f706 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfArray.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfArray.java
@@ -254,6 +254,17 @@ public PdfObject remove(int idx) {
*/
public boolean remove(PdfObject object) {
return this.arrayList.remove(object);
+ }
+
+ /**
+ * Get a copy the internal list for this PdfArray.
+ *
+ * @deprecated Please use getElements() instead.
+ * @return a copy of the the internal List.
+ */
+ @Deprecated
+ public List getArrayList() {
+ return getElements();
}
/**
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfCopyFields.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfCopyFields.java
index 49661b1255..84dc10545c 100755
--- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfCopyFields.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfCopyFields.java
@@ -158,6 +158,7 @@ public void setEncryption(boolean strength, String userPassword, String ownerPas
/**
* Closes the output document.
*/
+ @Override
public void close() {
fc.close();
}
@@ -215,6 +216,7 @@ public void setFullCompression() {
/**
* @see com.lowagie.text.pdf.interfaces.PdfEncryptionSettings#setEncryption(byte[], byte[], int, int)
*/
+ @Override
public void setEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionType) throws DocumentException {
fc.setEncryption(userPassword, ownerPassword, permissions, encryptionType);
}
@@ -222,6 +224,7 @@ public void setEncryption(byte[] userPassword, byte[] ownerPassword, int permiss
/**
* @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#addViewerPreference(com.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfObject)
*/
+ @Override
public void addViewerPreference(PdfName key, PdfObject value) {
fc.addViewerPreference(key, value);
}
@@ -229,6 +232,7 @@ public void addViewerPreference(PdfName key, PdfObject value) {
/**
* @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#setViewerPreferences(int)
*/
+ @Override
public void setViewerPreferences(int preferences) {
fc.setViewerPreferences(preferences);
}
@@ -236,6 +240,7 @@ public void setViewerPreferences(int preferences) {
/**
* @see com.lowagie.text.pdf.interfaces.PdfEncryptionSettings#setEncryption(java.security.cert.Certificate[], int[], int)
*/
+ @Override
public void setEncryption(Certificate[] certs, int[] permissions, int encryptionType) throws DocumentException {
fc.setEncryption(certs, permissions, encryptionType);
}
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfCopyFieldsImp.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfCopyFieldsImp.java
index 7947781c57..0ccbafa1d7 100755
--- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfCopyFieldsImp.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfCopyFieldsImp.java
@@ -263,6 +263,15 @@ private void adjustTabOrder(PdfArray annots, PdfIndirectReference ind, PdfNumber
}
}
+ /**
+ * @deprecated use {@link PdfCopyFieldsImp#branchForm(Map, PdfIndirectReference, String)}
+ */
+ @Deprecated
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ protected PdfArray branchForm(HashMap level, PdfIndirectReference parent, String fname) throws IOException {
+ return branchForm((Map) level, parent, fname);
+ }
+
protected PdfArray branchForm(Map level, PdfIndirectReference parent, String fname) throws IOException {
PdfArray arr = new PdfArray();
for (Map.Entry entry : level.entrySet()) {
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfFormField.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfFormField.java
index 3fa1b92780..a49352ee4e 100755
--- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfFormField.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfFormField.java
@@ -248,6 +248,15 @@ public void addKid(PdfFormField field) {
kids = new ArrayList<>();
kids.add(field);
}
+
+ /**
+ * @deprecated use {@link #getKidFields()}
+ * @return an ArrayList of the kids
+ */
+ @Deprecated
+ public ArrayList getKids() {
+ return (ArrayList) kids;
+ }
public List getKidFields() {
return kids;
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfName.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfName.java
index 1100faba24..f9ec5328dc 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfName.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfName.java
@@ -1870,7 +1870,7 @@ public class PdfName extends PdfObject implements Comparable {
* image dictionary
* Type 1 form dictionary
* group attributes dictionary
- * content group dictionary
+ * content group dictionary>
* content membership dictionary
* Type 1 font dictionary
* Type 3 font dictionary
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfPKCS7.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfPKCS7.java
index 8ec38d0857..7b8717d280 100755
--- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfPKCS7.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfPKCS7.java
@@ -1691,6 +1691,8 @@ public static class X509Name {
/**
* A HashMap with default symbols
*/
+ @Deprecated
+ public static HashMap DefaultSymbols = new HashMap();
public static Map defaultSymbols = new HashMap<>();
static {
@@ -1710,11 +1712,14 @@ public static class X509Name {
defaultSymbols.put(INITIALS, "INITIALS");
defaultSymbols.put(GENERATION, "GENERATION");
+ DefaultSymbols.putAll(defaultSymbols);
}
/**
* A HashMap with values
*/
+ @Deprecated
+ public HashMap values = new HashMap();
public Map> valuesMap = new HashMap<>();
/**
@@ -1771,6 +1776,18 @@ public String getField(String name) {
return vs == null ? null : vs.get(0);
}
+ /**
+ * gets a field array from the values Hashmap
+ *
+ * @param name the name of the field to get
+ * @deprecated use {@link #getFieldsByName(String)}
+ * @return an ArrayList
+ */
+ @Deprecated
+ public ArrayList getFieldArray(String name) {
+ return (ArrayList) valuesMap.get(name);
+ }
+
/**
* gets a field array from the values Hashmap
*
@@ -1781,6 +1798,17 @@ public List getFieldsByName(String name) {
return valuesMap.get(name);
}
+ /**
+ * getter for values
+ *
+ * @deprecated use {@link #getAllFields()}
+ * @return a HashMap with the fields of the X509 name
+ */
+ @Deprecated
+ public HashMap getFields() {
+ return (HashMap) valuesMap;
+ }
+
/**
* getter for values
*
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfStamper.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfStamper.java
index 77123e919a..273a8fcb8d 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfStamper.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfStamper.java
@@ -131,6 +131,17 @@ public PdfStamper(PdfReader reader, OutputStream os, char pdfVersion, boolean ap
stamper = new PdfStamperImp(reader, os, pdfVersion, append);
}
+ /** Gets the optional String
map to add or change values in
+ * the info dictionary.
+ * @deprecated use {@link #getInfoDictionary()}
+ * @return the map or null
+ *
+ */
+ @Deprecated
+ public HashMap getMoreInfo() {
+ return (HashMap) this.moreInfo;
+ }
+
/** Gets the optional String
map to add or change values in
* the info dictionary.
* @return the map or null
@@ -139,6 +150,18 @@ public PdfStamper(PdfReader reader, OutputStream os, char pdfVersion, boolean ap
public Map getInfoDictionary() {
return moreInfo;
}
+
+ /** An optional String
map to add or change values in
+ * the info dictionary. Entries with null
+ * values delete the key in the original info dictionary
+ * @param moreInfo additional entries to the info dictionary
+ * @deprecated use {@link #setInfoDictionary(Map)}
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void setMoreInfo(HashMap moreInfo) {
+ this.moreInfo = moreInfo;
+ }
/**
* An option to make this stamper to clean metadata in the generated file. You must call this method before closing the stamper.
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfWriter.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfWriter.java
index 011bd9140f..e146c96239 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfWriter.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfWriter.java
@@ -113,10 +113,10 @@ public class PdfWriter extends DocWriter implements
/**
* The highest generation number possible.
*
- * @since iText 2.1.6
+ * @since iText 2.1.6
*/
public static final int GENERATION_MAX = 65535;
-
+
// INNER CLASSES
/**
@@ -126,9 +126,9 @@ public class PdfWriter extends DocWriter implements
* (page 55-60). It contains the body of a PDF document (section 5.14) and it can also generate a Cross-reference
* Table (section 5.15).
*
- * @see PdfWriter
- * @see PdfObject
- * @see PdfIndirectObject
+ * @see PdfWriter
+ * @see PdfObject
+ * @see PdfIndirectObject
*/
public static class PdfBody {
@@ -136,14 +136,14 @@ public static class PdfBody {
// membervariables
- /**
+ /**
* array containing the cross-reference table of the normal objects.
- */
+ */
private final TreeSet xrefs;
- private int refnum;
- /**
+ private int refnum;
+ /**
* the current byte position in the body.
- */
+ */
private long position;
private final PdfWriter writer;
private ByteBuffer index;
@@ -217,8 +217,8 @@ private void flushObjStm() throws IOException {
* PdfObject
. It also adds a PdfCrossReference
for this object to an
* ArrayList
that will be used to build the Cross-reference Table.
*
- * @param object a PdfObject
- * @return a PdfIndirectObject
+ * @param object a PdfObject
+ * @return a PdfIndirectObject
* @throws IOException
*/
PdfIndirectObject add(PdfObject object) throws IOException {
@@ -252,9 +252,9 @@ int getIndirectReferenceNumber() {
* It also adds a PdfCrossReference
for this object to an ArrayList
that will be used
* to build the Cross-reference Table.
*
- * @param object a PdfObject
- * @param ref a PdfIndirectReference
- * @return a PdfIndirectObject
+ * @param object a PdfObject
+ * @param ref a PdfIndirectReference
+ * @return a PdfIndirectObject
* @throws IOException
*/
PdfIndirectObject add(PdfObject object, PdfIndirectReference ref) throws IOException {
@@ -294,7 +294,7 @@ PdfIndirectObject add(PdfObject object, int refNumber, boolean inObjStm) throws
/**
* Returns the offset of the Cross-Reference table.
*
- * @return an offset
+ * @return an offset
*/
long offset() {
return position;
@@ -303,7 +303,7 @@ long offset() {
/**
* Returns the total number of objects contained in the CrossReferenceTable of this Body
.
*
- * @return a number of objects
+ * @return a number of objects
*/
int size() {
return Math.max((xrefs.last()).getRefnum() + 1, refnum);
@@ -434,9 +434,9 @@ public PdfCrossReference(int refnum, long offset, int generation) {
this.offset = offset;
this.refnum = refnum;
this.generation = generation;
- }
+ }
- /**
+ /**
* Constructs a cross-reference element for a PdfIndirectObject.
*
* @param refnum the reference number
@@ -506,10 +506,10 @@ public int compareTo(final PdfCrossReference reference) {
*/
@Override
public boolean equals(Object obj) {
- if (!(obj instanceof PdfCrossReference other)) {
+ if (!(obj instanceof PdfCrossReference)) {
return false;
}
-
+ final PdfCrossReference other = (PdfCrossReference)obj;
return refnum == other.refnum;
}
@@ -534,9 +534,9 @@ static class PdfTrailer extends PdfDictionary {
/**
* Constructs a PDF-Trailer.
*
- * @param size the number of entries in the PdfCrossReferenceTable
- * @param root an indirect reference to the root of the PDF document
- * @param info an indirect reference to the info object of the PDF document
+ * @param size the number of entries in the PdfCrossReferenceTable
+ * @param root an indirect reference to the root of the PDF document
+ * @param info an indirect reference to the info object of the PDF document
* @param encryption
* @param fileID
* @param prevxref
@@ -557,7 +557,7 @@ static class PdfTrailer extends PdfDictionary {
}
if (prevxref > 0) {
put(PdfName.PREV, new PdfNumber(prevxref));
- }
+ }
}
/**
@@ -591,8 +591,8 @@ protected PdfWriter() {
* Remark: a PdfWriter can only be constructed by calling the method
* getInstance(Document document, OutputStream os)
.
*
- * @param document The PdfDocument
that has to be written
- * @param os The OutputStream
the writer has to write to.
+ * @param document The PdfDocument
that has to be written
+ * @param os The OutputStream
the writer has to write to.
*/
protected PdfWriter(PdfDocument document, OutputStream os) {
@@ -605,14 +605,14 @@ protected PdfWriter(PdfDocument document, OutputStream os) {
/**
* Use this method to get an instance of the PdfWriter
.
*
- * @param document The Document
that has to be written
- * @param os The OutputStream
the writer has to write to.
- * @return a new PdfWriter
- * @throws DocumentException on error
+ * @param document The Document
that has to be written
+ * @param os The OutputStream
the writer has to write to.
+ * @return a new PdfWriter
+ * @throws DocumentException on error
*/
public static PdfWriter getInstance(Document document, OutputStream os)
- throws DocumentException {
+ throws DocumentException {
PdfDocument pdf = new PdfDocument();
pdf.setTextRenderingOptions(document.getTextRenderingOptions());
document.addDocListener(pdf);
@@ -625,14 +625,14 @@ public static PdfWriter getInstance(Document document, OutputStream os)
* Use this method to get an instance of the PdfWriter
.
*
* @param document The Document
that has to be written
- * @param os The OutputStream
the writer has to write to.
+ * @param os The OutputStream
the writer has to write to.
* @param listener A DocListener
to pass to the PdfDocument.
* @return a new PdfWriter
* @throws DocumentException on error
*/
public static PdfWriter getInstance(Document document, OutputStream os, DocListener listener)
- throws DocumentException {
+ throws DocumentException {
PdfDocument pdf = new PdfDocument();
pdf.setTextRenderingOptions(document.getTextRenderingOptions());
pdf.addDocListener(listener);
@@ -683,9 +683,9 @@ public float getVerticalPosition(boolean ensureNewLine) {
/**
* Sets the initial leading for the PDF document. This has to be done before the document is opened.
*
- * @param leading the initial leading
+ * @param leading the initial leading
* @throws DocumentException if you try setting the leading after the document was opened.
- * @since 2.1.6
+ * @since 2.1.6
*/
public void setInitialLeading(float leading) throws DocumentException {
if (open) {
@@ -694,17 +694,17 @@ public void setInitialLeading(float leading) throws DocumentException {
}
pdf.setLeading(leading);
}
-
+
// the PdfDirectContentByte instances
- /*
- * You should see Direct Content as a canvas on which you can draw
- * graphics and text. One canvas goes on top of the page (getDirectContent),
- * the other goes underneath (getDirectContentUnder).
- * You can always the same object throughout your document,
- * even if you have moved to a new page. Whatever you add on
- * the canvas will be displayed on top or under the current page.
- */
+/*
+ * You should see Direct Content as a canvas on which you can draw
+ * graphics and text. One canvas goes on top of the page (getDirectContent),
+ * the other goes underneath (getDirectContentUnder).
+ * You can always the same object throughout your document,
+ * even if you have moved to a new page. Whatever you add on
+ * the canvas will be displayed on top or under the current page.
+ */
/**
* The direct content in this document.
@@ -754,13 +754,13 @@ void resetContent() {
// PDF body
- /*
- * A PDF file has 4 parts: a header, a body, a cross-reference table, and a trailer.
- * The body contains all the PDF objects that make up the PDF document.
- * Each element gets a reference (a set of numbers) and the byte position of
- * every object is stored in the cross-reference table.
- * Use these methods only if you know what you're doing.
- */
+/*
+ * A PDF file has 4 parts: a header, a body, a cross-reference table, and a trailer.
+ * The body contains all the PDF objects that make up the PDF document.
+ * Each element gets a reference (a set of numbers) and the byte position of
+ * every object is stored in the cross-reference table.
+ * Use these methods only if you know what you're doing.
+ */
/**
* body of the PDF document
@@ -787,9 +787,9 @@ void addLocalDestinations(TreeMap dest) throws IOException {
addToBody(new PdfString("invalid_" + name), (PdfIndirectReference) obj[1]);
} else {
addToBody(destination, (PdfIndirectReference) obj[1]);
- }
}
}
+ }
/**
* Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!
@@ -805,7 +805,7 @@ public PdfIndirectObject addToBody(PdfObject object) throws IOException {
/**
* Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!
*
- * @param object the PDF object to add
+ * @param object the PDF object to add
* @param inObjStm a boolean
* @return a PdfIndirectObject
* @throws IOException thrown when an I/O operation fails
@@ -818,7 +818,7 @@ public PdfIndirectObject addToBody(PdfObject object, boolean inObjStm) throws IO
* Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!
*
* @param object the object to add
- * @param ref the IndirectReference of that object
+ * @param ref the IndirectReference of that object
* @return a PdfIndirectObject
* @throws IOException thrown when an I/O operation fails
*/
@@ -829,8 +829,8 @@ public PdfIndirectObject addToBody(PdfObject object, PdfIndirectReference ref) t
/**
* Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!
*
- * @param object the object to add
- * @param ref the indirect reference
+ * @param object the object to add
+ * @param ref the indirect reference
* @param inObjStm a boolean
* @return a PdfIndirectObject
* @throws IOException thrown when an I/O operation fails
@@ -843,7 +843,7 @@ public PdfIndirectObject addToBody(PdfObject object, PdfIndirectReference ref, b
/**
* Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!
*
- * @param object the object to add
+ * @param object the object to add
* @param refNumber the reference number
* @return a PdfIndirectObject
* @throws IOException thrown when an I/O operation fails
@@ -855,9 +855,9 @@ public PdfIndirectObject addToBody(PdfObject object, int refNumber) throws IOExc
/**
* Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!
*
- * @param object the object to add
+ * @param object the object to add
* @param refNumber the reference number
- * @param inObjStm a boolean
+ * @param inObjStm a boolean
* @return a PdfIndirectObject
* @throws IOException thrown when an I/O operation fails
*/
@@ -891,13 +891,13 @@ OutputStreamCounter getOs() {
// PDF Catalog
- /*
- * The Catalog is also called the root object of the document.
- * Whereas the Cross-Reference maps the objects number with the
- * byte offset so that the viewer can find the objects, the
- * Catalog tells the viewer the numbers of the objects needed
- * to render the document.
- */
+/*
+ * The Catalog is also called the root object of the document.
+ * Whereas the Cross-Reference maps the objects number with the
+ * byte offset so that the viewer can find the objects, the
+ * Catalog tells the viewer the numbers of the objects needed
+ * to render the document.
+ */
protected PdfDictionary getCatalog(PdfIndirectReference rootObj) {
PdfDictionary catalog = pdf.getCatalog(rootObj);
@@ -943,12 +943,12 @@ public PdfDictionary getExtraCatalog() {
// PdfPages
- /*
- * The page root keeps the complete page tree of the document.
- * There's an entry in the Catalog that refers to the root
- * of the page tree, the page tree contains the references
- * to pages and other page trees.
- */
+/*
+ * The page root keeps the complete page tree of the document.
+ * There's an entry in the Catalog that refers to the root
+ * of the page tree, the page tree contains the references
+ * to pages and other page trees.
+ */
/**
* The root of the page tree.
@@ -965,7 +965,7 @@ public PdfDictionary getExtraCatalog() {
/**
* The value of the Tabs entry in the page dictionary.
*
- * @since 2.1.5
+ * @since 2.1.5
*/
protected PdfName tabs = null;
@@ -973,7 +973,7 @@ public PdfDictionary getExtraCatalog() {
* Use this method to make sure the page tree has a linear structure (every leave is attached directly to the root).
* Use this method to allow page reordering with method reorderPages.
*/
- public void setLinearPageMode() {
+ public void setLinearPageMode() {
root.setLinearMode(null);
}
@@ -1045,7 +1045,7 @@ public int getCurrentPageNumber() {
*
* @param tabs Can be PdfName.R, PdfName.C or PdfName.S. Since the Adobe Extensions Level 3, it can also be
* PdfName.A or PdfName.W
- * @since 2.1.5
+ * @since 2.1.5
*/
public void setTabs(PdfName tabs) {
this.tabs = tabs;
@@ -1055,7 +1055,7 @@ public void setTabs(PdfName tabs) {
* Returns the value to be used for the Tabs entry in the page tree.
*
* @return a PdfName of the value of the Tabs entry in the page dictionnary
- * @since 2.1.5
+ * @since 2.1.5
*/
public PdfName getTabs() {
return tabs;
@@ -1066,7 +1066,7 @@ public PdfName getTabs() {
*
* The document has to be open before you can begin to add content to the body of the document.
*
- * @param page the PdfPage
to add
+ * @param page the PdfPage
to add
* @param contents the PdfContents
of the page
* @return a PdfIndirectReference
* @throws PdfException on error
@@ -1101,12 +1101,12 @@ PdfIndirectReference add(PdfPage page, PdfContents contents) throws PdfException
// page events
- /*
- * Page events are specific for iText, not for PDF.
- * Upon specific events (for instance when a page starts
- * or ends), the corresponding method in the page event
- * implementation that is added to the writer is invoked.
- */
+/*
+ * Page events are specific for iText, not for PDF.
+ * Upon specific events (for instance when a page starts
+ * or ends), the corresponding method in the page event
+ * implementation that is added to the writer is invoked.
+ */
/**
* The PdfPageEvent
for this document.
@@ -1167,10 +1167,10 @@ public void open() {
body = new PdfBody(this);
if (pdfxConformance.isPdfX32002()) {
PdfDictionary sec = new PdfDictionary();
- sec.put(PdfName.GAMMA, new PdfArray(new float[]{2.2f, 2.2f, 2.2f}));
+ sec.put(PdfName.GAMMA, new PdfArray(new float[]{2.2f,2.2f,2.2f}));
sec.put(PdfName.MATRIX, new PdfArray(
new float[]{0.4124f, 0.2126f, 0.0193f, 0.3576f, 0.7152f, 0.1192f, 0.1805f, 0.0722f, 0.9505f}));
- sec.put(PdfName.WHITEPOINT, new PdfArray(new float[]{0.9505f, 1f, 1.089f}));
+ sec.put(PdfName.WHITEPOINT, new PdfArray(new float[]{0.9505f,1f,1.089f}));
PdfArray arr = new PdfArray(PdfName.CALRGB);
arr.add(sec);
setDefaultColorspace(PdfName.DEFAULTRGB, addToBody(arr).getIndirectReference());
@@ -1197,14 +1197,14 @@ public void close() {
.getComposedMessage("you.should.call.document.close.instead"));
}
if ((currentPageNumber - 1) != pageReferences.size())
- // 2019-04-26: If you get this error, it could be that you are using OpenPDF or
- // another library such as flying-saucer's ITextRenderer in a non-threadsafe way.
- // ITextRenderer is not thread safe. So if you get this problem here, create a new
- // instance, rather than re-using it.
- // See: https://github.com/LibrePDF/OpenPDF/issues/164
+ // 2019-04-26: If you get this error, it could be that you are using OpenPDF or
+ // another library such as flying-saucer's ITextRenderer in a non-threadsafe way.
+ // ITextRenderer is not thread safe. So if you get this problem here, create a new
+ // instance, rather than re-using it.
+ // See: https://github.com/LibrePDF/OpenPDF/issues/164
{
throw new RuntimeException("The page " + pageReferences.size() +
- " was requested but the document has only " + (currentPageNumber - 1) + " pages.");
+ " was requested but the document has only " + (currentPageNumber - 1) + " pages.");
}
try {
@@ -1260,7 +1260,7 @@ public void close() {
// write the cross-reference table of the body
body.writeCrossReferenceTable(os, indirectCatalog.getIndirectReference(),
- infoObj.getIndirectReference(), encryption, fileID, prevxref);
+ infoObj.getIndirectReference(), encryption, fileID, prevxref);
os.write(getISOBytes("startxref\n"));
os.write(getISOBytes(String.valueOf(body.offset())));
@@ -1319,7 +1319,8 @@ protected void addSharedObjectsToBody() throws IOException {
for (Map.Entry entry : documentProperties.entrySet()) {
Object prop = entry.getKey();
PdfObject[] obj = entry.getValue();
- if (prop instanceof PdfLayerMembership layer) {
+ if (prop instanceof PdfLayerMembership) {
+ PdfLayerMembership layer = (PdfLayerMembership) prop;
addToBody(layer.getPdfObject(), layer.getRef());
} else if ((prop instanceof PdfDictionary) && !(prop instanceof PdfLayer)) {
addToBody((PdfDictionary) prop, (PdfIndirectReference) obj[1]);
@@ -1335,17 +1336,17 @@ protected void addSharedObjectsToBody() throws IOException {
// [C1] Outlines (bookmarks)
- /**
+ /**
* Use this method to get the root outline and construct bookmarks.
*
- * @return the root outline
- */
+ * @return the root outline
+ */
- public PdfOutline getRootOutline() {
- return directContent.getRootOutline();
- }
+ public PdfOutline getRootOutline() {
+ return directContent.getRootOutline();
+ }
- protected List newBookmarks;
+ protected List newBookmarks;
/**
* Sets the bookmarks. The list structure is defined in {@link SimpleBookmark}.
@@ -1363,8 +1364,8 @@ protected void writeOutlines(PdfDictionary catalog, boolean namedAsNames) throws
PdfDictionary top = new PdfDictionary();
PdfIndirectReference topRef = getPdfIndirectReference();
Object[] kids = SimpleBookmark.iterateOutlines(this, topRef, newBookmarks, namedAsNames);
- top.put(PdfName.FIRST, (PdfIndirectReference) kids[0]);
- top.put(PdfName.LAST, (PdfIndirectReference) kids[1]);
+ top.put(PdfName.FIRST, (PdfIndirectReference)kids[0]);
+ top.put(PdfName.LAST, (PdfIndirectReference)kids[1]);
top.put(PdfName.COUNT, new PdfNumber((Integer) kids[2]));
addToBody(top, topRef);
catalog.put(PdfName.OUTLINES, topRef);
@@ -1374,52 +1375,52 @@ protected void writeOutlines(PdfDictionary catalog, boolean namedAsNames) throws
/**
* possible PDF version (header)
*/
- public static final char VERSION_1_2 = '2';
+ public static final char VERSION_1_2 = '2';
/**
* possible PDF version (header)
*/
- public static final char VERSION_1_3 = '3';
+ public static final char VERSION_1_3 = '3';
/**
* possible PDF version (header)
*/
- public static final char VERSION_1_4 = '4';
+ public static final char VERSION_1_4 = '4';
/**
* possible PDF version (header)
*/
- public static final char VERSION_1_5 = '5';
+ public static final char VERSION_1_5 = '5';
/**
* possible PDF version (header)
*/
- public static final char VERSION_1_6 = '6';
+ public static final char VERSION_1_6 = '6';
/**
* possible PDF version (header)
*/
- public static final char VERSION_1_7 = '7';
+ public static final char VERSION_1_7 = '7';
/**
* possible PDF version (catalog)
*/
- public static final PdfName PDF_VERSION_1_2 = new PdfName("1.2");
+ public static final PdfName PDF_VERSION_1_2 = new PdfName("1.2");
/**
* possible PDF version (catalog)
*/
- public static final PdfName PDF_VERSION_1_3 = new PdfName("1.3");
+ public static final PdfName PDF_VERSION_1_3 = new PdfName("1.3");
/**
* possible PDF version (catalog)
*/
- public static final PdfName PDF_VERSION_1_4 = new PdfName("1.4");
+ public static final PdfName PDF_VERSION_1_4 = new PdfName("1.4");
/**
* possible PDF version (catalog)
*/
- public static final PdfName PDF_VERSION_1_5 = new PdfName("1.5");
+ public static final PdfName PDF_VERSION_1_5 = new PdfName("1.5");
/**
* possible PDF version (catalog)
*/
- public static final PdfName PDF_VERSION_1_6 = new PdfName("1.6");
+ public static final PdfName PDF_VERSION_1_6 = new PdfName("1.6");
/**
* possible PDF version (catalog)
*/
- public static final PdfName PDF_VERSION_1_7 = new PdfName("1.7");
+ public static final PdfName PDF_VERSION_1_7 = new PdfName("1.7");
/**
* Stores the version information for the header and the catalog.
@@ -1429,6 +1430,7 @@ protected void writeOutlines(PdfDictionary catalog, boolean namedAsNames) throws
/**
* @see com.lowagie.text.pdf.interfaces.PdfVersion#setPdfVersion(char)
*/
+ @Override
public void setPdfVersion(char version) {
pdf_version.setPdfVersion(version);
}
@@ -1436,6 +1438,7 @@ public void setPdfVersion(char version) {
/**
* @see com.lowagie.text.pdf.interfaces.PdfVersion#setAtLeastPdfVersion(char)
*/
+ @Override
public void setAtLeastPdfVersion(char version) {
pdf_version.setAtLeastPdfVersion(version);
}
@@ -1443,18 +1446,20 @@ public void setAtLeastPdfVersion(char version) {
/**
* @see com.lowagie.text.pdf.interfaces.PdfVersion#setPdfVersion(com.lowagie.text.pdf.PdfName)
*/
+ @Override
public void setPdfVersion(PdfName version) {
pdf_version.setPdfVersion(version);
}
/**
* @see com.lowagie.text.pdf.interfaces.PdfVersion#addDeveloperExtension(com.lowagie.text.pdf.PdfDeveloperExtension)
- * @since 2.1.6
+ * @since 2.1.6
*/
+ @Override
public void addDeveloperExtension(PdfDeveloperExtension de) {
pdf_version.addDeveloperExtension(de);
}
-
+
/**
* Returns the version information.
*/
@@ -1579,6 +1584,7 @@ PdfVersionImp getPdfVersion() {
/**
* @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#setViewerPreferences(int)
*/
+ @Override
public void setViewerPreferences(int preferences) {
pdf.setViewerPreferences(preferences);
}
@@ -1587,6 +1593,7 @@ public void setViewerPreferences(int preferences) {
* @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#addViewerPreference(com.lowagie.text.pdf.PdfName,
* com.lowagie.text.pdf.PdfObject)
*/
+ @Override
public void addViewerPreference(PdfName key, PdfObject value) {
pdf.addViewerPreference(key, value);
}
@@ -1611,8 +1618,8 @@ public void setPageLabels(PdfPageLabels pageLabels) {
* @param map a map with strings as keys for the names, and structured strings as values for the
* destinations
* @param page_offset number of pages that has to be added to the page numbers in the destinations (useful if you
- * use this method in combination with PdfCopy).
- * @since iText 5.0
+ * use this method in combination with PdfCopy).
+ * @since iText 5.0
*/
public void addNamedDestinations(Map map, int page_offset) {
Map.Entry entry;
@@ -1627,175 +1634,178 @@ public void addNamedDestinations(Map map, int page_offset) {
addNamedDestination(entry.getKey(), page + page_offset, destination);
}
}
-
+
/**
* Adds one named destination.
*
- * @param name the name for the destination
- * @param page the page number where you want to jump to
- * @param dest an explicit destination
- * @since iText 5.0
+ * @param name the name for the destination
+ * @param page the page number where you want to jump to
+ * @param dest an explicit destination
+ * @since iText 5.0
*/
public void addNamedDestination(String name, int page, PdfDestination dest) {
dest.addPage(getPageReference(page));
pdf.localDestination(name, dest);
}
-
- /**
+
+ /**
* Use this method to add a JavaScript action at the document level. When the document opens, all this JavaScript
* runs.
*
- * @param js The JavaScript action
- */
- public void addJavaScript(PdfAction js) {
- pdf.addJavaScript(js);
- }
+ * @param js The JavaScript action
+ */
+ public void addJavaScript(PdfAction js) {
+ pdf.addJavaScript(js);
+ }
- /**
+ /**
* Use this method to add a JavaScript action at the document level. When the document opens, all this JavaScript
* runs.
*
- * @param code the JavaScript code
+ * @param code the JavaScript code
* @param unicode select JavaScript unicode. Note that the internal Acrobat JavaScript engine does not support
* unicode, so this may or may not work for you
- */
- public void addJavaScript(String code, boolean unicode) {
- addJavaScript(PdfAction.javaScript(code, this, unicode));
- }
+ */
+ public void addJavaScript(String code, boolean unicode) {
+ addJavaScript(PdfAction.javaScript(code, this, unicode));
+ }
- /**
+ /**
* Use this method to adds a JavaScript action at the document level. When the document opens, all this JavaScript
* runs.
*
- * @param code the JavaScript code
- */
- public void addJavaScript(String code) {
- addJavaScript(code, false);
- }
+ * @param code the JavaScript code
+ */
+ public void addJavaScript(String code) {
+ addJavaScript(code, false);
+ }
- /**
+ /**
* Use this method to add a JavaScript action at the document level. When the document opens, all this JavaScript
* runs.
*
- * @param name The name of the JS Action in the name tree
- * @param js The JavaScript action
- */
- public void addJavaScript(String name, PdfAction js) {
- pdf.addJavaScript(name, js);
- }
+ * @param name The name of the JS Action in the name tree
+ * @param js The JavaScript action
+ */
+ public void addJavaScript(String name, PdfAction js) {
+ pdf.addJavaScript(name, js);
+ }
- /**
+ /**
* Use this method to add a JavaScript action at the document level. When the document opens, all this JavaScript
* runs.
*
- * @param name The name of the JS Action in the name tree
- * @param code the JavaScript code
+ * @param name The name of the JS Action in the name tree
+ * @param code the JavaScript code
* @param unicode select JavaScript unicode. Note that the internal Acrobat JavaScript engine does not support
* unicode, so this may or may not work for you
- */
- public void addJavaScript(String name, String code, boolean unicode) {
- addJavaScript(name, PdfAction.javaScript(code, this, unicode));
- }
+ */
+ public void addJavaScript(String name, String code, boolean unicode) {
+ addJavaScript(name, PdfAction.javaScript(code, this, unicode));
+ }
- /**
+ /**
* Use this method to adds a JavaScript action at the document level. When the document opens, all this JavaScript
* runs.
*
- * @param name The name of the JS Action in the name tree
- * @param code the JavaScript code
- */
- public void addJavaScript(String name, String code) {
- addJavaScript(name, code, false);
- }
+ * @param name The name of the JS Action in the name tree
+ * @param code the JavaScript code
+ */
+ public void addJavaScript(String name, String code) {
+ addJavaScript(name, code, false);
+ }
- /**
- * Use this method to add a file attachment at the document level.
+ /**
+ * Use this method to add a file attachment at the document level.
*
- * @param description the file description
+ * @param description the file description
* @param fileStore an array with the file. If it's null
the file will be read from the disk
- * @param file the path to the file. It will only be used if
- * fileStore
is not null
- * @param fileDisplay the actual file name stored in the pdf
- * @throws IOException on error
- */
+ * @param file the path to the file. It will only be used if
+ * fileStore
is not null
+ * @param fileDisplay the actual file name stored in the pdf
+ * @throws IOException on error
+ */
public void addFileAttachment(String description, byte[] fileStore, String file, String fileDisplay)
throws IOException {
- addFileAttachment(description, PdfFileSpecification.fileEmbedded(this, file, fileDisplay, fileStore));
- }
-
- /**
- * Use this method to add a file attachment at the document level.
- *
- * @param description the file description
- * @param fs the file specification
- * @throws IOException thrown when an I/O operation fails
- */
- public void addFileAttachment(String description, PdfFileSpecification fs) throws IOException {
- pdf.addFileAttachment(description, fs);
- }
-
- /**
- * Use this method to add a file attachment at the document level.
- *
- * @param fs the file specification
- * @throws IOException thrown when an I/O operation fails
- */
- public void addFileAttachment(PdfFileSpecification fs) throws IOException {
- addFileAttachment(null, fs);
- }
+ addFileAttachment(description, PdfFileSpecification.fileEmbedded(this, file, fileDisplay, fileStore));
+ }
+
+ /**
+ * Use this method to add a file attachment at the document level.
+ *
+ * @param description the file description
+ * @param fs the file specification
+ * @throws IOException thrown when an I/O operation fails
+ */
+ public void addFileAttachment(String description, PdfFileSpecification fs) throws IOException {
+ pdf.addFileAttachment(description, fs);
+ }
+
+ /**
+ * Use this method to add a file attachment at the document level.
+ *
+ * @param fs the file specification
+ * @throws IOException thrown when an I/O operation fails
+ */
+ public void addFileAttachment(PdfFileSpecification fs) throws IOException {
+ addFileAttachment(null, fs);
+ }
// [C6] Actions (open and additional)
/**
* action value
*/
- public static final PdfName DOCUMENT_CLOSE = PdfName.WC;
+ public static final PdfName DOCUMENT_CLOSE = PdfName.WC;
/**
* action value
*/
- public static final PdfName WILL_SAVE = PdfName.WS;
+ public static final PdfName WILL_SAVE = PdfName.WS;
/**
* action value
*/
- public static final PdfName DID_SAVE = PdfName.DS;
+ public static final PdfName DID_SAVE = PdfName.DS;
/**
* action value
*/
- public static final PdfName WILL_PRINT = PdfName.WP;
+ public static final PdfName WILL_PRINT = PdfName.WP;
/**
* action value
*/
- public static final PdfName DID_PRINT = PdfName.DP;
+ public static final PdfName DID_PRINT = PdfName.DP;
/**
* @see com.lowagie.text.pdf.interfaces.PdfDocumentActions#setOpenAction(java.lang.String)
*/
+ @Override
public void setOpenAction(String name) {
- pdf.setOpenAction(name);
- }
+ pdf.setOpenAction(name);
+ }
/**
* @see com.lowagie.text.pdf.interfaces.PdfDocumentActions#setOpenAction(com.lowagie.text.pdf.PdfAction)
*/
+ @Override
public void setOpenAction(PdfAction action) {
- pdf.setOpenAction(action);
- }
+ pdf.setOpenAction(action);
+ }
/**
* @see com.lowagie.text.pdf.interfaces.PdfDocumentActions#setAdditionalAction(com.lowagie.text.pdf.PdfName,
* com.lowagie.text.pdf.PdfAction)
*/
+ @Override
public void setAdditionalAction(PdfName actionType, PdfAction action) throws DocumentException {
- if (!(actionType.equals(DOCUMENT_CLOSE) ||
- actionType.equals(WILL_SAVE) ||
- actionType.equals(DID_SAVE) ||
- actionType.equals(WILL_PRINT) ||
- actionType.equals(DID_PRINT))) {
+ if (!(actionType.equals(DOCUMENT_CLOSE) ||
+ actionType.equals(WILL_SAVE) ||
+ actionType.equals(DID_SAVE) ||
+ actionType.equals(WILL_PRINT) ||
+ actionType.equals(DID_PRINT))) {
throw new DocumentException(
MessageLocalization.getComposedMessage("invalid.additional.action.type.1", actionType.toString()));
- }
- pdf.addAdditionalAction(actionType, action);
- }
+ }
+ pdf.addAdditionalAction(actionType, action);
+ }
// [C7] portable collections
@@ -1823,6 +1833,7 @@ public void setCollection(PdfCollection collection) {
/**
* @see com.lowagie.text.pdf.interfaces.PdfAnnotations#getAcroForm()
*/
+ @Override
public PdfAcroForm getAcroForm() {
return pdf.getAcroForm();
}
@@ -1830,6 +1841,7 @@ public PdfAcroForm getAcroForm() {
/**
* @see com.lowagie.text.pdf.interfaces.PdfAnnotations#addAnnotation(com.lowagie.text.pdf.PdfAnnotation)
*/
+ @Override
public void addAnnotation(PdfAnnotation annot) {
pdf.addAnnotation(annot);
}
@@ -1841,6 +1853,7 @@ void addAnnotation(PdfAnnotation annot, int page) {
/**
* @see com.lowagie.text.pdf.interfaces.PdfAnnotations#addCalculationOrder(com.lowagie.text.pdf.PdfFormField)
*/
+ @Override
public void addCalculationOrder(PdfFormField annot) {
pdf.addCalculationOrder(annot);
}
@@ -1848,6 +1861,7 @@ public void addCalculationOrder(PdfFormField annot) {
/**
* @see com.lowagie.text.pdf.interfaces.PdfAnnotations#setSigFlags(int)
*/
+ @Override
public void setSigFlags(int f) {
pdf.setSigFlags(f);
}
@@ -1928,6 +1942,7 @@ private byte[] createXmpMetadataBytes() {
/**
* @see com.lowagie.text.pdf.interfaces.PdfXConformance#setPDFXConformance(int)
*/
+ @Override
public void setPDFXConformance(int pdfx) {
if (pdfxConformance.getPDFXConformance() == pdfx) {
return;
@@ -1952,6 +1967,7 @@ public void setPDFXConformance(int pdfx) {
/**
* @see com.lowagie.text.pdf.interfaces.PdfXConformance#getPDFXConformance()
*/
+ @Override
public int getPDFXConformance() {
return pdfxConformance.getPDFXConformance();
}
@@ -1959,6 +1975,7 @@ public int getPDFXConformance() {
/**
* @see com.lowagie.text.pdf.interfaces.PdfXConformance#isPdfX()
*/
+ @Override
public boolean isPdfX() {
return pdfxConformance.isPdfX();
}
@@ -2010,7 +2027,7 @@ public void setOutputIntents(String outputConditionIdentifier, String outputCond
extraCatalog.put(PdfName.OUTPUTINTENTS, new PdfArray(out));
}
- /**
+ /**
* Sets the values of the output intent dictionary. Null values are allowed to suppress any key.
*
* Prefer the ICC_Profile
-based version of this method.
@@ -2033,9 +2050,9 @@ public void setOutputIntents(String outputConditionIdentifier, String outputCond
/**
* Use this method to copy the output intent dictionary from another document to this one.
*
- * @param reader the other document
+ * @param reader the other document
* @param checkExistence true
to just check for the existence of a valid output intent
- * dictionary, false
to insert the dictionary if it exists
+ * dictionary, false
to insert the dictionary if it exists
* @return true
if the output intent dictionary exists, false
* otherwise
* @throws IOException on error
@@ -2057,7 +2074,7 @@ public boolean setOutputIntents(PdfReader reader, boolean checkExistence) throws
if (checkExistence) {
return true;
}
- PRStream stream = (PRStream) PdfReader.getPdfObject(out.get(PdfName.DESTOUTPUTPROFILE));
+ PRStream stream = (PRStream)PdfReader.getPdfObject(out.get(PdfName.DESTOUTPUTPROFILE));
byte[] destProfile = null;
if (stream != null) {
destProfile = PdfReader.getStreamBytes(stream);
@@ -2073,7 +2090,7 @@ private static String getNameString(PdfDictionary dic, PdfName key) {
if (obj == null || !obj.isString()) {
return null;
}
- return ((PdfString) obj).toUnicodeString();
+ return ((PdfString)obj).toUnicodeString();
}
// PDF Objects that have an impact on the PDF body
@@ -2177,10 +2194,40 @@ private static String getNameString(PdfDictionary dic, PdfName key) {
*/
public static final int ALLOW_DEGRADED_PRINTING = 4;
-
- /**
- * Contains the business logic for cryptography.
- */
+ /** @deprecated As of iText 2.0.7, use {@link #ALLOW_PRINTING} instead. Scheduled for removal at or after 2.2.0 */
+ @Deprecated
+ public static final int AllowPrinting = ALLOW_PRINTING;
+ /** @deprecated As of iText 2.0.7, use {@link #ALLOW_MODIFY_CONTENTS} instead. Scheduled for removal at or after 2.2.0 */
+ @Deprecated
+ public static final int AllowModifyContents = ALLOW_MODIFY_CONTENTS;
+ /** @deprecated As of iText 2.0.7, use {@link #ALLOW_COPY} instead. Scheduled for removal at or after 2.2.0 */
+ @Deprecated
+ public static final int AllowCopy = ALLOW_COPY;
+ /** @deprecated As of iText 2.0.7, use {@link #ALLOW_MODIFY_ANNOTATIONS} instead. Scheduled for removal at or after 2.2.0 */
+ @Deprecated
+ public static final int AllowModifyAnnotations = ALLOW_MODIFY_ANNOTATIONS;
+ /** @deprecated As of iText 2.0.7, use {@link #ALLOW_FILL_IN} instead. Scheduled for removal at or after 2.2.0 */
+ @Deprecated
+ public static final int AllowFillIn = ALLOW_FILL_IN;
+ /** @deprecated As of iText 2.0.7, use {@link #ALLOW_SCREENREADERS} instead. Scheduled for removal at or after 2.2.0 */
+ @Deprecated
+ public static final int AllowScreenReaders = ALLOW_SCREENREADERS;
+ /** @deprecated As of iText 2.0.7, use {@link #ALLOW_ASSEMBLY} instead. Scheduled for removal at or after 2.2.0 */
+ @Deprecated
+ public static final int AllowAssembly = ALLOW_ASSEMBLY;
+ /** @deprecated As of iText 2.0.7, use {@link #ALLOW_DEGRADED_PRINTING} instead. Scheduled for removal at or after 2.2.0 */
+ @Deprecated
+ public static final int AllowDegradedPrinting = ALLOW_DEGRADED_PRINTING;
+
+ // Strength of the encryption (kept for historical reasons)
+ /** @deprecated As of iText 2.0.7, use {@link #STANDARD_ENCRYPTION_40} instead. Scheduled for removal at or after 2.2.0 */
+ @Deprecated
+ public static final boolean STRENGTH40BITS = false;
+ /** @deprecated As of iText 2.0.7, use {@link #STANDARD_ENCRYPTION_128} instead. Scheduled for removal at or after 2.2.0 */
+ @Deprecated
+ public static final boolean STRENGTH128BITS = true;
+
+ /** Contains the business logic for cryptography. */
protected PdfEncryption crypto;
PdfEncryption getEncryption() {
@@ -2190,6 +2237,7 @@ PdfEncryption getEncryption() {
/**
* @see com.lowagie.text.pdf.interfaces.PdfEncryptionSettings#setEncryption(byte[], byte[], int, int)
*/
+ @Override
public void setEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionType)
throws DocumentException {
if (pdf.isOpen()) {
@@ -2205,6 +2253,7 @@ public void setEncryption(byte[] userPassword, byte[] ownerPassword, int permiss
* @see com.lowagie.text.pdf.interfaces.PdfEncryptionSettings#setEncryption(java.security.cert.Certificate[], int[],
* int)
*/
+ @Override
public void setEncryption(Certificate[] certs, int[] permissions, int encryptionType) throws DocumentException {
if (pdf.isOpen()) {
throw new DocumentException(
@@ -2212,7 +2261,7 @@ public void setEncryption(Certificate[] certs, int[] permissions, int encryption
}
crypto = new PdfEncryption();
if (certs != null) {
- for (int i = 0; i < certs.length; i++) {
+ for (int i=0; i < certs.length; i++) {
crypto.addRecipient(certs[i], permissions[i]);
}
}
@@ -2220,8 +2269,65 @@ public void setEncryption(Certificate[] certs, int[] permissions, int encryption
crypto.getEncryptionDictionary();
}
-// [F2] compression
+ /**
+ * Sets the encryption options for this document. The userPassword and the
+ * ownerPassword can be null or have zero length. In this case the ownerPassword
+ * is replaced by a random string. The open permissions for the document can be
+ * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
+ * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
+ * The permissions can be combined by ORing them.
+ * @param userPassword the user password. Can be null or empty
+ * @param ownerPassword the owner password. Can be null or empty
+ * @param permissions the user permissions
+ * @param strength128Bits true
for 128 bit key length, false
for 40 bit key length
+ * @throws DocumentException if the document is already open
+ * @deprecated As of iText 2.0.3, replaced by (@link #setEncryption(byte[], byte[], int, int)}. Scheduled for removal at or after 2.2.0
+ */
+ @Deprecated
+ public void setEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits) throws DocumentException {
+ setEncryption(userPassword, ownerPassword, permissions, strength128Bits ? STANDARD_ENCRYPTION_128 : STANDARD_ENCRYPTION_40);
+ }
+
+ /**
+ * Sets the encryption options for this document. The userPassword and the
+ * ownerPassword can be null or have zero length. In this case the ownerPassword
+ * is replaced by a random string. The open permissions for the document can be
+ * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
+ * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
+ * The permissions can be combined by ORing them.
+ * @param strength true
for 128 bit key length, false
for 40 bit key length
+ * @param userPassword the user password. Can be null or empty
+ * @param ownerPassword the owner password. Can be null or empty
+ * @param permissions the user permissions
+ * @throws DocumentException if the document is already open
+ * @deprecated As of iText 2.0.3, replaced by (@link #setEncryption(byte[], byte[], int, int)}. Scheduled for removal at or after 2.2.0
+ */
+ @Deprecated
+ public void setEncryption(boolean strength, String userPassword, String ownerPassword, int permissions) throws DocumentException {
+ setEncryption(getISOBytes(userPassword), getISOBytes(ownerPassword), permissions, strength ? STANDARD_ENCRYPTION_128 : STANDARD_ENCRYPTION_40);
+ }
+
+ /**
+ * Sets the encryption options for this document. The userPassword and the
+ * ownerPassword can be null or have zero length. In this case the ownerPassword
+ * is replaced by a random string. The open permissions for the document can be
+ * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
+ * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
+ * The permissions can be combined by ORing them.
+ * @param encryptionType the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128.
+ * Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext
+ * @param userPassword the user password. Can be null or empty
+ * @param ownerPassword the owner password. Can be null or empty
+ * @param permissions the user permissions
+ * @throws DocumentException if the document is already open
+ * @deprecated As of iText 2.0.3, replaced by (@link #setEncryption(byte[], byte[], int, int)}. Scheduled for removal at or after 2.2.0
+ */
+ @Deprecated
+ public void setEncryption(int encryptionType, String userPassword, String ownerPassword, int permissions) throws DocumentException {
+ setEncryption(getISOBytes(userPassword), getISOBytes(ownerPassword), permissions, encryptionType);
+ }
+ // [F2] compression
/**
* Holds value of property fullCompression.
*/
@@ -2275,7 +2381,7 @@ public void setCompressionLevel(int compressionLevel) {
this.compressionLevel = PdfStream.DEFAULT_COMPRESSION;
} else {
this.compressionLevel = compressionLevel;
- }
+ }
}
// [F3] adding fonts
@@ -2300,7 +2406,7 @@ public void setCompressionLevel(int compressionLevel) {
FontDetails addSimple(BaseFont bf) {
if (bf.getFontType() == BaseFont.FONT_TYPE_DOCUMENT) {
- return new FontDetails(new PdfName("F" + (fontNumber++)), ((DocumentFont) bf).getIndirectReference(), bf);
+ return new FontDetails(new PdfName("F" + (fontNumber++)), ((DocumentFont)bf).getIndirectReference(), bf);
}
FontDetails ret = documentFonts.get(bf);
if (ret == null) {
@@ -2315,9 +2421,9 @@ void eliminateFontSubset(PdfDictionary fonts) {
for (FontDetails ft : documentFonts.values()) {
if (fonts.get(ft.getFontName()) != null) {
ft.setSubset(false);
- }
}
}
+ }
// [F4] adding (and releasing) form XObjects
@@ -2334,7 +2440,7 @@ void eliminateFontSubset(PdfDictionary fonts) {
/**
* Adds a template to the document but not to the page resources.
*
- * @param template the template to add
+ * @param template the template to add
* @param forcedName the template name, rather than a generated one. Can be null
* @return the PdfName
for this template
*/
@@ -2353,7 +2459,7 @@ PdfName addDirectTemplateSimple(PdfTemplate template, PdfName forcedName) {
}
if (template.getType() == PdfTemplate.TYPE_IMPORTED) {
// If we got here from PdfCopy we'll have to fill importedPages
- PdfImportedPage ip = (PdfImportedPage) template;
+ PdfImportedPage ip = (PdfImportedPage)template;
PdfReader r = ip.getPdfReaderInstance().getReader();
if (!importedPages.containsKey(r)) {
importedPages.put(r, ip.getPdfReaderInstance());
@@ -2362,8 +2468,8 @@ PdfName addDirectTemplateSimple(PdfTemplate template, PdfName forcedName) {
}
formXObjects.put(ref, new Object[]{name, template});
} else {
- name = (PdfName) obj[0];
- }
+ name = (PdfName)obj[0];
+ }
} catch (Exception e) {
throw new ExceptionConverter(e);
}
@@ -2383,7 +2489,7 @@ public void releaseTemplate(PdfTemplate tp) throws IOException {
if (objs == null || objs[1] == null) {
return;
}
- PdfTemplate template = (PdfTemplate) objs[1];
+ PdfTemplate template = (PdfTemplate)objs[1];
if (template.getIndirectReference() instanceof PRIndirectReference) {
return;
}
@@ -2401,7 +2507,7 @@ public void releaseTemplate(PdfTemplate tp) throws IOException {
* Use this method to get a page from other PDF document. The page can be used as any other PdfTemplate. Note that
* calling this method more than once with the same parameters will retrieve the same object.
*
- * @param reader the PDF document where the page is
+ * @param reader the PDF document where the page is
* @param pageNumber the page number. The first page is 1
* @return the template representing the imported page
*/
@@ -2439,7 +2545,7 @@ public void freeReader(PdfReader reader) throws IOException {
* @return the approximate size without fonts or templates
*/
public long getCurrentDocumentSize() {
- return body.offset() + (long) body.size() * 20L + 0x48;
+ return body.offset() + (long)body.size() * 20L + 0x48;
}
protected PdfReaderInstance currentPdfReaderInstance;
@@ -2505,7 +2611,7 @@ ColorDetails addSimple(PdfSpotColor spc) {
PdfName addSimplePattern(PdfPatternPainter painter) {
PdfName name = documentPatterns.get(painter);
try {
- if (name == null) {
+ if ( name == null ) {
name = new PdfName("P" + patternNumber);
++patternNumber;
documentPatterns.put(painter, name);
@@ -2628,7 +2734,7 @@ public PdfStructureTreeRoot getStructureTreeRoot() {
/**
* The locked array in an OCG dictionary
*
- * @since 2.1.2
+ * @since 2.1.2
*/
protected PdfArray OCGLocked = new PdfArray();
@@ -2656,7 +2762,7 @@ public void addOCGRadioGroup(List group) {
for (PdfLayer layer : group) {
if (layer.getTitle() == null) {
ar.add(layer.getRef());
- }
+ }
}
if (ar.isEmpty()) {
return;
@@ -2669,8 +2775,8 @@ public void addOCGRadioGroup(List group) {
* interface of a viewer application. Producers can use this entry to prevent the visibility of content that depends
* on these groups from being changed by users.
*
- * @param layer the layer that needs to be added to the array of locked OCGs
- * @since 2.1.2
+ * @param layer the layer that needs to be added to the array of locked OCGs
+ * @since 2.1.2
*/
public void lockLayer(PdfLayer layer) {
OCGLocked.add(layer.getRef());
@@ -2696,7 +2802,7 @@ private static void getOCGOrder(PdfArray order, PdfLayer layer) {
}
if (!kids.isEmpty()) {
order.add(kids);
- }
+ }
}
private void addASEvent(PdfName event, PdfName category) {
@@ -2706,13 +2812,13 @@ private void addASEvent(PdfName event, PdfName category) {
PdfDictionary usage = layer.getAsDict(PdfName.USAGE);
if (usage != null && usage.get(category) != null) {
arr.add(layer.getRef());
- }
+ }
}
if (arr.isEmpty()) {
return;
}
- PdfDictionary d = (PdfDictionary) OCProperties.get(PdfName.D);
- PdfArray arras = (PdfArray) d.get(PdfName.AS);
+ PdfDictionary d = (PdfDictionary)OCProperties.get(PdfName.D);
+ PdfArray arras = (PdfArray)d.get(PdfName.AS);
if (arras == null) {
arras = new PdfArray();
d.put(PdfName.AS, arras);
@@ -2749,8 +2855,8 @@ protected void fillOCProperties(boolean erase) {
}
List docOrder = documentOCGorder.stream()
- .filter(pdfOCG -> ((PdfLayer) pdfOCG).getParent() == null)
- .collect(Collectors.toList());
+ .filter(pdfOCG -> ((PdfLayer)pdfOCG).getParent() == null)
+ .collect(Collectors.toList());
PdfArray order = new PdfArray();
for (PdfOCG o1 : docOrder) {
@@ -2765,7 +2871,7 @@ protected void fillOCProperties(boolean erase) {
PdfLayer layer = (PdfLayer) o;
if (!layer.isOn()) {
gr.add(layer.getRef());
- }
+ }
}
if (!gr.isEmpty()) {
d.put(PdfName.OFF, gr);
@@ -2785,7 +2891,8 @@ protected void fillOCProperties(boolean erase) {
void registerLayer(PdfOCG layer) {
PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_LAYER, null);
- if (layer instanceof PdfLayer la) {
+ if (layer instanceof PdfLayer) {
+ PdfLayer la = (PdfLayer)layer;
if (la.getTitle() == null) {
if (!documentOCG.contains(layer)) {
documentOCG.add(layer);
@@ -2826,7 +2933,7 @@ public void setCropBoxSize(Rectangle crop) {
* Use this method to set the page box sizes. Allowed names are: "crop", "trim", "art" and "bleed".
*
* @param boxName the box size
- * @param size the size
+ * @param size the size
*/
public void setBoxSize(String boxName, Rectangle size) {
pdf.setBoxSize(boxName, size);
@@ -2882,28 +2989,31 @@ public boolean isPageEmpty() {
* @see com.lowagie.text.pdf.interfaces.PdfPageActions#setPageAction(com.lowagie.text.pdf.PdfName,
* com.lowagie.text.pdf.PdfAction)
*/
+ @Override
public void setPageAction(PdfName actionType, PdfAction action) throws DocumentException {
if (!actionType.equals(PAGE_OPEN) && !actionType.equals(PAGE_CLOSE)) {
throw new DocumentException(
MessageLocalization.getComposedMessage("invalid.page.additional.action.type.1",
actionType.toString()));
}
- pdf.setPageAction(actionType, action);
- }
+ pdf.setPageAction(actionType, action);
+ }
/**
* @see com.lowagie.text.pdf.interfaces.PdfPageActions#setDuration(int)
*/
+ @Override
public void setDuration(int seconds) {
- pdf.setDuration(seconds);
- }
+ pdf.setDuration(seconds);
+ }
/**
* @see com.lowagie.text.pdf.interfaces.PdfPageActions#setTransition(com.lowagie.text.pdf.PdfTransition)
*/
+ @Override
public void setTransition(PdfTransition transition) {
- pdf.setTransition(transition);
- }
+ pdf.setTransition(transition);
+ }
// [U4] Thumbnail image
@@ -2911,7 +3021,7 @@ public void setTransition(PdfTransition transition) {
* Use this method to set the thumbnail image for the current page.
*
* @param image the image
- * @throws PdfException on error
+ * @throws PdfException on error
* @throws DocumentException or error
*/
public void setThumbnail(Image image) throws DocumentException {
@@ -3009,6 +3119,7 @@ public void setSpaceCharRatio(float spaceCharRatio) {
*
* @param runDirection the run direction
*/
+ @Override
public void setRunDirection(int runDirection) {
if (runDirection < RUN_DIRECTION_NO_BIDI || runDirection > RUN_DIRECTION_RTL) {
throw new RuntimeException(MessageLocalization.getComposedMessage("invalid.run.direction.1", runDirection));
@@ -3021,13 +3132,14 @@ public void setRunDirection(int runDirection) {
*
* @return the run direction
*/
+ @Override
public int getRunDirection() {
return runDirection;
}
// [U8] user units
- protected float userunit = 0f;
+ protected float userunit = 0f;
/**
* Use this method to get the user unit. A user unit is a value that defines the default user space unit. The
@@ -3048,14 +3160,14 @@ public float getUserunit() {
* @param userunit The userunit to set.
* @throws DocumentException on error
*/
- public void setUserunit(float userunit) throws DocumentException {
+ public void setUserunit(float userunit) throws DocumentException {
if (userunit < 1f || userunit > 75000f) {
throw new DocumentException(
MessageLocalization.getComposedMessage("userunit.should.be.a.value.between.1.and.75000"));
}
- this.userunit = userunit;
- setAtLeastPdfVersion(VERSION_1_6);
- }
+ this.userunit = userunit;
+ setAtLeastPdfVersion(VERSION_1_6);
+ }
// Miscellaneous topics
@@ -3080,7 +3192,7 @@ public PdfDictionary getDefaultColorspace() {
*
* @param key the name of the colorspace. It can be PdfName.DEFAULTGRAY
,
* PdfName.DEFAULTRGB
or PdfName.DEFAULTCMYK
- * @param cs the colorspace. A null
or PdfNull
removes any colorspace with the same name
+ * @param cs the colorspace. A null
or PdfNull
removes any colorspace with the same name
*/
public void setDefaultColorspace(PdfName key, PdfObject cs) {
if (cs == null || cs.isNull()) {
@@ -3132,7 +3244,7 @@ ColorDetails addSimplePatternColorspace(Color color) {
}
return patternColorspaceGRAY;
case ExtendedColor.TYPE_SEPARATION: {
- ColorDetails details = addSimple(((SpotColor) color).getPdfSpotColor());
+ ColorDetails details = addSimple(((SpotColor)color).getPdfSpotColor());
ColorDetails patternDetails = documentSpotPatterns.get(details);
if (patternDetails == null) {
patternDetails = new ColorDetails(getColorspaceName(), body.getPdfIndirectReference(), null);
@@ -3196,7 +3308,7 @@ public void clearTextWrap() throws DocumentException {
*
* @param image the Image
to add
* @return the name of the image added
- * @throws PdfException on error
+ * @throws PdfException on error
* @throws DocumentException on error
*/
public PdfName addDirectImageSimple(Image image) throws DocumentException {
@@ -3207,11 +3319,11 @@ public PdfName addDirectImageSimple(Image image) throws DocumentException {
* Adds an image to the document but not to the page resources. It is used with templates and
* Document.add(Image)
. Use this method only if you know what you're doing!
*
- * @param image the Image
to add
+ * @param image the Image
to add
* @param fixedRef the reference to used. It may be null
, a PdfIndirectReference
or a
* PRIndirectReference
.
* @return the name of the image added
- * @throws PdfException on error
+ * @throws PdfException on error
* @throws DocumentException on error
*/
public PdfName addDirectImageSimple(Image image, PdfIndirectReference fixedRef) throws DocumentException {
@@ -3224,9 +3336,9 @@ public PdfName addDirectImageSimple(Image image, PdfIndirectReference fixedRef)
else {
if (image.isImgTemplate()) {
name = new PdfName("img" + images.size());
- if (image instanceof ImgWMF) {
+ if(image instanceof ImgWMF){
try {
- ImgWMF wmf = (ImgWMF) image;
+ ImgWMF wmf = (ImgWMF)image;
wmf.readWMF(PdfTemplate.createTemplate(this, 0, 0));
} catch (Exception e) {
throw new DocumentException(e);
@@ -3267,10 +3379,10 @@ public PdfName addDirectImageSimple(Image image, PdfIndirectReference fixedRef)
colorspace.set(1, iccArray);
} else {
i.put(PdfName.COLORSPACE, iccArray);
- }
+ }
} else {
i.put(PdfName.COLORSPACE, iccArray);
- }
+ }
}
add(i, fixedRef);
name = i.name();
@@ -3289,18 +3401,18 @@ public PdfName addDirectImageSimple(Image image, PdfIndirectReference fixedRef)
*/
PdfIndirectReference add(PdfImage pdfImage, PdfIndirectReference fixedRef) throws PdfException {
- if (!imageDictionary.contains(pdfImage.name())) {
+ if (! imageDictionary.contains(pdfImage.name())) {
PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_IMAGE, pdfImage);
- if (fixedRef instanceof PRIndirectReference r2) {
- fixedRef = new PdfIndirectReference(0,
- getNewObjectNumber(r2.getReader(), r2.getNumber(), r2.getGeneration()));
+ if (fixedRef instanceof PRIndirectReference) {
+ PRIndirectReference r2 = (PRIndirectReference)fixedRef;
+ fixedRef = new PdfIndirectReference(0, getNewObjectNumber(r2.getReader(), r2.getNumber(), r2.getGeneration()));
}
try {
if (fixedRef == null) {
fixedRef = addToBody(pdfImage).getIndirectReference();
} else {
addToBody(pdfImage, fixedRef);
- }
+ }
} catch (IOException ioe) {
throw new ExceptionConverter(ioe);
}
@@ -3342,9 +3454,9 @@ protected PdfIndirectReference add(PdfICCBased icc) {
* Gets an indirect reference to a JBIG2 Globals stream. Adds the stream if it hasn't already been added to the
* writer.
*
- * @param content a byte array that may already been added to the writer inside a stream object.
+ * @param content a byte array that may already been added to the writer inside a stream object.
* @return the PdfIndirectReference
- * @since 2.1.5
+ * @since 2.1.5
*/
protected PdfIndirectReference getReferenceJBIG2Globals(byte[] content) {
if (content == null) {
@@ -3373,9 +3485,9 @@ protected PdfIndirectReference getReferenceJBIG2Globals(byte[] content) {
/**
* Checks if a Table
fits the current page of the PdfDocument
.
*
- * @param table the table that has to be checked
- * @param margin a certain margin
- * @return true
if the Table
fits the page, false
otherwise.
+ * @param table the table that has to be checked
+ * @param margin a certain margin
+ * @return true
if the Table
fits the page, false
otherwise.
*/
public boolean fitsPage(Table table, float margin) {
@@ -3385,8 +3497,8 @@ public boolean fitsPage(Table table, float margin) {
/**
* Checks if a Table
fits the current page of the PdfDocument
.
*
- * @param table the table that has to be checked
- * @return true
if the Table
fits the page, false
otherwise.
+ * @param table the table that has to be checked
+ * @return true
if the Table
fits the page, false
otherwise.
*/
public boolean fitsPage(Table table) {
@@ -3440,7 +3552,7 @@ public boolean isRgbTransparencyBlending() {
*
* @param rgbTransparencyBlending true
to set the transparency blending colorspace to RGB,
* false
- * to use the default blending colorspace
+ * to use the default blending colorspace
* @since 2.1.0
*/
public void setRgbTransparencyBlending(boolean rgbTransparencyBlending) {
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/RadioCheckField.java b/openpdf/src/main/java/com/lowagie/text/pdf/RadioCheckField.java
index 6eeb294a24..de868b0d11 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/RadioCheckField.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/RadioCheckField.java
@@ -431,6 +431,33 @@ public PdfFormField getRadioGroup(boolean noToggleToOff, boolean radiosInUnison)
return field;
}
+ /**
+ * Gets the radio field. It's only composed of the widget keys and must be used
+ * with {@link #getRadioGroup(boolean,boolean)}.
+ * @return the radio field
+ * @throws IOException on error
+ * @throws DocumentException on error
+ *
+ * @deprecated use {@link #getKidField()} instead
+ */
+ @Deprecated
+ public PdfFormField getRadioField() throws IOException, DocumentException {
+ return getField(true);
+ }
+
+ /**
+ * Gets the check field.
+ * @return the check field
+ * @throws IOException on error
+ * @throws DocumentException on error
+ *
+ * @deprecated use {@link #getFullField()} instead
+ */
+ @Deprecated
+ public PdfFormField getCheckField() throws IOException, DocumentException {
+ return getField(false);
+ }
+
/**
* Gets a parent of a checkbox autofill parent.
* It is composed of the field specific keys, without the widget ones.
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/SimpleBookmark.java b/openpdf/src/main/java/com/lowagie/text/pdf/SimpleBookmark.java
index db1a6f748a..fcf25d6ac6 100755
--- a/openpdf/src/main/java/com/lowagie/text/pdf/SimpleBookmark.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/SimpleBookmark.java
@@ -275,6 +275,20 @@ private static int getNumber(PdfIndirectReference indirect)
}
return indirect.getNumber();
}
+
+ /**
+ * Gets a List
with the bookmarks. It returns null
if
+ * the document doesn't have any bookmarks.
+ * @param reader the document
+ * @deprecated use {@link #getBookmarkList(PdfReader)}
+ * @return a List
with the bookmarks or null
if the
+ * document doesn't have any
+ */
+ @Deprecated
+ @SuppressWarnings("rawtypes")
+ public static List getBookmark(PdfReader reader) {
+ return getBookmarkList(reader);
+ }
/**
* Gets a List
with the bookmarks. It returns null
if
@@ -354,6 +368,23 @@ public static void eliminatePages(List> list, int[] pageRang
}
}
}
+
+ /**
+ * For the pages in range add the pageShift
to the page number.
+ * The page ranges
+ * consists of a number of pairs with the start/end page range. The page numbers
+ * are inclusive.
+ * @param list the bookmarks
+ * @param pageShift the number to add to the pages in range
+ * @param pageRange the page ranges, always in pairs. It can be null
+ * to include all the pages
+ * @deprecated use {@link #shiftPageNumbersInRange(List, int, int[])}
+ */
+ @Deprecated
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public static void shiftPageNumbers(List list, int pageShift, int[] pageRange) {
+ shiftPageNumbersInRange(list, pageShift, pageRange);
+ }
/**
* For the pages in range add the pageShift
to the page number.
@@ -750,6 +781,15 @@ public void endElement(String tag) {
public void startDocument() {
}
+ /**
+ * @deprecated user {@link SimpleBookmark#startElement(String, Map)}
+ */
+ @Deprecated
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public void startElement(String tag, HashMap h) {
+ startElement(tag, (Map) h);
+ }
+
public void startElement(String tag, Map h) {
if (topList == null) {
if (tag.equals("Bookmark")) {
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/SimpleNamedDestination.java b/openpdf/src/main/java/com/lowagie/text/pdf/SimpleNamedDestination.java
index 2078731dfa..476453a819 100755
--- a/openpdf/src/main/java/com/lowagie/text/pdf/SimpleNamedDestination.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/SimpleNamedDestination.java
@@ -309,6 +309,12 @@ public void endElement(String tag) {
public void startDocument() {
}
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void startElement(String tag, HashMap h) {
+ startElement(tag, (Map) h);
+ }
+
public void startElement(String tag, Map h) {
if (xmlNames == null) {
if (tag.equals("Destination")) {
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/TextField.java b/openpdf/src/main/java/com/lowagie/text/pdf/TextField.java
index 08c8c42673..d4d8429c2b 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/TextField.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/TextField.java
@@ -96,7 +96,7 @@ public TextField(PdfWriter writer, Rectangle box, String fieldName) {
}
private static boolean checkRTL(String text) {
- if (text == null || text.isEmpty())
+ if (text == null || text.length() == 0)
return false;
char[] cc = text.toCharArray();
for (int c : cc) {
@@ -784,6 +784,18 @@ public void addChoiceSelection( int selection) {
}
}
+ /**
+ * replaces the existing selections with the param. If this field isn't a MULTISELECT
+ * list, all but the first element will be removed.
+ * @param selections new selections. If null, it clear()s the underlying ArrayList.
+ * @deprecated use {@link #setChoiceSelections(List)}
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void setChoiceSelections(ArrayList selections ) {
+ setChoiceSelections((List) selections);
+ }
+
/**
* replaces the existing selections with the param. If this field isn't a MULTISELECT
* list, all but the first element will be removed.
@@ -823,6 +835,17 @@ public void setExtraMargin(float extraMarginLeft, float extraMarginTop) {
*/
private List substitutionFonts;
+ /**
+ * Gets the list of substitution fonts. The list is composed of BaseFont
and can be null
. The fonts in this list will be used if the original
+ * font doesn't contain the needed glyphs.
+ * @deprecated use {@link #getSubstitutionFontList()}
+ * @return the list
+ */
+ @Deprecated
+ public ArrayList getSubstitutionFonts() {
+ return (ArrayList) this.substitutionFonts;
+ }
+
/**
* Gets the list of substitution fonts. The list is composed of BaseFont
and can be null
. The fonts in this list will be used if the original
* font doesn't contain the needed glyphs.
@@ -832,6 +855,17 @@ public List getSubstitutionFontList() {
return this.substitutionFonts;
}
+ /**
+ * Sets a list of substitution fonts. The list is composed of BaseFont
and can also be null
. The fonts in this list will be used if the original
+ * font doesn't contain the needed glyphs.
+ * @param substitutionFonts the list
+ * @deprecated use {@link #setSubstitutionFontList(List)}
+ */
+ @Deprecated
+ public void setSubstitutionFonts(List substitutionFonts) {
+ this.substitutionFonts = substitutionFonts;
+ }
+
/**
* Sets a list of substitution fonts. The list is composed of BaseFont
and can also be null
. The fonts in this list will be used if the original
* font doesn't contain the needed glyphs.
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/XfaForm.java b/openpdf/src/main/java/com/lowagie/text/pdf/XfaForm.java
index 6708bfb9d7..d884a191c7 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/XfaForm.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/XfaForm.java
@@ -609,6 +609,18 @@ public void inverseSearchAdd(String unstack) {
addSomNameToSearchNodeChain(inverseSearch, stack, unstack);
}
+ /**
+ * Adds a SOM name to the search node chain.
+ * @param inverseSearch the start point
+ * @param stack the stack with the separated SOM parts
+ * @param unstack the full name
+ * @deprecated use {@link #addSomNameToSearchNodeChain}
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public static void inverseSearchAdd(HashMap inverseSearch, Stack2 stack, String unstack) {
+ addSomNameToSearchNodeChain(inverseSearch, stack, unstack);
+ }
/**
* Adds a SOM name to the search node chain.
@@ -640,6 +652,18 @@ public static void addSomNameToSearchNodeChain(Map inverse
store.follow.add(unstack);
}
+ /**
+ * Searches the SOM hierarchy from the bottom.
+ * @param parts the SOM parts
+ * @deprecated use {@link #inverseSearch(List)}
+ * @return the full name or null
if not found
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public String inverseSearchGlobal(ArrayList parts) {
+ return inverseSearch(parts);
+ }
+
/**
* Searches the SOM hierarchy from the bottom.
* @param parts the SOM parts
@@ -702,6 +726,16 @@ public static Stack2 splitParts(String name) {
return parts;
}
+ /**
+ * Gets the order the names appear in the XML, depth first.
+ * @deprecated use {@link #getNamesOrder()}
+ * @return the order the names appear in the XML, depth first
+ */
+ @Deprecated
+ public ArrayList getOrder() {
+ return (ArrayList) order;
+ }
+
/**
* Gets the order the names appear in the XML, depth first.
* @return the order the names appear in the XML, depth first
@@ -710,6 +744,17 @@ public List getNamesOrder() {
return order;
}
+ /**
+ * Sets the order the names appear in the XML, depth first
+ * @deprecated use {@link #setNamesOrder(List)}
+ * @param order the order the names appear in the XML, depth first
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void setOrder(ArrayList order) {
+ this.order = order;
+ }
+
/**
* Sets the order the names appear in the XML, depth first
* @param order the order the names appear in the XML, depth first
@@ -718,6 +763,16 @@ public void setNamesOrder(List order) {
this.order = order;
}
+ /**
+ * Gets the mapping of full names to nodes.
+ * @deprecated use {@link #getNodesByName()}
+ * @return the mapping of full names to nodes
+ */
+ @Deprecated
+ public HashMap getName2Node() {
+ return (HashMap) name2Node;
+ }
+
/**
* Gets the mapping of full names to nodes.
* @return the mapping of full names to nodes
@@ -726,6 +781,17 @@ public Map getNodesByName() {
return name2Node;
}
+ /**
+ * Sets the mapping of full names to nodes.
+ * @deprecated use {@link #setNodesByName(Map)}
+ * @param name2Node the mapping of full names to nodes
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void setName2Node(HashMap name2Node) {
+ this.name2Node = name2Node;
+ }
+
/**
* Sets the mapping of full names to nodes.
* @param name2Node the mapping of full names to nodes
@@ -734,6 +800,16 @@ public void setNodesByName(Map name2Node) {
this.name2Node = name2Node;
}
+ /**
+ * Gets the data to do a search from the bottom hierarchy.
+ * @deprecated use {@link #getInverseSearchData()}
+ * @return the data to do a search from the bottom hierarchy
+ */
+ @Deprecated
+ public HashMap getInverseSearch() {
+ return (HashMap) inverseSearch;
+ }
+
/**
* Gets the data to do a search from the bottom hierarchy.
* @return the data to do a search from the bottom hierarchy
@@ -742,6 +818,16 @@ public Map getInverseSearchData() {
return inverseSearch;
}
+ /**
+ * Sets the data to do a search from the bottom hierarchy.
+ * @deprecated use {@link #setInverseSearchData(Map)}
+ * @param inverseSearch the data to do a search from the bottom hierarchy
+ */
+ @Deprecated
+ public void setInverseSearch(Map inverseSearch) {
+ this.inverseSearch = inverseSearch;
+ }
+
/**
* Sets the data to do a search from the bottom hierarchy.
* @param inverseSearch the data to do a search from the bottom hierarchy
@@ -883,6 +969,27 @@ public AcroFieldsSearch(Collection items) {
}
}
+ /**
+ * Gets the mapping from short names to long names. A long
+ * name may contain the #subform name part.
+ * @return the mapping from short names to long names
+ */
+ @Deprecated
+ public HashMap getAcroShort2LongName() {
+ return (HashMap) acroShort2LongName;
+ }
+
+ /**
+ * Sets the mapping from short names to long names. A long
+ * name may contain the #subform name part.
+ * @param acroShort2LongName the mapping from short names to long names
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void setAcroShort2LongName(HashMap acroShort2LongName) {
+ this.acroShort2LongName = acroShort2LongName;
+ }
+
/**
* Gets the mapping from short names to long names. A long
* name may contain the #subform name part.
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/XfdfReader.java b/openpdf/src/main/java/com/lowagie/text/pdf/XfdfReader.java
index 323f84c4fb..f96baeb862 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/XfdfReader.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/XfdfReader.java
@@ -107,6 +107,20 @@ public XfdfReader(byte[] xfdfIn) throws IOException {
SimpleXMLParser.parse(this, new ByteArrayInputStream(xfdfIn));
}
+ /**
+ * Gets all the fields. The map is keyed by the fully qualified field name and the value is a merged
+ * PdfDictionary
with the
+ * field content.
+ *
+ * @deprecated use {@link #getAllFields()}
+ * @return all the fields
+ */
+ @Override
+ @Deprecated
+ public HashMap getFields() {
+ return (HashMap) fields;
+ }
+
@Override
public Map getAllFields() {
return fields;
@@ -154,6 +168,19 @@ public String getFileSpec() {
return fileSpec;
}
+ /**
+ * Called when a start tag is found.
+ *
+ * @param tag the tag name
+ * @param h the tag's attributes
+ */
+ @Deprecated
+ @Override
+ @SuppressWarnings("unchecked")
+ public void startElement(String tag, HashMap h) {
+ startElement(tag, (Map) h);
+ }
+
/**
* Called when a start tag is found.
*
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/Hyphenator.java b/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/Hyphenator.java
index 6c207cb651..a7cac266fb 100755
--- a/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/Hyphenator.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/Hyphenator.java
@@ -91,12 +91,14 @@ public static HyphenationTree getHyphenationTree(String lang,
* @return a hyphenation tree
*/
public static HyphenationTree getResourceHyphenationTree(String key) {
- try {
- InputStream stream = BaseFont.getResourceStream(defaultHyphLocation + key + ".xml");
- if (stream == null && key.length() > 2)
- stream = BaseFont.getResourceStream(defaultHyphLocation + key.substring(0, 2) + ".xml");
- if (stream == null)
- return null;
+
+ InputStream stream = readHyphenationFile(key);
+
+ if (stream == null) {
+ return null;
+ }
+
+ try (InputStream resourceStream = stream){
HyphenationTree hTree = new HyphenationTree();
hTree.loadSimplePatterns(stream);
return hTree;
@@ -105,26 +107,32 @@ public static HyphenationTree getResourceHyphenationTree(String key) {
return null;
}
}
+
+ private static InputStream readHyphenationFile(String key) {
+ InputStream stream = BaseFont.getResourceStream(defaultHyphLocation + key + ".xml");
+ if (stream == null && key.length() > 2) {
+ stream = BaseFont.getResourceStream(defaultHyphLocation + key.substring(0, 2) + ".xml");
+ }
+ return stream;
+ }
+
/**
- * @param key The language to get the tree from
- * @return a hyphenation tree
+ * @param key The language to get the tree from
+ * @return a hyphenation tree or null
*/
public static HyphenationTree getFileHyphenationTree(String key) {
- try {
- if (hyphenDir == null)
- return null;
- InputStream stream = null;
- File hyphenFile = new File(hyphenDir, key + ".xml");
- if (hyphenFile.canRead())
- stream = new FileInputStream(hyphenFile);
- if (stream == null && key.length() > 2) {
- hyphenFile = new File(hyphenDir, key.substring(0, 2) + ".xml");
- if (hyphenFile.canRead())
- stream = new FileInputStream(hyphenFile);
- }
- if (stream == null)
- return null;
+
+ if (hyphenDir == null) {
+ return null;
+ }
+
+ File hyphenFile = getHyphenFile(key);
+ if (hyphenFile == null) {
+ return null;
+ }
+
+ try (InputStream stream = new FileInputStream(hyphenFile)){
HyphenationTree hTree = new HyphenationTree();
hTree.loadSimplePatterns(stream);
return hTree;
@@ -133,6 +141,22 @@ public static HyphenationTree getFileHyphenationTree(String key) {
return null;
}
}
+
+ private static File getHyphenFile(String key) {
+ File hyphenFile = new File(hyphenDir, key + ".xml");
+ if (hyphenFile.canRead()) {
+ return hyphenFile;
+ }
+
+ if (key.length() > 2) {
+ hyphenFile = new File(hyphenDir, key.substring(0, 2) + ".xml");
+ if (hyphenFile.canRead()) {
+ return hyphenFile;
+ }
+ }
+
+ return null;
+ }
/**
* @param lang The language
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/SimplePatternParser.java b/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/SimplePatternParser.java
index ae1d927214..8f317652c2 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/SimplePatternParser.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/SimplePatternParser.java
@@ -59,6 +59,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
@@ -101,7 +102,7 @@ public void parse(InputStream stream, PatternConsumer consumer) {
SimpleXMLParser.parse(this, stream);
} catch (IOException e) {
throw new ExceptionConverter(e);
- }
+ }
}
protected static String getPattern(String word) {
@@ -175,9 +176,11 @@ protected static String getInterletterValues(String pat) {
return il.toString();
}
+ @Override
public void endDocument() {
}
+ @Override
public void endElement(String tag) {
if (token.length() > 0) {
String word = token.toString();
@@ -214,6 +217,16 @@ public void endElement(String tag) {
public void startDocument() {
}
+ /**
+ * @deprecated use {@link SimplePatternParser#startElement(String, Map)}
+ */
+ @Override
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public void startElement(String tag, HashMap h) {
+ startElement(tag, ((Map) h));
+ }
+
@Override
public void startElement(String tag, Map h) {
switch (tag) {
@@ -244,6 +257,7 @@ public void startElement(String tag, Map h) {
token.setLength(0);
}
+ @Override
public void text(String str) {
StringTokenizer tk = new StringTokenizer(str);
while (tk.hasMoreTokens()) {
@@ -269,23 +283,26 @@ public void text(String str) {
}
// PatternConsumer implementation for testing purposes
+ @Override
public void addClass(String c) {
System.out.println("class: " + c);
}
+ @Override
public void addException(String w, ArrayList e) {
System.out.println("exception: " + w + " : " + e.toString());
}
+ @Override
public void addPattern(String p, String v) {
System.out.println("pattern: " + p + " : " + v);
}
public static void main(String[] args) {
- try {
+ try (FileInputStream fis = new FileInputStream(args[0]);){
if (args.length > 0) {
SimplePatternParser pp = new SimplePatternParser();
- pp.parse(new FileInputStream(args[0]), pp);
+ pp.parse(fis, pp);
}
} catch (Exception e) {
e.printStackTrace();
diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/parser/ParsedText.java b/openpdf/src/main/java/com/lowagie/text/pdf/parser/ParsedText.java
index d59f272b3b..2804390cf3 100644
--- a/openpdf/src/main/java/com/lowagie/text/pdf/parser/ParsedText.java
+++ b/openpdf/src/main/java/com/lowagie/text/pdf/parser/ParsedText.java
@@ -67,6 +67,22 @@ public class ParsedText extends ParsedTextImpl {
*/
private PdfString pdfText = null;
+ /**
+ * This constructor should only be called when the origin for text display is at (0,0) and the
+ * graphical state reflects all transformations of the baseline. This is in text space units.
+ *
+ * Decodes a String (which will contain glyph ids encoded in the font's encoding) based on
+ * the active font. This is supported for compatibility, but is no longer preferred.
+ *
+ * @param text string
+ * @param graphicsState graphical state
+ * @param textMatrix transform from text space to graphics (drawing space)
+ */
+ @Deprecated
+ ParsedText(String text, GraphicsState graphicsState, Matrix textMatrix) {
+ this(text, new GraphicsState(graphicsState), textMatrix.multiply(graphicsState.getCtm()),
+ getUnscaledFontSpaceWidth(graphicsState));
+ }
/**
* This constructor should only be called when the origin for text display is at (0,0) and the
@@ -114,6 +130,25 @@ private ParsedText(PdfString text, GraphicsState graphicsState, Matrix textMatri
this.graphicsState = graphicsState;
}
+ /**
+ * Internal constructor when the code points are already in a string.
+ *
+ * @param text string
+ * @param graphicsState graphical state
+ * @param textMatrix transform from text space to graphics (drawing space)
+ * @param unscaledWidth width of the space character in the font.
+ */
+ @Deprecated
+ private ParsedText(String text, GraphicsState graphicsState, Matrix textMatrix, float unscaledWidth) {
+ super(text, pointToUserSpace(0, 0, textMatrix),
+ pointToUserSpace(getStringWidth(text, graphicsState), 0f, textMatrix),
+ pointToUserSpace(1.0f, 0f, textMatrix),
+ convertHeightToUser(graphicsState.getFontAscentDescriptor(), textMatrix),
+ convertHeightToUser(graphicsState.getFontDescentDescriptor(), textMatrix),
+ convertWidthToUser(unscaledWidth, textMatrix));
+ textToUserSpaceTransformMatrix = textMatrix;
+ this.graphicsState = graphicsState;
+ }
/**
* @param xOffset offset in x direction
diff --git a/openpdf/src/main/java/com/lowagie/text/xml/TagMap.java b/openpdf/src/main/java/com/lowagie/text/xml/TagMap.java
index eef5df800a..c350343bd3 100644
--- a/openpdf/src/main/java/com/lowagie/text/xml/TagMap.java
+++ b/openpdf/src/main/java/com/lowagie/text/xml/TagMap.java
@@ -151,6 +151,18 @@ class AttributeHandler extends DefaultHandler {
*/
private XmlPeer currentPeer;
+ /**
+ * Constructs a new SAXiTextHandler that will translate all the events
+ * triggered by the parser to actions on the Document
-object.
+ *
+ * @param tagMap A Hashmap containing XmlPeer-objects
+ */
+ @Deprecated
+ @SuppressWarnings("unchecked")
+ public AttributeHandler(HashMap tagMap) {
+ this.tagMap = tagMap;
+ }
+
public AttributeHandler(Map tagMap) {
this.tagMap = tagMap;
}
diff --git a/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/EntitiesToSymbol.java b/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/EntitiesToSymbol.java
index 6e787344aa..d145d516b4 100644
--- a/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/EntitiesToSymbol.java
+++ b/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/EntitiesToSymbol.java
@@ -69,8 +69,11 @@ public static Map getMap() {
/**
* This is a map that contains all possible id values of the entity tag
* that can be translated to a character in font Symbol.
+ *
+ * @deprecated use the getter ({@link EntitiesToSymbol#getMap()}) instead of accessing this field directly
*/
- static final HashMap map;
+ @Deprecated
+ public static final HashMap map;
static {
map = new HashMap<>(300);
diff --git a/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/EntitiesToUnicode.java b/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/EntitiesToUnicode.java
index c2f45e82d2..e1309b6067 100644
--- a/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/EntitiesToUnicode.java
+++ b/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/EntitiesToUnicode.java
@@ -65,8 +65,11 @@ public static Map getMap() {
/**
* This is a map that contains the names of entities and their unicode value.
+ *
+ * @deprecated use the getter ({@link EntitiesToUnicode#getMap()}) instead of accessing this field directly
*/
- static final HashMap map = new HashMap<>();
+ @Deprecated
+ public static final HashMap map = new HashMap<>();
static {
map.put("nbsp", '\u00a0'); // no-break space = non-breaking space, U+00A0 ISOnum
diff --git a/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/SimpleXMLDocHandler.java b/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/SimpleXMLDocHandler.java
index 0f00c813bf..e9c1a5a326 100644
--- a/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/SimpleXMLDocHandler.java
+++ b/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/SimpleXMLDocHandler.java
@@ -46,6 +46,7 @@
*/
package com.lowagie.text.xml.simpleparser;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -53,6 +54,12 @@
* @author Paulo Soares (psoares@consiste.pt)
*/
public interface SimpleXMLDocHandler {
+ /**
+ * Called when a start tag is found.
+ * @param tag the tag name
+ * @param h the tag's attributes
+ */
+ void startElement(String tag, HashMap h);
/**
* Called when a start tag is found.
* @param tag the tag name
diff --git a/openpdf/src/test/java/com/lowagie/text/pdf/PdfDocumentCJKExtensionTest.java b/openpdf/src/test/java/com/lowagie/text/pdf/PdfDocumentCJKExtensionTest.java
new file mode 100644
index 0000000000..9553c1bcab
--- /dev/null
+++ b/openpdf/src/test/java/com/lowagie/text/pdf/PdfDocumentCJKExtensionTest.java
@@ -0,0 +1,65 @@
+package com.lowagie.text.pdf;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import com.lowagie.text.Chunk;
+import com.lowagie.text.Document;
+import com.lowagie.text.Font;
+import com.lowagie.text.FontFactory;
+import org.junit.jupiter.api.Test;
+
+class PdfDocumentCJKExtensionTest {
+ @Test
+ void generateDocumentsWithCJKExtension() throws IOException {
+ String fontName = "TakaoMjMincho";
+
+ // TakaoMjMincho Version 003.01.01
+ // Please download and place it below.
+ // https://launchpad.net/takao-fonts
+ // https://launchpad.net/takao-fonts/trunk/15.03/+download/TakaoMjFonts_00301.01.zip
+ String fontPath = "src/test/resources/fonts/TakaoMjFonts/TakaoMjMincho.ttf";
+
+ // register font
+ FontFactory.register(fontPath, fontName);
+
+ Document document = new Document();
+
+ // FOP off
+ document.setGlyphSubstitutionEnabled(false);
+
+ PdfWriter.getInstance(document, new FileOutputStream("target/" + PdfDocumentCJKExtensionTest.class.getSimpleName() + ".pdf"));
+
+ try {
+ Font font = FontFactory.getFont(fontName, "Identity-H", false, 10, 0, null);
+
+ document.open();
+ // CJK Unified Ideographs Extension B
+ // https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_Extension_B
+
+ // U+20000
+ String cjkB_OK = "𠀀";
+ // U+2A000
+ String cjkB_NG = "𪀀";
+
+
+ // CJK Unified Ideographs Extension C
+ // https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_Extension_C
+
+ // U+2A746
+ String cjkC_NG = "𪝆";
+
+
+ // CJK Unified Ideographs Extension D
+ // https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_Extension_D
+
+ // U+2B746
+ String cjkD_NG = "𫝆";
+
+ document.add(new Chunk(cjkB_OK + " " + cjkB_NG + " " + cjkC_NG + " " + cjkD_NG, font));
+
+ } finally {
+ document.close();
+ }
+ }
+}
diff --git a/openpdf/src/test/java/com/lowagie/text/xml/simpleparser/SimpleXMLParserTest.java b/openpdf/src/test/java/com/lowagie/text/xml/simpleparser/SimpleXMLParserTest.java
index d0c9638a74..aed69bb0ad 100755
--- a/openpdf/src/test/java/com/lowagie/text/xml/simpleparser/SimpleXMLParserTest.java
+++ b/openpdf/src/test/java/com/lowagie/text/xml/simpleparser/SimpleXMLParserTest.java
@@ -4,6 +4,7 @@
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
@@ -57,6 +58,9 @@ static class TestHandler implements SimpleXMLDocHandler, AutoCloseable {
this.charset = charset.displayName();
}
+ @Override
+ public void startElement(String tag, HashMap h) {}
+
@Override
public void startElement(String tag, Map h) {}