Ejemplo n.º 1
0
        private void mnuSaveStream_Click(object sender, EventArgs e)
        {
            var trg = tvPdfDoc.SelectedNode;

            if (trg == null || trg.Tag == null || key_ == 0)
            {
                return;
            }
            var idx    = (trg.Tag as ObjInfo).idx_;
            var stmlen = PdfAnal.analObjStream(key_, idx);

            if (stmlen == 0)
            {
                return;
            }
            var stmbuf = new byte[stmlen];

            PdfAnal.getBuff(key_, stmbuf);
            var sfd = new SaveFileDialog();

            sfd.FileName = Path.GetFileNameWithoutExtension(fname_) + "_obj" + idx.ToString() + ".txt";
            if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            using (var fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write)) {
                fs.Write(stmbuf, 0, stmbuf.Length);
            }
        }
Ejemplo n.º 2
0
        private void mnuOpen_Click(object sender, EventArgs e)
        {
            var ofn = new OpenFileDialog();

            ofn.Filter = "PDF Document(*.pdf)|*.pdf";
            if (ofn.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            if (key_ != 0)
            {
                PdfAnal.closeDocument(key_);
                GC.Collect();
                key_ = 0;
                tvPdfDoc.Nodes.Clear();
            }

            fname_    = ofn.FileName;
            this.Text = fname_;
            key_      = PdfAnal.getPdfDocument(ofn.FileName);
            //MessageBox.Show(key_.ToString());
            Debug.Write(key_.ToString());
            if (key_ == 0)
            {
                return;
            }
            //var len = PdfAnal.analDocument(key_);
            var len = PdfAnal.analPages(key_);
            //MessageBox.Show(len.ToString());
            var buff = new byte[len];             //new StringBuilder((int)len);

            PdfAnal.getBuff(key_, buff);

            var docstr = Encoding.UTF8.GetString(buff);

            var jsr    = new Newtonsoft.Json.JsonReader(new StringReader(docstr));
            var js     = new Newtonsoft.Json.JsonSerializer();
            var jsroot = js.Deserialize(jsr);

            //Action<Object, string, TreeView, TreeNode, bool> jsoFunc = null;
            int lvl = 0;

            tvPdfDoc.Update();
            jsoFunc(jsroot, "", tvPdfDoc, null, false, lvl);
            tvPdfDoc.EndUpdate();
        }
Ejemplo n.º 3
0
        private void tvPdfDoc_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node.Tag == null || key_ == 0)
            {
                return;
            }

            txtStream.Text = string.Empty;
            var idxObj = e.Node.Tag as ObjInfo;
            var idx    = -1;

            if (idxObj != null && idxObj.idx_ >= 0)
            {
                idx = idxObj.idx_;
            }
            else if (chkRefResolve.Checked && idxObj.pdfObj_ != null && idxObj.pdfObj_.ContainsKey("$Type") && idxObj.refresolve_ == false)
            {
                // resolve obj ref;
                var objnum = Convert.ToInt32(idxObj.pdfObj_["num"]);
                idxObj.idx_ = objnum;
                var len  = PdfAnal.analObject(key_, objnum);
                var buff = new byte[len];                 //new StringBuilder((int)len);
                PdfAnal.getBuff(key_, buff);

                var docstr = Encoding.UTF8.GetString(buff);

                var jsr    = new Newtonsoft.Json.JsonReader(new StringReader(docstr));
                var js     = new Newtonsoft.Json.JsonSerializer();
                var jsroot = js.Deserialize(jsr);

                e.Node.Nodes.Clear();
                jsoFunc(jsroot, "", null, e.Node, false, 10);                   // 10は適当

                e.Node.Text = string.Format("{0} ({1} 0 R)", e.Node.Text, objnum);
            }
            else
            {
                return;
            }
            var stmlen = PdfAnal.analObjStream(key_, idx);

            if (stmlen == 0)
            {
                return;
            }
            var stmbuf = new byte[stmlen];

            PdfAnal.getBuff(key_, stmbuf);
            var tmpPath = Path.Combine(Path.GetTempPath(), "pdfanl.tmp");

            using (var tmp = new FileStream(tmpPath, FileMode.Create, FileAccess.Write)) {
                tmp.Write(stmbuf, 0, stmbuf.Length);
            }
            using (var tmp = new StreamReader(tmpPath)) {
                var txtBuf = new StringBuilder();
                while (true)
                {
                    var line = tmp.ReadLine();
                    if (line == null || txtBuf.Length > (2 << 15))
                    {
                        break;
                    }
                    txtBuf.AppendLine(line);
                }
                txtStream.Text = txtBuf.ToString();
            }
        }