0

I am working using itextsharp in c# .net. I have multiple text annotation and multiple reply to that annotation, everything working fine but when i try to add review status (Eg: Accepted,Rejected,None etc..) to the annotation. It is not showing in pdf.

I had export the data file from pdf and checked. Annotation's review status is coming in data file. If i changed the status flag of annotation review status /F 28/ to /F 30/ in data file,review status showing correctly in pdf.

How do i set status flag of annotation as /F 30/. I tried all annotation flag in itextsharp /F 30/ not coming.

Annotation tag in exported pdf data file

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)

Annotation status review tag in exported pd data file

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# code used is given below.

 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());                        
                }

Does anyone know how to do it?

Thanks in advance

SHIJIL

  • Did you read the answer to this question: http://stackoverflow.com/questions/37652181 – Bruno Lowagie Oct 15 '16 at 11:23
  • @BrunoLowagie:Thank you for your reply. Yes, I read the answer you posted and used the same code given in the example.Only difference is i had used PdfContentByte for adding annotation. I didn't understand where it went wrong. – Shijil Kailas Oct 17 '16 at 05:11

0 Answers0