本文整理汇总了C#中iTextSharp.text.pdf.PRStream类的典型用法代码示例。如果您正苦于以下问题:C# PRStream类的具体用法?C# PRStream怎么用?C# PRStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PRStream类属于iTextSharp.text.pdf命名空间,在下文中一共展示了PRStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PRStream
public PRStream(PRStream stream, PdfDictionary newDic) {
reader = stream.reader;
offset = stream.offset;
length = stream.Length;
compressed = stream.compressed;
compressionLevel = stream.compressionLevel;
streamBytes = stream.streamBytes;
bytes = stream.bytes;
objNum = stream.objNum;
objGen = stream.objGen;
if (newDic != null)
Merge(newDic);
else
Merge(stream);
}
示例2: SetPageContent
/** Sets the contents of the page.
* @param content the new page content
* @param pageNum the page number. 1 is the first
* @since 2.1.3 (the method already existed without param compressionLevel)
*/
virtual public void SetPageContent(int pageNum, byte[] content, int compressionLevel) {
PdfDictionary page = GetPageN(pageNum);
if (page == null)
return;
PdfObject contents = page.Get(PdfName.CONTENTS);
freeXref = -1;
KillXref(contents);
if (freeXref == -1) {
xrefObj.Add(null);
freeXref = xrefObj.Count - 1;
}
page.Put(PdfName.CONTENTS, new PRIndirectReference(this, freeXref));
xrefObj[freeXref] = new PRStream(this, content, compressionLevel);
}
示例3: ByteStore
internal ByteStore(PRStream str)
{
md5 = HashAlgorithm.Create("MD5");
ByteBuffer bb = new ByteBuffer();
int level = 100;
SerObject(str, level, bb);
this.b = bb.ToByteArray();
md5 = null;
}
示例4: ByteStore
internal ByteStore(PRStream str, Dictionary<RefKey, int> serialized)
{
ByteBuffer bb = new ByteBuffer();
int level = 100;
SerObject(str, level, bb, serialized);
this.b = bb.ToByteArray();
hash = CalculateHash(this.b);
}
示例5: CopyStream
/**
* Translate a PRStream to a PdfStream. The data part copies itself.
*/
protected PdfStream CopyStream(PRStream inp)
{
PRStream outp = new PRStream(inp, null);
foreach (PdfName key in inp.Keys) {
PdfObject value = inp.Get(key);
outp.Put(key, CopyObject(value));
}
return outp;
}
示例6: PdfImageObject
/**
* Creates a PdfImage object.
* @param stream a PRStream
* @param colorSpaceDic a color space dictionary
* @throws IOException
*/
public PdfImageObject(PRStream stream, PdfDictionary colorSpaceDic)
: this(stream, PdfReader.GetStreamBytesRaw(stream), colorSpaceDic)
{
}
示例7: GetStreamBytesRaw
/** Get the content from a stream as it is without applying any filter.
* @param stream the stream
* @throws IOException on error
* @return the stream content
*/
public static byte[] GetStreamBytesRaw(PRStream stream) {
RandomAccessFileOrArray rf = stream.Reader.SafeFile;
try {
rf.ReOpen();
return GetStreamBytesRaw(stream, rf);
}
finally {
try{rf.Close();}catch{}
}
}
示例8: UpdateImageStream
private void UpdateImageStream(PRStream imageStream, byte[] newData) {
PdfImage image = new PdfImage(Image.GetInstance(newData), "", null);
if (imageStream.Contains(PdfName.SMASK)) {
image.Put(PdfName.SMASK, imageStream.Get(PdfName.SMASK));
}
if (imageStream.Contains(PdfName.MASK)) {
image.Put(PdfName.MASK, imageStream.Get(PdfName.MASK));
}
if (imageStream.Contains(PdfName.SMASKINDATA)) {
image.Put(PdfName.SMASKINDATA, imageStream.Get(PdfName.SMASKINDATA));
}
imageStream.Clear();
imageStream.PutAll(image);
imageStream.SetDataRaw(image.GetBytes());
}
示例9: ByteStore
internal ByteStore(PRStream str)
{
md5 = new MD5CryptoServiceProvider();
ByteBuffer bb = new ByteBuffer();
int level = 100;
SerObject(str, level, bb);
this.b = bb.ToByteArray();
md5 = null;
}
示例10: PdfImageObject
/**
* Creates a PdfImage object.
* @param stream a PRStream
* @throws IOException
*/
public PdfImageObject(PRStream stream) : this(stream, iTextSharp.text.pdf.PdfReader.GetStreamBytesRaw(stream), null) {
}
示例11: Parse
/// <summary>
/// Parses a stream object and removes OCGs. </summary>
/// <param name="stream"> a stream object </param>
/// <param name="resources"> the resources dictionary of that object (containing info about the OCGs) </param>
public virtual void Parse(PRStream stream, PdfDictionary resources) {
baos = new MemoryStream();
properties = resources.GetAsDict(PdfName.PROPERTIES);
xobj = new HashSet2<PdfName>();
PdfDictionary xobjects = resources.GetAsDict(PdfName.XOBJECT);
if (xobjects != null) {
// remove XObject (form or image) that belong to an OCG that needs to be removed
foreach (PdfName name in xobjects.Keys) {
PRStream xobject = (PRStream) xobjects.GetAsStream(name);
PdfDictionary oc = xobject.GetAsDict(PdfName.OC);
if (oc != null) {
PdfString ocname = oc.GetAsString(PdfName.NAME);
if (ocname != null && ocgs.Contains(ocname.ToString())) {
xobj.Add(name);
}
}
}
foreach (PdfName name in xobj) {
xobjects.Remove(name);
}
}
// parse the content stream
byte[] contentBytes = PdfReader.GetStreamBytes(stream);
PRTokeniser tokeniser = new PRTokeniser(new RandomAccessFileOrArray(contentBytes));
PdfContentParser ps = new PdfContentParser(tokeniser);
List<PdfObject> operands = new List<PdfObject>();
while (ps.Parse(operands).Count > 0) {
PdfLiteral @operator = (PdfLiteral) operands[operands.Count - 1];
ProcessOperator(this, @operator, operands);
}
baos.Flush();
baos.Close();
stream.SetData(baos.GetBuffer());
}
示例12: ReadOneObjStm
protected internal PdfObject ReadOneObjStm(PRStream stream, int idx) {
int first = stream.GetAsNumber(PdfName.FIRST).IntValue;
byte[] b = GetStreamBytes(stream, tokens.File);
PRTokeniser saveTokens = tokens;
tokens = new PRTokeniser(b);
try {
int address = 0;
bool ok = true;
++idx;
for (int k = 0; k < idx; ++k) {
ok = tokens.NextToken();
if (!ok)
break;
if (tokens.TokenType != PRTokeniser.TK_NUMBER) {
ok = false;
break;
}
ok = tokens.NextToken();
if (!ok)
break;
if (tokens.TokenType != PRTokeniser.TK_NUMBER) {
ok = false;
break;
}
address = tokens.IntValue + first;
}
if (!ok)
throw new InvalidPdfException(MessageLocalization.GetComposedMessage("error.reading.objstm"));
tokens.Seek(address);
return ReadPRObject();
}
finally {
tokens = saveTokens;
}
}
示例13: GetStreamBytes
/** Get the content from a stream applying the required filters.
* @param stream the stream
* @param file the location where the stream is
* @throws IOException on error
* @return the stream content
*/
public static byte[] GetStreamBytes(PRStream stream, RandomAccessFileOrArray file) {
PdfObject filter = GetPdfObjectRelease(stream.Get(PdfName.FILTER));
byte[] b = GetStreamBytesRaw(stream, file);
ArrayList filters = new ArrayList();
if (filter != null) {
if (filter.IsName())
filters.Add(filter);
else if (filter.IsArray())
filters = ((PdfArray)filter).ArrayList;
}
ArrayList dp = new ArrayList();
PdfObject dpo = GetPdfObjectRelease(stream.Get(PdfName.DECODEPARMS));
if (dpo == null || (!dpo.IsDictionary() && !dpo.IsArray()))
dpo = GetPdfObjectRelease(stream.Get(PdfName.DP));
if (dpo != null) {
if (dpo.IsDictionary())
dp.Add(dpo);
else if (dpo.IsArray())
dp = ((PdfArray)dpo).ArrayList;
}
String name;
for (int j = 0; j < filters.Count; ++j) {
name = ((PdfName)GetPdfObjectRelease((PdfObject)filters[j])).ToString();
if (name.Equals("/FlateDecode") || name.Equals("/Fl")) {
b = FlateDecode(b);
PdfObject dicParam = null;
if (j < dp.Count) {
dicParam = (PdfObject)dp[j];
b = DecodePredictor(b, dicParam);
}
}
else if (name.Equals("/ASCIIHexDecode") || name.Equals("/AHx"))
b = ASCIIHexDecode(b);
else if (name.Equals("/ASCII85Decode") || name.Equals("/A85"))
b = ASCII85Decode(b);
else if (name.Equals("/LZWDecode")) {
b = LZWDecode(b);
PdfObject dicParam = null;
if (j < dp.Count) {
dicParam = (PdfObject)dp[j];
b = DecodePredictor(b, dicParam);
}
}
else if (name.Equals("/Crypt")) {
}
else
throw new UnsupportedPdfException(MessageLocalization.GetComposedMessage("the.filter.1.is.not.supported", name));
}
return b;
}
示例14: GetStreamBytes
/** Get the content from a stream applying the required filters.
* @param stream the stream
* @param file the location where the stream is
* @throws IOException on error
* @return the stream content
*/
public static byte[] GetStreamBytes(PRStream stream, RandomAccessFileOrArray file) {
byte[] b = GetStreamBytesRaw(stream, file);
return DecodeBytes(b, stream);
}
示例15: CheckPRStreamLength
private void CheckPRStreamLength(PRStream stream) {
int fileLength = tokens.Length;
int start = stream.Offset;
bool calc = false;
int streamLength = 0;
PdfObject obj = GetPdfObjectRelease(stream.Get(PdfName.LENGTH));
if (obj != null && obj.Type == PdfObject.NUMBER) {
streamLength = ((PdfNumber)obj).IntValue;
if (streamLength + start > fileLength - 20)
calc = true;
else {
tokens.Seek(start + streamLength);
String line = tokens.ReadString(20);
if (!line.StartsWith("\nendstream") &&
!line.StartsWith("\r\nendstream") &&
!line.StartsWith("\rendstream") &&
!line.StartsWith("endstream"))
calc = true;
}
}
else
calc = true;
if (calc) {
byte[] tline = new byte[16];
tokens.Seek(start);
while (true) {
int pos = tokens.FilePointer;
if (!tokens.ReadLineSegment(tline))
break;
if (Equalsn(tline, endstream)) {
streamLength = pos - start;
break;
}
if (Equalsn(tline, endobj)) {
tokens.Seek(pos - 16);
String s = tokens.ReadString(16);
int index = s.IndexOf("endstream");
if (index >= 0)
pos = pos - 16 + index;
streamLength = pos - start;
break;
}
}
}
stream.Length = streamLength;
}