Porting update.
git-svn-id: svn://svn.code.sf.net/p/itextsharp/code/trunk@32 820d3149-562b-4f88-9aa4-a8e61a3485cfmaster
parent
ac378f9583
commit
b972b07a17
|
@ -326,8 +326,11 @@ namespace iTextSharp.text {
|
||||||
System.Array.Copy(icc[k], 14, ficc, total, icc[k].Length - 14);
|
System.Array.Copy(icc[k], 14, ficc, total, icc[k].Length - 14);
|
||||||
total += icc[k].Length - 14;
|
total += icc[k].Length - 14;
|
||||||
}
|
}
|
||||||
ICC_Profile icc_prof = ICC_Profile.GetInstance(ficc);
|
try {
|
||||||
TagICC = icc_prof;
|
ICC_Profile icc_prof = ICC_Profile.GetInstance(ficc);
|
||||||
|
TagICC = icc_prof;
|
||||||
|
}
|
||||||
|
catch {}
|
||||||
icc = null;
|
icc = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -371,6 +371,9 @@ namespace iTextSharp.text.html.simpleparser {
|
||||||
else if (key.Equals(Markup.CSS_KEY_TEXTALIGN)) {
|
else if (key.Equals(Markup.CSS_KEY_TEXTALIGN)) {
|
||||||
String ss = prop[key].Trim().ToLower(System.Globalization.CultureInfo.InvariantCulture);
|
String ss = prop[key].Trim().ToLower(System.Globalization.CultureInfo.InvariantCulture);
|
||||||
h["align"] = ss;
|
h["align"] = ss;
|
||||||
|
} else if (key.Equals(Markup.CSS_KEY_PADDINGLEFT)) {
|
||||||
|
String ss = prop[key].Trim().ToLower(System.Globalization.CultureInfo.InvariantCulture);
|
||||||
|
h["indent"] = ss;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,7 +313,12 @@ namespace iTextSharp.text.html.simpleparser {
|
||||||
EndElement(HtmlTags.LISTITEM);
|
EndElement(HtmlTags.LISTITEM);
|
||||||
skipText = true;
|
skipText = true;
|
||||||
cprops.AddToChain(tag, h);
|
cprops.AddToChain(tag, h);
|
||||||
List list = new List(false, 10);
|
List list = new List(false);
|
||||||
|
try{
|
||||||
|
list.IndentationLeft = float.Parse(cprops["indent"], System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||||
|
}catch {
|
||||||
|
list.Autoindent = true;
|
||||||
|
}
|
||||||
list.SetListSymbol("\u2022");
|
list.SetListSymbol("\u2022");
|
||||||
stack.Push(list);
|
stack.Push(list);
|
||||||
return;
|
return;
|
||||||
|
@ -323,7 +328,12 @@ namespace iTextSharp.text.html.simpleparser {
|
||||||
EndElement(HtmlTags.LISTITEM);
|
EndElement(HtmlTags.LISTITEM);
|
||||||
skipText = true;
|
skipText = true;
|
||||||
cprops.AddToChain(tag, h);
|
cprops.AddToChain(tag, h);
|
||||||
List list = new List(true, 10);
|
List list = new List(true);
|
||||||
|
try{
|
||||||
|
list.IndentationLeft = float.Parse(cprops["indent"], System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||||
|
}catch {
|
||||||
|
list.Autoindent = true;
|
||||||
|
}
|
||||||
stack.Push(list);
|
stack.Push(list);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,59 +1,59 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Id: BadPasswordException.cs,v 1.1 2008/01/10 15:49:39 psoares33 Exp $
|
* $Id: BadPasswordException.cs,v 1.1 2008/01/10 15:49:39 psoares33 Exp $
|
||||||
*
|
*
|
||||||
* Copyright 2008 Bruno Lowagie
|
* Copyright 2008 Bruno Lowagie
|
||||||
*
|
*
|
||||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
* (the "License"); you may not use this file except in compliance with the License.
|
* (the "License"); you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||||
*
|
*
|
||||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
* for the specific language governing rights and limitations under the License.
|
* for the specific language governing rights and limitations under the License.
|
||||||
*
|
*
|
||||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||||
*
|
*
|
||||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Contributor(s): all the names of the contributors are added in the source code
|
* Contributor(s): all the names of the contributors are added in the source code
|
||||||
* where applicable.
|
* where applicable.
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of the
|
* Alternatively, the contents of this file may be used under the terms of the
|
||||||
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
|
||||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||||
* allow use of your version of this file only under the terms of the LGPL
|
* allow use of your version of this file only under the terms of the LGPL
|
||||||
* License and not to allow others to use your version of this file under
|
* License and not to allow others to use your version of this file under
|
||||||
* the MPL, indicate your decision by deleting the provisions above and
|
* the MPL, indicate your decision by deleting the provisions above and
|
||||||
* replace them with the notice and other provisions required by the LGPL.
|
* replace them with the notice and other provisions required by the LGPL.
|
||||||
* If you do not delete the provisions above, a recipient may use your version
|
* If you do not delete the provisions above, a recipient may use your version
|
||||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify it
|
* This library is free software; you can redistribute it and/or modify it
|
||||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||||
* Library General Public License as published by the Free Software Foundation;
|
* Library General Public License as published by the Free Software Foundation;
|
||||||
* either version 2 of the License, or any later version.
|
* either version 2 of the License, or any later version.
|
||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||||
* details.
|
* details.
|
||||||
*
|
*
|
||||||
* If you didn't download this code from the following link, you should check if
|
* If you didn't download this code from the following link, you should check if
|
||||||
* you aren't using an obsolete version:
|
* you aren't using an obsolete version:
|
||||||
* http://www.lowagie.com/iText/
|
* http://www.lowagie.com/iText/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace iTextSharp.text.pdf {
|
namespace iTextSharp.text.pdf {
|
||||||
|
|
||||||
public class BadPasswordException : IOException {
|
public class BadPasswordException : IOException {
|
||||||
public BadPasswordException() : base("Bad user Password") {
|
public BadPasswordException(string message) : base(message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@ using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using iTextSharp.text;
|
using iTextSharp.text;
|
||||||
|
using iTextSharp.text.exceptions;
|
||||||
using iTextSharp.text.pdf.intern;
|
using iTextSharp.text.pdf.intern;
|
||||||
using iTextSharp.text.pdf.interfaces;
|
using iTextSharp.text.pdf.interfaces;
|
||||||
using System.util;
|
using System.util;
|
||||||
|
@ -258,8 +259,8 @@ namespace iTextSharp.text.pdf {
|
||||||
}
|
}
|
||||||
this.pageRefs = new PageRefs(reader.pageRefs, this);
|
this.pageRefs = new PageRefs(reader.pageRefs, this);
|
||||||
this.trailer = (PdfDictionary)DuplicatePdfObject(reader.trailer, this);
|
this.trailer = (PdfDictionary)DuplicatePdfObject(reader.trailer, this);
|
||||||
this.catalog = (PdfDictionary)GetPdfObject(trailer.Get(PdfName.ROOT));
|
this.catalog = trailer.GetAsDict(PdfName.ROOT);
|
||||||
this.rootPages = (PdfDictionary)GetPdfObject(catalog.Get(PdfName.PAGES));
|
this.rootPages = catalog.GetAsDict(PdfName.PAGES);
|
||||||
this.fileLength = reader.fileLength;
|
this.fileLength = reader.fileLength;
|
||||||
this.partial = reader.partial;
|
this.partial = reader.partial;
|
||||||
this.hybridXref = reader.hybridXref;
|
this.hybridXref = reader.hybridXref;
|
||||||
|
@ -333,7 +334,7 @@ namespace iTextSharp.text.pdf {
|
||||||
}
|
}
|
||||||
|
|
||||||
internal int GetPageRotation(PdfDictionary page) {
|
internal int GetPageRotation(PdfDictionary page) {
|
||||||
PdfNumber rotate = (PdfNumber)GetPdfObject(page.Get(PdfName.ROTATE));
|
PdfNumber rotate = page.GetAsNumber(PdfName.ROTATE);
|
||||||
if (rotate == null)
|
if (rotate == null)
|
||||||
return 0;
|
return 0;
|
||||||
else {
|
else {
|
||||||
|
@ -381,7 +382,7 @@ namespace iTextSharp.text.pdf {
|
||||||
* @return the page
|
* @return the page
|
||||||
*/
|
*/
|
||||||
public Rectangle GetPageSize(PdfDictionary page) {
|
public Rectangle GetPageSize(PdfDictionary page) {
|
||||||
PdfArray mediaBox = (PdfArray)GetPdfObject(page.Get(PdfName.MEDIABOX));
|
PdfArray mediaBox = page.GetAsArray(PdfName.MEDIABOX);
|
||||||
return GetNormalizedRectangle(mediaBox);
|
return GetNormalizedRectangle(mediaBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,7 +432,7 @@ namespace iTextSharp.text.pdf {
|
||||||
public Hashtable Info {
|
public Hashtable Info {
|
||||||
get {
|
get {
|
||||||
Hashtable map = new Hashtable();
|
Hashtable map = new Hashtable();
|
||||||
PdfDictionary info = (PdfDictionary)GetPdfObject(trailer.Get(PdfName.INFO));
|
PdfDictionary info = trailer.GetAsDict(PdfName.INFO);
|
||||||
if (info == null)
|
if (info == null)
|
||||||
return map;
|
return map;
|
||||||
foreach (PdfName key in info.Keys) {
|
foreach (PdfName key in info.Keys) {
|
||||||
|
@ -460,11 +461,10 @@ namespace iTextSharp.text.pdf {
|
||||||
* @return a normalized <CODE>Rectangle</CODE>
|
* @return a normalized <CODE>Rectangle</CODE>
|
||||||
*/
|
*/
|
||||||
public static Rectangle GetNormalizedRectangle(PdfArray box) {
|
public static Rectangle GetNormalizedRectangle(PdfArray box) {
|
||||||
ArrayList rect = box.ArrayList;
|
float llx = ((PdfNumber)GetPdfObjectRelease(box[0])).FloatValue;
|
||||||
float llx = ((PdfNumber)GetPdfObjectRelease((PdfObject)rect[0])).FloatValue;
|
float lly = ((PdfNumber)GetPdfObjectRelease(box[1])).FloatValue;
|
||||||
float lly = ((PdfNumber)GetPdfObjectRelease((PdfObject)rect[1])).FloatValue;
|
float urx = ((PdfNumber)GetPdfObjectRelease(box[2])).FloatValue;
|
||||||
float urx = ((PdfNumber)GetPdfObjectRelease((PdfObject)rect[2])).FloatValue;
|
float ury = ((PdfNumber)GetPdfObjectRelease(box[3])).FloatValue;
|
||||||
float ury = ((PdfNumber)GetPdfObjectRelease((PdfObject)rect[3])).FloatValue;
|
|
||||||
return new Rectangle(Math.Min(llx, urx), Math.Min(lly, ury),
|
return new Rectangle(Math.Min(llx, urx), Math.Min(lly, ury),
|
||||||
Math.Max(llx, urx), Math.Max(lly, ury));
|
Math.Max(llx, urx), Math.Max(lly, ury));
|
||||||
}
|
}
|
||||||
|
@ -483,15 +483,17 @@ namespace iTextSharp.text.pdf {
|
||||||
lastXref = -1;
|
lastXref = -1;
|
||||||
}
|
}
|
||||||
catch (Exception ne) {
|
catch (Exception ne) {
|
||||||
throw new IOException("Rebuild failed: " + ne.Message + "; Original message: " + e.Message);
|
throw new InvalidPdfException("Rebuild failed: " + ne.Message + "; Original message: " + e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ReadDocObj();
|
ReadDocObj();
|
||||||
}
|
}
|
||||||
catch (Exception ne) {
|
catch (Exception ne) {
|
||||||
|
if (ne is BadPasswordException)
|
||||||
|
throw new BadPasswordException(ne.Message);
|
||||||
if (rebuilt || encryptionError)
|
if (rebuilt || encryptionError)
|
||||||
throw ne;
|
throw new InvalidPdfException(ne.Message);
|
||||||
rebuilt = true;
|
rebuilt = true;
|
||||||
encrypted = false;
|
encrypted = false;
|
||||||
RebuildXref();
|
RebuildXref();
|
||||||
|
@ -528,7 +530,7 @@ namespace iTextSharp.text.pdf {
|
||||||
lastXref = -1;
|
lastXref = -1;
|
||||||
}
|
}
|
||||||
catch (Exception ne) {
|
catch (Exception ne) {
|
||||||
throw new IOException("Rebuild failed: " + ne.Message + "; Original message: " + e.Message);
|
throw new InvalidPdfException("Rebuild failed: " + ne.Message + "; Original message: " + e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ReadDocObjPartial();
|
ReadDocObjPartial();
|
||||||
|
@ -566,15 +568,15 @@ namespace iTextSharp.text.pdf {
|
||||||
String s;
|
String s;
|
||||||
PdfObject o;
|
PdfObject o;
|
||||||
|
|
||||||
PdfArray documentIDs = (PdfArray)GetPdfObject(trailer.Get(PdfName.ID));
|
PdfArray documentIDs = trailer.GetAsArray(PdfName.ID);
|
||||||
byte[] documentID = null;
|
byte[] documentID = null;
|
||||||
if (documentIDs != null) {
|
if (documentIDs != null) {
|
||||||
o = (PdfObject)documentIDs.ArrayList[0];
|
o = documentIDs[0];
|
||||||
strings.Remove(o);
|
strings.Remove(o);
|
||||||
s = o.ToString();
|
s = o.ToString();
|
||||||
documentID = DocWriter.GetISOBytes(s);
|
documentID = DocWriter.GetISOBytes(s);
|
||||||
if (documentIDs.Size > 1)
|
if (documentIDs.Size > 1)
|
||||||
strings.Remove(documentIDs.ArrayList[1]);
|
strings.Remove(documentIDs[1]);
|
||||||
}
|
}
|
||||||
// just in case we have a broken producer
|
// just in case we have a broken producer
|
||||||
if (documentID == null)
|
if (documentID == null)
|
||||||
|
@ -595,43 +597,48 @@ namespace iTextSharp.text.pdf {
|
||||||
strings.Remove(enc.Get(PdfName.O));
|
strings.Remove(enc.Get(PdfName.O));
|
||||||
oValue = DocWriter.GetISOBytes(s);
|
oValue = DocWriter.GetISOBytes(s);
|
||||||
|
|
||||||
o = enc.Get(PdfName.R);
|
|
||||||
if (!o.IsNumber()) throw new IOException("Illegal R value.");
|
|
||||||
rValue = ((PdfNumber)o).IntValue;
|
|
||||||
if (rValue != 2 && rValue != 3 && rValue != 4) throw new IOException("Unknown encryption type (" + rValue + ")");
|
|
||||||
|
|
||||||
o = enc.Get(PdfName.P);
|
o = enc.Get(PdfName.P);
|
||||||
if (!o.IsNumber()) throw new IOException("Illegal P value.");
|
if (!o.IsNumber())
|
||||||
|
throw new InvalidPdfException("Illegal P value.");
|
||||||
pValue = ((PdfNumber)o).IntValue;
|
pValue = ((PdfNumber)o).IntValue;
|
||||||
|
|
||||||
if ( rValue == 3 ){
|
o = enc.Get(PdfName.R);
|
||||||
|
if (!o.IsNumber())
|
||||||
|
throw new InvalidPdfException("Illegal R value.");
|
||||||
|
rValue = ((PdfNumber)o).IntValue;
|
||||||
|
|
||||||
|
switch (rValue) {
|
||||||
|
case 2:
|
||||||
|
cryptoMode = PdfWriter.STANDARD_ENCRYPTION_40;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
o = enc.Get(PdfName.LENGTH);
|
o = enc.Get(PdfName.LENGTH);
|
||||||
if (!o.IsNumber())
|
if (!o.IsNumber())
|
||||||
throw new IOException("Illegal Length value.");
|
throw new InvalidPdfException("Illegal Length value.");
|
||||||
lengthValue = ((PdfNumber)o).IntValue;
|
lengthValue = ( (PdfNumber) o).IntValue;
|
||||||
if (lengthValue > 128 || lengthValue < 40 || lengthValue % 8 != 0)
|
if (lengthValue > 128 || lengthValue < 40 || lengthValue % 8 != 0)
|
||||||
throw new IOException("Illegal Length value.");
|
throw new InvalidPdfException("Illegal Length value.");
|
||||||
cryptoMode = PdfWriter.STANDARD_ENCRYPTION_128;
|
cryptoMode = PdfWriter.STANDARD_ENCRYPTION_128;
|
||||||
}
|
break;
|
||||||
else if (rValue == 4) {
|
case 4:
|
||||||
lengthValue = 128;
|
|
||||||
PdfDictionary dic = (PdfDictionary)enc.Get(PdfName.CF);
|
PdfDictionary dic = (PdfDictionary)enc.Get(PdfName.CF);
|
||||||
if (dic == null)
|
if (dic == null)
|
||||||
throw new IOException("/CF not found (encryption)");
|
throw new InvalidPdfException("/CF not found (encryption)");
|
||||||
dic = (PdfDictionary)dic.Get(PdfName.STDCF);
|
dic = (PdfDictionary)dic.Get(PdfName.STDCF);
|
||||||
if (dic == null)
|
if (dic == null)
|
||||||
throw new IOException("/StdCF not found (encryption)");
|
throw new InvalidPdfException("/StdCF not found (encryption)");
|
||||||
if (PdfName.V2.Equals(dic.Get(PdfName.CFM)))
|
if (PdfName.V2.Equals(dic.Get(PdfName.CFM)))
|
||||||
cryptoMode = PdfWriter.STANDARD_ENCRYPTION_128;
|
cryptoMode = PdfWriter.STANDARD_ENCRYPTION_128;
|
||||||
else if (PdfName.AESV2.Equals(dic.Get(PdfName.CFM)))
|
else if (PdfName.AESV2.Equals(dic.Get(PdfName.CFM)))
|
||||||
cryptoMode = PdfWriter.ENCRYPTION_AES_128;
|
cryptoMode = PdfWriter.ENCRYPTION_AES_128;
|
||||||
else
|
else
|
||||||
throw new IOException("No compatible encryption found");
|
throw new UnsupportedPdfException("No compatible encryption found");
|
||||||
PdfObject em = enc.Get(PdfName.ENCRYPTMETADATA);
|
PdfObject em = enc.Get(PdfName.ENCRYPTMETADATA);
|
||||||
if (em != null && em.ToString().Equals("false"))
|
if (em != null && em.ToString().Equals("false"))
|
||||||
cryptoMode |= PdfWriter.DO_NOT_ENCRYPT_METADATA;
|
cryptoMode |= PdfWriter.DO_NOT_ENCRYPT_METADATA;
|
||||||
} else {
|
break;
|
||||||
cryptoMode = PdfWriter.STANDARD_ENCRYPTION_40;
|
default:
|
||||||
|
throw new UnsupportedPdfException("Unknown encryption type R = " + rValue);
|
||||||
}
|
}
|
||||||
} else if (filter.Equals(PdfName.PUBSEC)) {
|
} else if (filter.Equals(PdfName.PUBSEC)) {
|
||||||
bool foundRecipient = false;
|
bool foundRecipient = false;
|
||||||
|
@ -639,53 +646,55 @@ namespace iTextSharp.text.pdf {
|
||||||
PdfArray recipients = null;
|
PdfArray recipients = null;
|
||||||
|
|
||||||
o = enc.Get(PdfName.V);
|
o = enc.Get(PdfName.V);
|
||||||
if (!o.IsNumber()) throw new IOException("Illegal V value.");
|
if (!o.IsNumber())
|
||||||
|
throw new InvalidPdfException("Illegal V value.");
|
||||||
int vValue = ((PdfNumber)o).IntValue;
|
int vValue = ((PdfNumber)o).IntValue;
|
||||||
if (vValue != 1 && vValue != 2 && vValue != 4)
|
switch(vValue) {
|
||||||
throw new IOException("Unknown encryption type V = " + rValue);
|
case 1:
|
||||||
|
cryptoMode = PdfWriter.STANDARD_ENCRYPTION_40;
|
||||||
if ( vValue == 2 ){
|
lengthValue = 40;
|
||||||
|
recipients = (PdfArray)enc.Get(PdfName.RECIPIENTS);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
o = enc.Get(PdfName.LENGTH);
|
o = enc.Get(PdfName.LENGTH);
|
||||||
if (!o.IsNumber())
|
if (!o.IsNumber())
|
||||||
throw new IOException("Illegal Length value.");
|
throw new InvalidPdfException("Illegal Length value.");
|
||||||
lengthValue = ((PdfNumber)o).IntValue;
|
lengthValue = ( (PdfNumber) o).IntValue;
|
||||||
if (lengthValue > 128 || lengthValue < 40 || lengthValue % 8 != 0)
|
if (lengthValue > 128 || lengthValue < 40 || lengthValue % 8 != 0)
|
||||||
throw new IOException("Illegal Length value.");
|
throw new InvalidPdfException("Illegal Length value.");
|
||||||
cryptoMode = PdfWriter.STANDARD_ENCRYPTION_128;
|
cryptoMode = PdfWriter.STANDARD_ENCRYPTION_128;
|
||||||
recipients = (PdfArray)enc.Get(PdfName.RECIPIENTS);
|
recipients = (PdfArray)enc.Get(PdfName.RECIPIENTS);
|
||||||
} else if (vValue == 4) {
|
break;
|
||||||
|
case 4:
|
||||||
PdfDictionary dic = (PdfDictionary)enc.Get(PdfName.CF);
|
PdfDictionary dic = (PdfDictionary)enc.Get(PdfName.CF);
|
||||||
if (dic == null)
|
if (dic == null)
|
||||||
throw new IOException("/CF not found (encryption)");
|
throw new InvalidPdfException("/CF not found (encryption)");
|
||||||
dic = (PdfDictionary)dic.Get(PdfName.DEFAULTCRYPTFILTER);
|
dic = (PdfDictionary)dic.Get(PdfName.DEFAULTCRYPTFILTER);
|
||||||
if (dic == null)
|
if (dic == null)
|
||||||
throw new IOException("/DefaultCryptFilter not found (encryption)");
|
throw new InvalidPdfException("/DefaultCryptFilter not found (encryption)");
|
||||||
if (PdfName.V2.Equals(dic.Get(PdfName.CFM)))
|
if (PdfName.V2.Equals(dic.Get(PdfName.CFM))) {
|
||||||
{
|
|
||||||
cryptoMode = PdfWriter.STANDARD_ENCRYPTION_128;
|
cryptoMode = PdfWriter.STANDARD_ENCRYPTION_128;
|
||||||
lengthValue = 128;
|
lengthValue = 128;
|
||||||
}
|
}
|
||||||
else if (PdfName.AESV2.Equals(dic.Get(PdfName.CFM)))
|
else if (PdfName.AESV2.Equals(dic.Get(PdfName.CFM))) {
|
||||||
{
|
|
||||||
cryptoMode = PdfWriter.ENCRYPTION_AES_128;
|
cryptoMode = PdfWriter.ENCRYPTION_AES_128;
|
||||||
lengthValue = 128;
|
lengthValue = 128;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw new IOException("No compatible encryption found");
|
throw new UnsupportedPdfException("No compatible encryption found");
|
||||||
PdfObject em = dic.Get(PdfName.ENCRYPTMETADATA);
|
PdfObject em = dic.Get(PdfName.ENCRYPTMETADATA);
|
||||||
if (em != null && em.ToString().Equals("false"))
|
if (em != null && em.ToString().Equals("false"))
|
||||||
cryptoMode |= PdfWriter.DO_NOT_ENCRYPT_METADATA;
|
cryptoMode |= PdfWriter.DO_NOT_ENCRYPT_METADATA;
|
||||||
|
|
||||||
recipients = (PdfArray)dic.Get(PdfName.RECIPIENTS);
|
recipients = (PdfArray)dic.Get(PdfName.RECIPIENTS);
|
||||||
} else {
|
break;
|
||||||
cryptoMode = PdfWriter.STANDARD_ENCRYPTION_40;
|
default:
|
||||||
lengthValue = 40;
|
throw new UnsupportedPdfException("Unknown encryption type V = " + rValue);
|
||||||
recipients = (PdfArray)enc.Get(PdfName.RECIPIENTS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i<recipients.Size; i++)
|
for (int i = 0; i<recipients.Size; i++)
|
||||||
{
|
{
|
||||||
PdfObject recipient = (PdfObject)recipients.ArrayList[i];
|
PdfObject recipient = recipients[i];
|
||||||
strings.Remove(recipient);
|
strings.Remove(recipient);
|
||||||
|
|
||||||
CmsEnvelopedData data = null;
|
CmsEnvelopedData data = null;
|
||||||
|
@ -702,16 +711,15 @@ namespace iTextSharp.text.pdf {
|
||||||
|
|
||||||
if (!foundRecipient || envelopedData == null)
|
if (!foundRecipient || envelopedData == null)
|
||||||
{
|
{
|
||||||
throw new IOException("Bad certificate and key.");
|
throw new UnsupportedPdfException("Bad certificate and key.");
|
||||||
}
|
}
|
||||||
|
|
||||||
SHA1 sh = new SHA1CryptoServiceProvider();
|
SHA1 sh = new SHA1CryptoServiceProvider();
|
||||||
|
|
||||||
sh.TransformBlock(envelopedData, 0, 20, envelopedData, 0);
|
sh.TransformBlock(envelopedData, 0, 20, envelopedData, 0);
|
||||||
for (int i=0; i<recipients.Size; i++)
|
for (int i=0; i<recipients.Size; i++) {
|
||||||
{
|
byte[] encodedRecipient = recipients[i].GetBytes();
|
||||||
byte[] encodedRecipient = ((PdfObject)recipients.ArrayList[i]).GetBytes();
|
sh.TransformBlock(encodedRecipient, 0, encodedRecipient.Length, encodedRecipient, 0);
|
||||||
sh.TransformBlock(encodedRecipient, 0, encodedRecipient.Length, encodedRecipient, 0);
|
|
||||||
}
|
}
|
||||||
if ((cryptoMode & PdfWriter.DO_NOT_ENCRYPT_METADATA) != 0)
|
if ((cryptoMode & PdfWriter.DO_NOT_ENCRYPT_METADATA) != 0)
|
||||||
sh.TransformBlock(PdfEncryption.metadataPad, 0, PdfEncryption.metadataPad.Length, PdfEncryption.metadataPad, 0);
|
sh.TransformBlock(PdfEncryption.metadataPad, 0, PdfEncryption.metadataPad.Length, PdfEncryption.metadataPad, 0);
|
||||||
|
@ -729,7 +737,7 @@ namespace iTextSharp.text.pdf {
|
||||||
//check by user password
|
//check by user password
|
||||||
decrypt.SetupByUserPassword(documentID, password, oValue, pValue);
|
decrypt.SetupByUserPassword(documentID, password, oValue, pValue);
|
||||||
if (!EqualsArray(uValue, decrypt.userKey, (rValue == 3 || rValue == 4) ? 16 : 32)) {
|
if (!EqualsArray(uValue, decrypt.userKey, (rValue == 3 || rValue == 4) ? 16 : 32)) {
|
||||||
throw new BadPasswordException();
|
throw new BadPasswordException("Bad user password");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -895,6 +903,8 @@ namespace iTextSharp.text.pdf {
|
||||||
return;
|
return;
|
||||||
if (!obj.IsIndirect())
|
if (!obj.IsIndirect())
|
||||||
return;
|
return;
|
||||||
|
if (!(obj is PRIndirectReference))
|
||||||
|
return;
|
||||||
PRIndirectReference refi = (PRIndirectReference)obj;
|
PRIndirectReference refi = (PRIndirectReference)obj;
|
||||||
PdfReader reader = refi.Reader;
|
PdfReader reader = refi.Reader;
|
||||||
if (reader.partial && reader.lastXrefPartial != -1 && reader.lastXrefPartial == refi.Number) {
|
if (reader.partial && reader.lastXrefPartial != -1 && reader.lastXrefPartial == refi.Number) {
|
||||||
|
@ -919,8 +929,8 @@ namespace iTextSharp.text.pdf {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal void ReadPages() {
|
protected internal void ReadPages() {
|
||||||
catalog = (PdfDictionary)GetPdfObject(trailer.Get(PdfName.ROOT));
|
catalog = trailer.GetAsDict(PdfName.ROOT);
|
||||||
rootPages = (PdfDictionary)GetPdfObject(catalog.Get(PdfName.PAGES));
|
rootPages = catalog.GetAsDict(PdfName.PAGES);
|
||||||
pageRefs = new PageRefs(this);
|
pageRefs = new PageRefs(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -981,7 +991,7 @@ namespace iTextSharp.text.pdf {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal PdfObject ReadOneObjStm(PRStream stream, int idx) {
|
protected internal PdfObject ReadOneObjStm(PRStream stream, int idx) {
|
||||||
int first = ((PdfNumber)GetPdfObject(stream.Get(PdfName.FIRST))).IntValue;
|
int first = stream.GetAsNumber(PdfName.FIRST).IntValue;
|
||||||
byte[] b = GetStreamBytes(stream, tokens.File);
|
byte[] b = GetStreamBytes(stream, tokens.File);
|
||||||
PRTokeniser saveTokens = tokens;
|
PRTokeniser saveTokens = tokens;
|
||||||
tokens = new PRTokeniser(b);
|
tokens = new PRTokeniser(b);
|
||||||
|
@ -1007,7 +1017,7 @@ namespace iTextSharp.text.pdf {
|
||||||
address = tokens.IntValue + first;
|
address = tokens.IntValue + first;
|
||||||
}
|
}
|
||||||
if (!ok)
|
if (!ok)
|
||||||
throw new IOException("Error reading ObjStm");
|
throw new InvalidPdfException("Error reading ObjStm");
|
||||||
tokens.Seek(address);
|
tokens.Seek(address);
|
||||||
return ReadPRObject();
|
return ReadPRObject();
|
||||||
}
|
}
|
||||||
|
@ -1123,8 +1133,8 @@ namespace iTextSharp.text.pdf {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal void ReadObjStm(PRStream stream, IntHashtable map) {
|
protected internal void ReadObjStm(PRStream stream, IntHashtable map) {
|
||||||
int first = ((PdfNumber)GetPdfObject(stream.Get(PdfName.FIRST))).IntValue;
|
int first = stream.GetAsNumber(PdfName.FIRST).IntValue;
|
||||||
int n = ((PdfNumber)GetPdfObject(stream.Get(PdfName.N))).IntValue;
|
int n = stream.GetAsNumber(PdfName.N).IntValue;
|
||||||
byte[] b = GetStreamBytes(stream, tokens.File);
|
byte[] b = GetStreamBytes(stream, tokens.File);
|
||||||
PRTokeniser saveTokens = tokens;
|
PRTokeniser saveTokens = tokens;
|
||||||
tokens = new PRTokeniser(b);
|
tokens = new PRTokeniser(b);
|
||||||
|
@ -1151,7 +1161,7 @@ namespace iTextSharp.text.pdf {
|
||||||
address[k] = tokens.IntValue + first;
|
address[k] = tokens.IntValue + first;
|
||||||
}
|
}
|
||||||
if (!ok)
|
if (!ok)
|
||||||
throw new IOException("Error reading ObjStm");
|
throw new InvalidPdfException("Error reading ObjStm");
|
||||||
for (int k = 0; k < n; ++k) {
|
for (int k = 0; k < n; ++k) {
|
||||||
if (map.ContainsKey(k)) {
|
if (map.ContainsKey(k)) {
|
||||||
tokens.Seek(address[k]);
|
tokens.Seek(address[k]);
|
||||||
|
@ -1206,10 +1216,10 @@ namespace iTextSharp.text.pdf {
|
||||||
tokens.Seek(tokens.Startxref);
|
tokens.Seek(tokens.Startxref);
|
||||||
tokens.NextToken();
|
tokens.NextToken();
|
||||||
if (!tokens.StringValue.Equals("startxref"))
|
if (!tokens.StringValue.Equals("startxref"))
|
||||||
throw new IOException("startxref not found.");
|
throw new InvalidPdfException("startxref not found.");
|
||||||
tokens.NextToken();
|
tokens.NextToken();
|
||||||
if (tokens.TokenType != PRTokeniser.TK_NUMBER)
|
if (tokens.TokenType != PRTokeniser.TK_NUMBER)
|
||||||
throw new IOException("startxref is not followed by a number.");
|
throw new InvalidPdfException("startxref is not followed by a number.");
|
||||||
int startxref = tokens.IntValue;
|
int startxref = tokens.IntValue;
|
||||||
lastXref = startxref;
|
lastXref = startxref;
|
||||||
eofPos = tokens.FilePointer;
|
eofPos = tokens.FilePointer;
|
||||||
|
@ -1258,7 +1268,7 @@ namespace iTextSharp.text.pdf {
|
||||||
pos = tokens.IntValue;
|
pos = tokens.IntValue;
|
||||||
tokens.NextValidToken();
|
tokens.NextValidToken();
|
||||||
gen = tokens.IntValue;
|
gen = tokens.IntValue;
|
||||||
if (pos == 0 && gen == 65535) {
|
if (pos == 0 && gen == PdfWriter.GENERATION_MAX) {
|
||||||
--start;
|
--start;
|
||||||
--end;
|
--end;
|
||||||
}
|
}
|
||||||
|
@ -1357,14 +1367,12 @@ namespace iTextSharp.text.pdf {
|
||||||
objStmToOffset = new IntHashtable();
|
objStmToOffset = new IntHashtable();
|
||||||
byte[] b = GetStreamBytes(stm, tokens.File);
|
byte[] b = GetStreamBytes(stm, tokens.File);
|
||||||
int bptr = 0;
|
int bptr = 0;
|
||||||
ArrayList wa = w.ArrayList;
|
|
||||||
int[] wc = new int[3];
|
int[] wc = new int[3];
|
||||||
for (int k = 0; k < 3; ++k)
|
for (int k = 0; k < 3; ++k)
|
||||||
wc[k] = ((PdfNumber)wa[k]).IntValue;
|
wc[k] = w.GetAsNumber(k).IntValue;
|
||||||
ArrayList sections = index.ArrayList;
|
for (int idx = 0; idx < index.Size; idx += 2) {
|
||||||
for (int idx = 0; idx < sections.Count; idx += 2) {
|
int start = index.GetAsNumber(idx).IntValue;
|
||||||
int start = ((PdfNumber)sections[idx]).IntValue;
|
int length = index.GetAsNumber(idx + 1).IntValue;
|
||||||
int length = ((PdfNumber)sections[idx + 1]).IntValue;
|
|
||||||
EnsureXrefSize((start + length) * 2);
|
EnsureXrefSize((start + length) * 2);
|
||||||
while (length-- > 0) {
|
while (length-- > 0) {
|
||||||
int type = 1;
|
int type = 1;
|
||||||
|
@ -1469,7 +1477,7 @@ namespace iTextSharp.text.pdf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (trailer == null)
|
if (trailer == null)
|
||||||
throw new IOException("trailer not found.");
|
throw new InvalidPdfException("trailer not found.");
|
||||||
xref = new int[top * 2];
|
xref = new int[top * 2];
|
||||||
for (int k = 0; k < top; ++k) {
|
for (int k = 0; k < top; ++k) {
|
||||||
int[] obj = xr[k];
|
int[] obj = xr[k];
|
||||||
|
@ -1512,15 +1520,27 @@ namespace iTextSharp.text.pdf {
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Track how deeply nested the current object is, so
|
||||||
|
// we know when to return an individual null or boolean, or
|
||||||
|
// reuse one of the static ones.
|
||||||
|
private int readDepth = 0;
|
||||||
|
|
||||||
protected internal PdfObject ReadPRObject() {
|
protected internal PdfObject ReadPRObject() {
|
||||||
tokens.NextValidToken();
|
tokens.NextValidToken();
|
||||||
int type = tokens.TokenType;
|
int type = tokens.TokenType;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PRTokeniser.TK_START_DIC: {
|
case PRTokeniser.TK_START_DIC: {
|
||||||
|
++readDepth;
|
||||||
PdfDictionary dic = ReadDictionary();
|
PdfDictionary dic = ReadDictionary();
|
||||||
|
--readDepth;
|
||||||
int pos = tokens.FilePointer;
|
int pos = tokens.FilePointer;
|
||||||
// be careful in the trailer. May not be a "next" token.
|
// be careful in the trailer. May not be a "next" token.
|
||||||
if (tokens.NextToken() && tokens.StringValue.Equals("stream")) {
|
bool hasNext;
|
||||||
|
do {
|
||||||
|
hasNext = tokens.NextToken();
|
||||||
|
} while (hasNext && tokens.TokenType == PRTokeniser.TK_COMMENT);
|
||||||
|
|
||||||
|
if (hasNext && tokens.StringValue.Equals("stream")) {
|
||||||
//skip whitespaces
|
//skip whitespaces
|
||||||
int ch;
|
int ch;
|
||||||
do {
|
do {
|
||||||
|
@ -1541,8 +1561,12 @@ namespace iTextSharp.text.pdf {
|
||||||
return dic;
|
return dic;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case PRTokeniser.TK_START_ARRAY:
|
case PRTokeniser.TK_START_ARRAY: {
|
||||||
return ReadArray();
|
++readDepth;
|
||||||
|
PdfArray arr = ReadArray();
|
||||||
|
--readDepth;
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
case PRTokeniser.TK_NUMBER:
|
case PRTokeniser.TK_NUMBER:
|
||||||
return new PdfNumber(tokens.StringValue);
|
return new PdfNumber(tokens.StringValue);
|
||||||
case PRTokeniser.TK_STRING:
|
case PRTokeniser.TK_STRING:
|
||||||
|
@ -1551,20 +1575,39 @@ namespace iTextSharp.text.pdf {
|
||||||
if (strings != null)
|
if (strings != null)
|
||||||
strings.Add(str);
|
strings.Add(str);
|
||||||
return str;
|
return str;
|
||||||
case PRTokeniser.TK_NAME:
|
case PRTokeniser.TK_NAME: {
|
||||||
return new PdfName(tokens.StringValue, false);
|
PdfName cachedName = (PdfName)PdfName.staticNames[tokens.StringValue];
|
||||||
|
if (readDepth > 0 && cachedName != null) {
|
||||||
|
return cachedName;
|
||||||
|
} else {
|
||||||
|
// an indirect name (how odd...), or a non-standard one
|
||||||
|
return new PdfName(tokens.StringValue, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
case PRTokeniser.TK_REF:
|
case PRTokeniser.TK_REF:
|
||||||
int num = tokens.Reference;
|
int num = tokens.Reference;
|
||||||
PRIndirectReference refi = new PRIndirectReference(this, num, tokens.Generation);
|
PRIndirectReference refi = new PRIndirectReference(this, num, tokens.Generation);
|
||||||
return refi;
|
return refi;
|
||||||
default:
|
default:
|
||||||
String sv = tokens.StringValue;
|
String sv = tokens.StringValue;
|
||||||
if ("null".Equals(sv))
|
if ("null".Equals(sv)) {
|
||||||
|
if (readDepth == 0) {
|
||||||
|
return new PdfNull();
|
||||||
|
} //else
|
||||||
return PdfNull.PDFNULL;
|
return PdfNull.PDFNULL;
|
||||||
else if ("true".Equals(sv))
|
}
|
||||||
|
else if ("true".Equals(sv)) {
|
||||||
|
if (readDepth == 0) {
|
||||||
|
return new PdfBoolean( true );
|
||||||
|
} //else
|
||||||
return PdfBoolean.PDFTRUE;
|
return PdfBoolean.PDFTRUE;
|
||||||
else if ("false".Equals(sv))
|
}
|
||||||
|
else if ("false".Equals(sv)) {
|
||||||
|
if (readDepth == 0) {
|
||||||
|
return new PdfBoolean( false );
|
||||||
|
} //else
|
||||||
return PdfBoolean.PDFFALSE;
|
return PdfBoolean.PDFFALSE;
|
||||||
|
}
|
||||||
return new PdfLiteral(-type, tokens.StringValue);
|
return new PdfLiteral(-type, tokens.StringValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1891,15 +1934,14 @@ namespace iTextSharp.text.pdf {
|
||||||
}
|
}
|
||||||
else if (contents.IsArray()) {
|
else if (contents.IsArray()) {
|
||||||
PdfArray array = (PdfArray)contents;
|
PdfArray array = (PdfArray)contents;
|
||||||
ArrayList list = array.ArrayList;
|
|
||||||
bout = new MemoryStream();
|
bout = new MemoryStream();
|
||||||
for (int k = 0; k < list.Count; ++k) {
|
for (int k = 0; k < array.Size; ++k) {
|
||||||
PdfObject item = GetPdfObjectRelease((PdfObject)list[k]);
|
PdfObject item = GetPdfObjectRelease(array[k]);
|
||||||
if (item == null || !item.IsStream())
|
if (item == null || !item.IsStream())
|
||||||
continue;
|
continue;
|
||||||
byte[] b = GetStreamBytes((PRStream)item, file);
|
byte[] b = GetStreamBytes((PRStream)item, file);
|
||||||
bout.Write(b, 0, b.Length);
|
bout.Write(b, 0, b.Length);
|
||||||
if (k != list.Count - 1)
|
if (k != array.Size - 1)
|
||||||
bout.WriteByte((byte)'\n');
|
bout.WriteByte((byte)'\n');
|
||||||
}
|
}
|
||||||
return bout.ToArray();
|
return bout.ToArray();
|
||||||
|
@ -1939,9 +1981,9 @@ namespace iTextSharp.text.pdf {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PdfObject.ARRAY: {
|
case PdfObject.ARRAY: {
|
||||||
ArrayList t = ((PdfArray)obj).ArrayList;
|
PdfArray t = (PdfArray)obj;
|
||||||
for (int i = 0; i < t.Count; ++i)
|
for (int i = 0; i < t.Size; ++i)
|
||||||
KillXref((PdfObject)t[i]);
|
KillXref(t[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PdfObject.STREAM:
|
case PdfObject.STREAM:
|
||||||
|
@ -2036,7 +2078,7 @@ namespace iTextSharp.text.pdf {
|
||||||
else if (name.Equals("/Crypt")) {
|
else if (name.Equals("/Crypt")) {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw new IOException("The filter " + name + " is not supported.");
|
throw new UnsupportedPdfException("The filter " + name + " is not supported.");
|
||||||
}
|
}
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
@ -2144,9 +2186,8 @@ namespace iTextSharp.text.pdf {
|
||||||
}
|
}
|
||||||
else if (contents.IsArray()) {
|
else if (contents.IsArray()) {
|
||||||
PdfArray array = (PdfArray)contents;
|
PdfArray array = (PdfArray)contents;
|
||||||
ArrayList list = array.ArrayList;
|
for (int j = 0; j < array.Size; ++j) {
|
||||||
for (int j = 0; j < list.Count; ++j) {
|
PRIndirectReference refi = (PRIndirectReference)array[j];
|
||||||
PRIndirectReference refi = (PRIndirectReference)list[j];
|
|
||||||
if (visited.ContainsKey(refi.Number)) {
|
if (visited.ContainsKey(refi.Number)) {
|
||||||
// need to duplicate
|
// need to duplicate
|
||||||
newRefs.Add(refi);
|
newRefs.Add(refi);
|
||||||
|
@ -2356,20 +2397,19 @@ namespace iTextSharp.text.pdf {
|
||||||
dic.Put(PdfName.BASEFONT, newName);
|
dic.Put(PdfName.BASEFONT, newName);
|
||||||
SetXrefPartialObject(k, dic);
|
SetXrefPartialObject(k, dic);
|
||||||
++total;
|
++total;
|
||||||
PdfDictionary fd = (PdfDictionary)GetPdfObject(dic.Get(PdfName.FONTDESCRIPTOR));
|
PdfDictionary fd = dic.GetAsDict(PdfName.FONTDESCRIPTOR);
|
||||||
if (fd == null)
|
if (fd == null)
|
||||||
continue;
|
continue;
|
||||||
fd.Put(PdfName.FONTNAME, newName);
|
fd.Put(PdfName.FONTNAME, newName);
|
||||||
}
|
}
|
||||||
else if (ExistsName(dic, PdfName.SUBTYPE, PdfName.TYPE0)) {
|
else if (ExistsName(dic, PdfName.SUBTYPE, PdfName.TYPE0)) {
|
||||||
String s = GetSubsetPrefix(dic);
|
String s = GetSubsetPrefix(dic);
|
||||||
PdfArray arr = (PdfArray)GetPdfObject(dic.Get(PdfName.DESCENDANTFONTS));
|
PdfArray arr = dic.GetAsArray(PdfName.DESCENDANTFONTS);
|
||||||
if (arr == null)
|
if (arr == null)
|
||||||
continue;
|
continue;
|
||||||
ArrayList list = arr.ArrayList;
|
if (arr.IsEmpty())
|
||||||
if (list.Count == 0)
|
|
||||||
continue;
|
continue;
|
||||||
PdfDictionary desc = (PdfDictionary)GetPdfObject((PdfObject)list[0]);
|
PdfDictionary desc = arr.GetAsDict(0);
|
||||||
String sde = GetSubsetPrefix(desc);
|
String sde = GetSubsetPrefix(desc);
|
||||||
if (sde == null)
|
if (sde == null)
|
||||||
continue;
|
continue;
|
||||||
|
@ -2380,7 +2420,7 @@ namespace iTextSharp.text.pdf {
|
||||||
PdfName newName = new PdfName(ns + sde.Substring(7));
|
PdfName newName = new PdfName(ns + sde.Substring(7));
|
||||||
desc.Put(PdfName.BASEFONT, newName);
|
desc.Put(PdfName.BASEFONT, newName);
|
||||||
++total;
|
++total;
|
||||||
PdfDictionary fd = (PdfDictionary)GetPdfObject(desc.Get(PdfName.FONTDESCRIPTOR));
|
PdfDictionary fd = desc.GetAsDict(PdfName.FONTDESCRIPTOR);
|
||||||
if (fd == null)
|
if (fd == null)
|
||||||
continue;
|
continue;
|
||||||
fd.Put(PdfName.FONTNAME, newName);
|
fd.Put(PdfName.FONTNAME, newName);
|
||||||
|
@ -2417,7 +2457,7 @@ namespace iTextSharp.text.pdf {
|
||||||
if (fd.Get(PdfName.FONTFILE) == null && fd.Get(PdfName.FONTFILE2) == null
|
if (fd.Get(PdfName.FONTFILE) == null && fd.Get(PdfName.FONTFILE2) == null
|
||||||
&& fd.Get(PdfName.FONTFILE3) == null)
|
&& fd.Get(PdfName.FONTFILE3) == null)
|
||||||
continue;
|
continue;
|
||||||
fd = (PdfDictionary)GetPdfObject(dic.Get(PdfName.FONTDESCRIPTOR));
|
fd = dic.GetAsDict(PdfName.FONTDESCRIPTOR);
|
||||||
PdfName newName = new PdfName(ns);
|
PdfName newName = new PdfName(ns);
|
||||||
dic.Put(PdfName.BASEFONT, newName);
|
dic.Put(PdfName.BASEFONT, newName);
|
||||||
fd.Put(PdfName.FONTNAME, newName);
|
fd.Put(PdfName.FONTNAME, newName);
|
||||||
|
@ -2450,7 +2490,18 @@ namespace iTextSharp.text.pdf {
|
||||||
* @return gets all the named destinations
|
* @return gets all the named destinations
|
||||||
*/
|
*/
|
||||||
public Hashtable GetNamedDestination() {
|
public Hashtable GetNamedDestination() {
|
||||||
Hashtable names = GetNamedDestinationFromNames();
|
return GetNamedDestination(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all the named destinations as an <CODE>HashMap</CODE>. The key is the name
|
||||||
|
* and the value is the destinations array.
|
||||||
|
* @param keepNames true if you want the keys to be real PdfNames instead of Strings
|
||||||
|
* @return gets all the named destinations
|
||||||
|
* @since 2.1.6
|
||||||
|
*/
|
||||||
|
public Hashtable GetNamedDestination(bool keepNames) {
|
||||||
|
Hashtable names = GetNamedDestinationFromNames(keepNames);
|
||||||
Hashtable names2 = GetNamedDestinationFromStrings();
|
Hashtable names2 = GetNamedDestinationFromStrings();
|
||||||
foreach (DictionaryEntry ie in names2)
|
foreach (DictionaryEntry ie in names2)
|
||||||
names[ie.Key] = ie.Value;
|
names[ie.Key] = ie.Value;
|
||||||
|
@ -2463,16 +2514,33 @@ namespace iTextSharp.text.pdf {
|
||||||
* @return gets the named destinations
|
* @return gets the named destinations
|
||||||
*/
|
*/
|
||||||
public Hashtable GetNamedDestinationFromNames() {
|
public Hashtable GetNamedDestinationFromNames() {
|
||||||
|
return GetNamedDestinationFromNames(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the named destinations from the /Dests key in the catalog as an <CODE>HashMap</CODE>. The key is the name
|
||||||
|
* and the value is the destinations array.
|
||||||
|
* @param keepNames true if you want the keys to be real PdfNames instead of Strings
|
||||||
|
* @return gets the named destinations
|
||||||
|
* @since 2.1.6
|
||||||
|
*/
|
||||||
|
public Hashtable GetNamedDestinationFromNames(bool keepNames) {
|
||||||
Hashtable names = new Hashtable();
|
Hashtable names = new Hashtable();
|
||||||
if (catalog.Get(PdfName.DESTS) != null) {
|
if (catalog.Get(PdfName.DESTS) != null) {
|
||||||
PdfDictionary dic = (PdfDictionary)GetPdfObjectRelease(catalog.Get(PdfName.DESTS));
|
PdfDictionary dic = (PdfDictionary)GetPdfObjectRelease(catalog.Get(PdfName.DESTS));
|
||||||
if (dic == null)
|
if (dic == null)
|
||||||
return names;
|
return names;
|
||||||
foreach (PdfName key in dic.Keys) {
|
foreach (PdfName key in dic.Keys) {
|
||||||
String name = PdfName.DecodeName(key.ToString());
|
|
||||||
PdfArray arr = GetNameArray(dic.Get(key));
|
PdfArray arr = GetNameArray(dic.Get(key));
|
||||||
if (arr != null)
|
if (arr == null)
|
||||||
|
continue;
|
||||||
|
if (keepNames) {
|
||||||
|
names[key] = arr;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String name = PdfName.DecodeName(key.ToString());
|
||||||
names[name] = arr;
|
names[name] = arr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
|
@ -2512,10 +2580,10 @@ namespace iTextSharp.text.pdf {
|
||||||
ReleaseLastXrefPartial();
|
ReleaseLastXrefPartial();
|
||||||
if (obj != null && obj.IsDictionary()) {
|
if (obj != null && obj.IsDictionary()) {
|
||||||
PdfObject ob2 = GetPdfObjectRelease(((PdfDictionary)obj).Get(PdfName.DEST));
|
PdfObject ob2 = GetPdfObjectRelease(((PdfDictionary)obj).Get(PdfName.DEST));
|
||||||
String name = null;
|
Object name = null;
|
||||||
if (ob2 != null) {
|
if (ob2 != null) {
|
||||||
if (ob2.IsName())
|
if (ob2.IsName())
|
||||||
name = PdfName.DecodeName(ob2.ToString());
|
name = ob2;
|
||||||
else if (ob2.IsString())
|
else if (ob2.IsString())
|
||||||
name = ob2.ToString();
|
name = ob2.ToString();
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
|
@ -2536,7 +2604,7 @@ namespace iTextSharp.text.pdf {
|
||||||
PdfObject ob3 = GetPdfObjectRelease(dic.Get(PdfName.D));
|
PdfObject ob3 = GetPdfObjectRelease(dic.Get(PdfName.D));
|
||||||
if (ob3 != null) {
|
if (ob3 != null) {
|
||||||
if (ob3.IsName())
|
if (ob3.IsName())
|
||||||
name = PdfName.DecodeName(ob3.ToString());
|
name = ob3;
|
||||||
else if (ob3.IsString())
|
else if (ob3.IsString())
|
||||||
name = ob3.ToString();
|
name = ob3.ToString();
|
||||||
}
|
}
|
||||||
|
@ -2562,21 +2630,20 @@ namespace iTextSharp.text.pdf {
|
||||||
pageRefs.ResetReleasePage();
|
pageRefs.ResetReleasePage();
|
||||||
for (int k = 1; k <= pageRefs.Size; ++k) {
|
for (int k = 1; k <= pageRefs.Size; ++k) {
|
||||||
PdfDictionary page = pageRefs.GetPageN(k);
|
PdfDictionary page = pageRefs.GetPageN(k);
|
||||||
PdfArray annots = (PdfArray)GetPdfObject(page.Get(PdfName.ANNOTS));
|
PdfArray annots = page.GetAsArray(PdfName.ANNOTS);
|
||||||
if (annots == null) {
|
if (annots == null) {
|
||||||
pageRefs.ReleasePage(k);
|
pageRefs.ReleasePage(k);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ArrayList arr = annots.ArrayList;
|
for (int j = 0; j < annots.Size; ++j) {
|
||||||
for (int j = 0; j < arr.Count; ++j) {
|
PdfObject obj = GetPdfObjectRelease((PdfObject)annots[j]);
|
||||||
PdfObject obj = GetPdfObjectRelease((PdfObject)arr[j]);
|
|
||||||
if (obj == null || !obj.IsDictionary())
|
if (obj == null || !obj.IsDictionary())
|
||||||
continue;
|
continue;
|
||||||
PdfDictionary annot = (PdfDictionary)obj;
|
PdfDictionary annot = (PdfDictionary)obj;
|
||||||
if (PdfName.WIDGET.Equals(annot.Get(PdfName.SUBTYPE)))
|
if (PdfName.WIDGET.Equals(annot.Get(PdfName.SUBTYPE)))
|
||||||
arr.RemoveAt(j--);
|
annots.Remove(j--);
|
||||||
}
|
}
|
||||||
if (arr.Count == 0)
|
if (annots.IsEmpty())
|
||||||
page.Remove(PdfName.ANNOTS);
|
page.Remove(PdfName.ANNOTS);
|
||||||
else
|
else
|
||||||
pageRefs.ReleasePage(k);
|
pageRefs.ReleasePage(k);
|
||||||
|
@ -2606,10 +2673,9 @@ namespace iTextSharp.text.pdf {
|
||||||
ArrayList result = new ArrayList();
|
ArrayList result = new ArrayList();
|
||||||
PdfDictionary pageDic = pageRefs.GetPageN(page);
|
PdfDictionary pageDic = pageRefs.GetPageN(page);
|
||||||
if (pageDic.Get(PdfName.ANNOTS) != null) {
|
if (pageDic.Get(PdfName.ANNOTS) != null) {
|
||||||
PdfArray annots = (PdfArray)GetPdfObject(pageDic.Get(PdfName.ANNOTS));
|
PdfArray annots = pageDic.GetAsArray(PdfName.ANNOTS);
|
||||||
ArrayList arr = annots.ArrayList;
|
for (int j = 0; j < annots.Size; ++j) {
|
||||||
for (int j = 0; j < arr.Count; ++j) {
|
PdfDictionary annot = (PdfDictionary)GetPdfObjectRelease(annots[j]);
|
||||||
PdfDictionary annot = (PdfDictionary)GetPdfObjectRelease((PdfObject)arr[j]);
|
|
||||||
|
|
||||||
if (PdfName.LINK.Equals(annot.Get(PdfName.SUBTYPE))) {
|
if (PdfName.LINK.Equals(annot.Get(PdfName.SUBTYPE))) {
|
||||||
result.Add(new PdfAnnotation.PdfImportedLink(annot));
|
result.Add(new PdfAnnotation.PdfImportedLink(annot));
|
||||||
|
@ -2638,7 +2704,7 @@ namespace iTextSharp.text.pdf {
|
||||||
if (consolidateNamedDestinations)
|
if (consolidateNamedDestinations)
|
||||||
return;
|
return;
|
||||||
consolidateNamedDestinations = true;
|
consolidateNamedDestinations = true;
|
||||||
Hashtable names = GetNamedDestination();
|
Hashtable names = GetNamedDestination(true);
|
||||||
if (names.Count == 0)
|
if (names.Count == 0)
|
||||||
return;
|
return;
|
||||||
for (int k = 1; k <= pageRefs.Size; ++k) {
|
for (int k = 1; k <= pageRefs.Size; ++k) {
|
||||||
|
@ -2651,10 +2717,9 @@ namespace iTextSharp.text.pdf {
|
||||||
pageRefs.ReleasePage(k);
|
pageRefs.ReleasePage(k);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ArrayList list = annots.ArrayList;
|
|
||||||
bool commitAnnots = false;
|
bool commitAnnots = false;
|
||||||
for (int an = 0; an < list.Count; ++an) {
|
for (int an = 0; an < annots.Size; ++an) {
|
||||||
PdfObject objRef = (PdfObject)list[an];
|
PdfObject objRef = annots[an];
|
||||||
if (ReplaceNamedDestination(objRef, names) && !objRef.IsIndirect())
|
if (ReplaceNamedDestination(objRef, names) && !objRef.IsIndirect())
|
||||||
commitAnnots = true;
|
commitAnnots = true;
|
||||||
}
|
}
|
||||||
|
@ -2692,10 +2757,9 @@ namespace iTextSharp.text.pdf {
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
case PdfObject.ARRAY: {
|
case PdfObject.ARRAY: {
|
||||||
ArrayList list = ((PdfArray)original).ArrayList;
|
|
||||||
PdfArray arr = new PdfArray();
|
PdfArray arr = new PdfArray();
|
||||||
foreach (PdfObject ob in list) {
|
for (ListIterator it = ((PdfArray)original).GetListIterator(); it.HasNext();) {
|
||||||
arr.Add(DuplicatePdfObject(ob, newReader));
|
arr.Add(DuplicatePdfObject((PdfObject)it.Next(), newReader));
|
||||||
}
|
}
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
@ -2950,6 +3014,8 @@ namespace iTextSharp.text.pdf {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns a bitset representing the PageMode and PageLayout viewer preferences.
|
||||||
|
* Doesn't return any information about the ViewerPreferences dictionary.
|
||||||
* @return an int that contains the Viewer Preferences.
|
* @return an int that contains the Viewer Preferences.
|
||||||
*/
|
*/
|
||||||
public virtual int SimpleViewerPreferences {
|
public virtual int SimpleViewerPreferences {
|
||||||
|
@ -3196,7 +3262,7 @@ namespace iTextSharp.text.pdf {
|
||||||
|
|
||||||
private void IteratePages(PRIndirectReference rpage) {
|
private void IteratePages(PRIndirectReference rpage) {
|
||||||
PdfDictionary page = (PdfDictionary)GetPdfObject(rpage);
|
PdfDictionary page = (PdfDictionary)GetPdfObject(rpage);
|
||||||
PdfArray kidsPR = (PdfArray)GetPdfObject(page.Get(PdfName.KIDS));
|
PdfArray kidsPR = page.GetAsArray(PdfName.KIDS);
|
||||||
if (kidsPR == null) {
|
if (kidsPR == null) {
|
||||||
page.Put(PdfName.TYPE, PdfName.PAGE);
|
page.Put(PdfName.TYPE, PdfName.PAGE);
|
||||||
PdfDictionary dic = (PdfDictionary)pageInh[pageInh.Count - 1];
|
PdfDictionary dic = (PdfDictionary)pageInh[pageInh.Count - 1];
|
||||||
|
@ -3213,12 +3279,11 @@ namespace iTextSharp.text.pdf {
|
||||||
else {
|
else {
|
||||||
page.Put(PdfName.TYPE, PdfName.PAGES);
|
page.Put(PdfName.TYPE, PdfName.PAGES);
|
||||||
PushPageAttributes(page);
|
PushPageAttributes(page);
|
||||||
ArrayList kids = kidsPR.ArrayList;
|
for (int k = 0; k < kidsPR.Size; ++k){
|
||||||
for (int k = 0; k < kids.Count; ++k){
|
PdfObject obj = kidsPR[k];
|
||||||
PdfObject obj = (PdfObject)kids[k];
|
|
||||||
if (!obj.IsIndirect()) {
|
if (!obj.IsIndirect()) {
|
||||||
while (k < kids.Count)
|
while (k < kidsPR.Size)
|
||||||
kids.RemoveAt(k);
|
kidsPR.Remove(k);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
IteratePages((PRIndirectReference)obj);
|
IteratePages((PRIndirectReference)obj);
|
||||||
|
@ -3323,7 +3388,7 @@ namespace iTextSharp.text.pdf {
|
||||||
* confuse Acrobat and it's advisabe to remove them altogether.
|
* confuse Acrobat and it's advisabe to remove them altogether.
|
||||||
*/
|
*/
|
||||||
public void RemoveUsageRights() {
|
public void RemoveUsageRights() {
|
||||||
PdfDictionary perms = (PdfDictionary)GetPdfObject(catalog.Get(PdfName.PERMS));
|
PdfDictionary perms = catalog.GetAsDict(PdfName.PERMS);
|
||||||
if (perms == null)
|
if (perms == null)
|
||||||
return;
|
return;
|
||||||
perms.Remove(PdfName.UR);
|
perms.Remove(PdfName.UR);
|
||||||
|
@ -3343,22 +3408,22 @@ namespace iTextSharp.text.pdf {
|
||||||
* @return gets the certification level for this document
|
* @return gets the certification level for this document
|
||||||
*/
|
*/
|
||||||
public int GetCertificationLevel() {
|
public int GetCertificationLevel() {
|
||||||
PdfDictionary dic = (PdfDictionary)GetPdfObject(catalog.Get(PdfName.PERMS));
|
PdfDictionary dic = catalog.GetAsDict(PdfName.PERMS);
|
||||||
if (dic == null)
|
if (dic == null)
|
||||||
return PdfSignatureAppearance.NOT_CERTIFIED;
|
return PdfSignatureAppearance.NOT_CERTIFIED;
|
||||||
dic = (PdfDictionary)GetPdfObject(dic.Get(PdfName.DOCMDP));
|
dic = dic.GetAsDict(PdfName.DOCMDP);
|
||||||
if (dic == null)
|
if (dic == null)
|
||||||
return PdfSignatureAppearance.NOT_CERTIFIED;
|
return PdfSignatureAppearance.NOT_CERTIFIED;
|
||||||
PdfArray arr = (PdfArray)GetPdfObject(dic.Get(PdfName.REFERENCE));
|
PdfArray arr = dic.GetAsArray(PdfName.REFERENCE);
|
||||||
if (arr == null || arr.Size == 0)
|
if (arr == null || arr.Size == 0)
|
||||||
return PdfSignatureAppearance.NOT_CERTIFIED;
|
return PdfSignatureAppearance.NOT_CERTIFIED;
|
||||||
dic = (PdfDictionary)GetPdfObject((PdfObject)(arr.ArrayList[0]));
|
dic = arr.GetAsDict(0);
|
||||||
if (dic == null)
|
if (dic == null)
|
||||||
return PdfSignatureAppearance.NOT_CERTIFIED;
|
return PdfSignatureAppearance.NOT_CERTIFIED;
|
||||||
dic = (PdfDictionary)GetPdfObject(dic.Get(PdfName.TRANSFORMPARAMS));
|
dic = dic.GetAsDict(PdfName.TRANSFORMPARAMS);
|
||||||
if (dic == null)
|
if (dic == null)
|
||||||
return PdfSignatureAppearance.NOT_CERTIFIED;
|
return PdfSignatureAppearance.NOT_CERTIFIED;
|
||||||
PdfNumber p = (PdfNumber)GetPdfObject(dic.Get(PdfName.P));
|
PdfNumber p = dic.GetAsNumber(PdfName.P);
|
||||||
if (p == null)
|
if (p == null)
|
||||||
return PdfSignatureAppearance.NOT_CERTIFIED;
|
return PdfSignatureAppearance.NOT_CERTIFIED;
|
||||||
return p.IntValue;
|
return p.IntValue;
|
||||||
|
|
Loading…
Reference in New Issue