Exemplo n.º 1
0
 protected override void CheckAnnotation(PdfWriter writer, int key, Object obj1)
 {
     if (obj1 is PdfFormField)
     {
         PdfFormField field = (PdfFormField)obj1;
         if (!field.Contains(PdfName.SUBTYPE))
         {
             return;
         }
         if (field.Contains(PdfName.AA) || field.Contains(PdfName.A))
         {
             throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("widget.annotation.dictionary.or.field.dictionary.shall.not.include.a.or.aa.entry"));
         }
     }
     if (obj1 is PdfAnnotation)
     {
         PdfAnnotation annot   = (PdfAnnotation)obj1;
         PdfName       subtype = annot.Get(PdfName.SUBTYPE) as PdfName;
         if (subtype != null && !allowedAnnotTypes.Contains(subtype))
         {
             throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("annotation.type.1.not.allowed", subtype.ToString()));
         }
         PdfNumber ca = annot.GetAsNumber(PdfName.CA);
         if (ca != null && ca.FloatValue != 1.0)
         {
             throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("an.annotation.dictionary.shall.not.contain.the.ca.key.with.a.value.other.than.1"));
         }
         PdfNumber f = annot.GetAsNumber(PdfName.F);
         if (f == null)
         {
             throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("an.annotation.dictionary.shall.contain.the.f.key"));
         }
         int flags = f.IntValue;
         if (CheckFlag(flags, PdfAnnotation.FLAGS_PRINT) == false || CheckFlag(flags, PdfAnnotation.FLAGS_HIDDEN) ||
             CheckFlag(flags, PdfAnnotation.FLAGS_INVISIBLE) || CheckFlag(flags, PdfAnnotation.FLAGS_NOVIEW))
         {
             throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("the.f.keys.print.flag.bit.shall.be.set.to.1.and.its.hidden.invisible.and.noview.flag.bits.shall.be.set.to.0"));
         }
         if (PdfName.TEXT.Equals(annot.GetAsName(PdfName.SUBTYPE)))
         {
             if (CheckFlag(flags, PdfAnnotation.FLAGS_NOZOOM) == false || CheckFlag(flags, PdfAnnotation.FLAGS_NOROTATE) == false)
             {
                 throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("text.annotations.should.set.the.nozoom.and.norotate.flag.bits.of.the.f.key.to.1"));
             }
         }
         if (annot.Contains(PdfName.C) || annot.Contains(PdfName.IC))
         {
             ICC_Profile colorProfile = ((PdfAWriter)writer).ColorProfile;
             String      cs           = "";
             cs = System.Text.Encoding.ASCII.GetString(colorProfile.Data, 16, 4);
             if (!"RGB".Equals(cs.ToUpper()))
             {
                 throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("destoutputprofile.in.the.pdfa1.outputintent.dictionary.shall.be.rgb"));
             }
         }
         PdfDictionary ap = GetDirectDictionary(annot.Get(PdfName.AP));
         if (ap != null)
         {
             if (ap.Contains(PdfName.R) || ap.Contains(PdfName.D))
             {
                 throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("appearance.dictionary.shall.contain.only.the.n.key.with.stream.value"));
             }
             PdfObject n = ap.Get(PdfName.N);
             if (!(n is PdfIndirectReference))
             {
                 throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("appearance.dictionary.shall.contain.only.the.n.key.with.stream.value"));
             }
         }
         if (PdfName.WIDGET.Equals(annot.GetAsName(PdfName.SUBTYPE)) && (annot.Contains(PdfName.AA) || annot.Contains(PdfName.A)))
         {
             throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("widget.annotation.dictionary.or.field.dictionary.shall.not.include.a.or.aa.entry"));
         }
         if (CheckStructure(conformanceLevel))
         {
             if (contentAnnotations.Contains(subtype) && !annot.Contains(PdfName.CONTENTS))
             {
                 throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("annotation.of.type.1.should.have.contents.key", subtype.ToString()));
             }
         }
     }
 }
Exemplo n.º 2
0
        public PdfArray RotateAnnotations(PdfWriter writer, Rectangle pageSize)
        {
            PdfArray array       = new PdfArray();
            int      rotation    = pageSize.Rotation % 360;
            int      currentPage = writer.CurrentPageNumber;

            for (int k = 0; k < annotations.Count; ++k)
            {
                PdfAnnotation dic  = (PdfAnnotation)annotations[k];
                int           page = dic.PlaceInPage;
                if (page > currentPage)
                {
                    delayedAnnotations.Add(dic);
                    continue;
                }
                if (dic.IsForm())
                {
                    if (!dic.IsUsed())
                    {
                        Hashtable templates = dic.Templates;
                        if (templates != null)
                        {
                            acroForm.AddFieldTemplates(templates);
                        }
                    }
                    PdfFormField field = (PdfFormField)dic;
                    if (field.Parent == null)
                    {
                        acroForm.AddDocumentField(field.IndirectReference);
                    }
                }
                if (dic.IsAnnotation())
                {
                    array.Add(dic.IndirectReference);
                    if (!dic.IsUsed())
                    {
                        PdfRectangle rect = (PdfRectangle)dic.Get(PdfName.RECT);
                        if (rect != null)
                        {
                            switch (rotation)
                            {
                            case 90:
                                dic.Put(PdfName.RECT, new PdfRectangle(
                                            pageSize.Top - rect.Bottom,
                                            rect.Left,
                                            pageSize.Top - rect.Top,
                                            rect.Right));
                                break;

                            case 180:
                                dic.Put(PdfName.RECT, new PdfRectangle(
                                            pageSize.Right - rect.Left,
                                            pageSize.Top - rect.Bottom,
                                            pageSize.Right - rect.Right,
                                            pageSize.Top - rect.Top));
                                break;

                            case 270:
                                dic.Put(PdfName.RECT, new PdfRectangle(
                                            rect.Bottom,
                                            pageSize.Right - rect.Left,
                                            rect.Top,
                                            pageSize.Right - rect.Right));
                                break;
                            }
                        }
                    }
                }
                if (!dic.IsUsed())
                {
                    dic.SetUsed();
                    writer.AddToBody(dic, dic.IndirectReference);
                }
            }
            return(array);
        }