private void LoadHash(long[] addresses) { this.objects = new Hashtable(); int part = 0; int total = addresses.Length; foreach (long add in addresses) { this.ProgressEvent(part, total); this.memory.Seek(add, SeekOrigin.Begin); StreamReader sr = new StreamReader(this.memory); string line = sr.ReadLine(); if (line.Length < 2) { line = sr.ReadLine(); } Match m = Regex.Match(line, @"(?'id'\d+)( )+0 obj", RegexOptions.ExplicitCapture); if (m.Success) { int num = int.Parse(m.Groups["id"].Value); if (!objects.ContainsKey(num)) { objects.Add(num, PdfFileObject.Create(this, num, add)); } } part++; } }
public int Compare(object x, object y) { PdfFileObject a = x as PdfFileObject; PdfFileObject b = y as PdfFileObject; return(a.number.CompareTo(b.number)); }
internal PdfFileStreamObject(PdfFileObject obj) { this.address = obj.address; this.length = obj.length; this.text = obj.text; this.number = obj.number; this.PdfFile = obj.PdfFile; this.LoadStreamBuffer(); }
internal static PdfFileObject Create(PdfFile PdfFile, int number, long address) { PdfFileObject pfo = new PdfFileObject(); pfo.PdfFile = PdfFile; pfo.number = number; pfo.address = address; pfo.GetLenght(PdfFile); pfo.LoadText(); if (pfo.Type == PdfObjectType.Stream) { pfo = new PdfFileStreamObject(pfo); } pfo.filterEval = new MatchEvaluator(pfo.FilterEval); return(pfo); }
internal ArrayList GetKids() { ArrayList kids = new ArrayList(); foreach (int id in this.GetArrayNumbers("Kids")) { PdfFileObject pfo = PdfFile.LoadObject(id); if (pfo.Type == PdfObjectType.Page) { kids.Add(pfo); } else { kids.AddRange(pfo.GetKids()); } } return(kids); }
internal void Load(PdfFile PdfFile, int[] PageNumbers, int startNumber) { this.PdfFile = PdfFile; this.pageNumbers = new ArrayList(); this.sObjects = new Hashtable(); int part = 0; int total = PageNumbers.Length; foreach (int PageNumber in PageNumbers) { this.ProgressEvent(part, total); PdfFileObject page = PdfFile.PageList[PageNumber] as PdfFileObject; page.PopulateRelatedObjects(PdfFile, this.sObjects); this.pageNumbers.Add(page.number); part++; } this.transHash = this.CalcTransHash(startNumber); foreach (PdfFileObject pfo in this.sObjects.Values) { pfo.Transform(transHash); } }
internal void PopulateRelatedObjects(PdfFile PdfFile, Hashtable container) { if (!container.ContainsKey(this.number)) { container.Add(this.number, this); Match m = Regex.Match(this.text, @"(?'parent'(/Parent)*)\s*(?'id'\d+) 0 R[^G]", RegexOptions.ExplicitCapture); while (m.Success) { int num = int.Parse(m.Groups["id"].Value); bool notparent = m.Groups["parent"].Length == 0; if (notparent & !container.Contains(num)) { PdfFileObject pfo = PdfFile.LoadObject(num); if (pfo != null & !container.Contains(pfo.number)) { pfo.PopulateRelatedObjects(PdfFile, container); } } m = m.NextMatch(); } } }
internal virtual void Transform(Hashtable TransformationHash) { if (this.Type == PdfObjectType.Page && this.MediaBoxText == "") { PdfFileObject parent = this.Parent; while (parent != null) { string mb = parent.MediaBoxText; if (mb == "") { parent = parent.Parent; } else { this.text = Regex.Replace(this.text, @"/Type\s*/Page", "/Type /Page\r" + mb); parent = null; } } } this.TransformationHash = TransformationHash; this.text = Regex.Replace(this.text , @"(?'id'\d+)(?'rest' 0 (obj|R))(?'end'[^G])", this.filterEval, RegexOptions.ExplicitCapture); this.text = Regex.Replace(this.text, @"/Parent\s+(\d+ 0 R)*", "/Parent 2 0 R \r"); }
internal static PdfFileObject Create(PdfFile PdfFile, int number, long address) { PdfFileObject pfo = new PdfFileObject(); pfo.PdfFile = PdfFile; pfo.number = number; pfo.address = address; pfo.GetLenght(PdfFile); pfo.LoadText(); if (pfo.Type == PdfObjectType.Stream) { pfo = new PdfFileStreamObject(pfo); } pfo.filterEval=new MatchEvaluator(pfo.FilterEval); return pfo; }