如何使用itextsharp添加pdf文本注释审阅状态

时间:2016-10-13 11:57:11

标签: c# .net json pdf itext

我在c#.net中使用itextsharp。我有多个文本注释和多个回复该注释,一切正常,但当我尝试添加审查状态(例如:接受,拒绝,无等...)到注释。它没有以pdf格式显示。

我从pdf导出了数据文件并进行了检查。注释的审阅状态即将出现在数据文件中。如果我在数据文件中更改了注释审阅状态/ F 28 /到/ F 30 /的状态标志,请在pdf中查看正确显示的状态。

如何将注释的状态标志设置为/ F 30 /。我在itextsharp / F 30中尝试了所有注释标志/未来。

导出的pdf数据文件中的注释标记

2 0 obj /Contents(brit mkt level 1 no 5)/F 28/M(D:20160928170753+05'30') NM(1888890568)/Page 0/Rect[231.0 605.0 249.0 625.0]/Subtype/Text/T(BM/01 Britania marketing | Marketing)

导出的pd数据文件中的注释状态审阅标记

7 0 obj /Contents(None by Britania commercial)/F 28/IRT(1888890568)/M(D:20161006111625+05'30')/NM(63aafcf6-742e-4ffb-9465-2dba3c731bf2)/Page 0/Popup 8 0 R/Rect[231.0 605.0 249.0 625.0]/State(None)/StateModel(Review)/Subtype/Text/T(Britania commercial) endobj 

8 0 obj /F 28/Open false/Page 0/Parent 7 0 R/Rect[2160.0 505.0 2340.0 625.0]/Subtype/Popup/Type/Annot endobj

使用的C#代码如下所示。

 var reader = new iTextSharp.text.pdf.PdfReader(originalReader);
             var fout = new MemoryStream();
            if (cmnts.ContainsKey("reviseStatus"))
                {
                    switch (Convert.ToInt16(cmnts["reviseStatus"]))
                    {
                        case 0:
                            reviseStatus = "None";
                            break;
                        case 1:
                            reviseStatus = "Accepted";
                            break;
                        case 2:
                            reviseStatus = "Cancelled";
                            break;
                        case 3:
                            reviseStatus = "Completed";
                            break;
                        case 4:
                            reviseStatus = "Rejected";
                            break;
                        default:
                            reviseStatus = "None";
                            break;
                    }
                    revisedOn = cmnts.ContainsKey("revisedOn") ? cmnts["revisedOn"].ToString() : "";
                    revisedBy = cmnts.ContainsKey("revisedBy") ? cmnts["revisedBy"].ToString() : "";
                }

                if (noteArray.Count == 1)
                {
                    var fstTemp = new MemoryStream();
                    var stamper = new PdfStamper(reader, fstTemp);
                    if (!string.IsNullOrEmpty(reviseStatus))
                    {
                        var writer = stamper.Writer;
                        var page = reader.GetPageN(pageNo);
                        var annots = page.GetAsArray(PdfName.ANNOTS);
                        var count = annots.Size;
                        var notes = (Dictionary<string, object>) noteArray[0];
                        for (var l = 0; l < count; l++)
                        {
                            var sticky = annots.GetAsDict(l);
                            var cmntid = sticky.Get(PdfName.NM);
                            if ((cmntid !=null?cmntid.ToString() : "") == notes["commentId"].ToString())
                            {
                                var stickyRect = sticky.GetAsArray(PdfName.RECT);
                                var stickyRectangle =
                                  new iTextSharp.text.Rectangle(
                                      stickyRect.GetAsNumber(0).FloatValue,
                                      stickyRect.GetAsNumber(1).FloatValue,
                                      stickyRect.GetAsNumber(2).FloatValue,
                                      stickyRect.GetAsNumber(3).FloatValue);
                                var replySticky = PdfAnnotation.CreateText(writer,
                                    stickyRectangle,
                                    revisedBy, reviseStatus + " by " + revisedBy, true, null);
                                replySticky.Put(PdfName.IRT, annots.GetAsIndirectObject(l));
                                replySticky.Put(PdfName.M,new PdfDate(convertTimestamp(Double.Parse(revisedOn))));
                                replySticky.Put(PdfName.STATE, new PdfString(reviseStatus));
                                 var n = sticky.GetAsNumber(PdfName.F);
                                replySticky.Put(PdfName.F, new PdfNumber(n.IntValue |PdfAnnotation.FLAGS_HIDDEN)); //PdfAnnotation.FLAGS_HIDDEN
                                replySticky.Put(PdfName.OPEN,PdfBoolean.PDFFALSE);
                                replySticky.Put(new PdfName("StateModel"), new PdfString("Review"));
                                var canvas = stamper.GetOverContent(pageNo);
                                canvas.AddAnnotation(replySticky,true);
                            }
                        }
                    }
                    fout = fstTemp;
                    stamper.Close();
                    reader = new iTextSharp.text.pdf.PdfReader((byte[]) fout.ToArray());                        
                }

有谁知道怎么做?

提前致谢

SHIJIL

0 个答案:

没有答案