Inheritance: PdfDictionary
コード例 #1
0
        /** Add a chained action.
         * @param na the next action
         */
        public void Next(PdfAction na)
        {
            PdfObject nextAction = Get(PdfName.NEXT);

            if (nextAction == null)
            {
                Put(PdfName.NEXT, na);
            }
            else if (nextAction.IsDictionary())
            {
                PdfArray array = new PdfArray(nextAction);
                array.Add(na);
                Put(PdfName.NEXT, array);
            }
            else
            {
                ((PdfArray)nextAction).Add(na);
            }
        }
コード例 #2
0
ファイル: PdfAction.cs プロジェクト: mbarylsk/pdf-tools
        /**
         * Creates a GoToR action to a named destination.
         * @param filename the file name to go to
         * @param dest the destination name
         * @param isName if true sets the destination as a name, if false sets it as a String
         * @param newWindow open the document in a new window if <CODE>true</CODE>, if false the current document is replaced by the new document.
         * @return a GoToR action
         */
        public static PdfAction GotoRemotePage(String filename, String dest, bool isName, bool newWindow)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.F, new PdfString(filename));
            action.Put(PdfName.S, PdfName.GOTOR);
            if (isName)
            {
                action.Put(PdfName.D, new PdfName(dest));
            }
            else
            {
                action.Put(PdfName.D, new PdfString(dest, null));
            }
            if (newWindow)
            {
                action.Put(PdfName.NEWWINDOW, PdfBoolean.PDFTRUE);
            }
            return(action);
        }
コード例 #3
0
        /// <summary>
        /// Creates a GoToR action to a named destination.
        /// </summary>
        /// <param name="filename">the file name to go to</param>
        /// <param name="dest">the destination name</param>
        /// <param name="isName">if true sets the destination as a name, if false sets it as a String</param>
        /// <param name="newWindow">open the document in a new window if  true , if false the current document is replaced by the new document.</param>
        /// <returns>a GoToR action</returns>
        public static PdfAction GotoRemotePage(string filename, string dest, bool isName, bool newWindow)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.F, new PdfString(filename));
            action.Put(PdfName.S, PdfName.Gotor);
            if (isName)
            {
                action.Put(PdfName.D, new PdfName(dest));
            }
            else
            {
                action.Put(PdfName.D, new PdfString(dest, null));
            }
            if (newWindow)
            {
                action.Put(PdfName.Newwindow, PdfBoolean.Pdftrue);
            }
            return(action);
        }
コード例 #4
0
        /**
         * Creates a screen PdfAnnotation
         * @param writer
         * @param rect
         * @param clipTitle
         * @param fs
         * @param mimeType
         * @param playOnDisplay
         * @return a screen PdfAnnotation
         * @throws IOException
         */
        public static PdfAnnotation CreateScreen(PdfWriter writer, Rectangle rect, String clipTitle, PdfFileSpecification fs,
                                                 String mimeType, bool playOnDisplay)
        {
            PdfAnnotation ann = writer.CreateAnnotation(rect, PdfName.SCREEN);

            ann.Put(PdfName.F, new PdfNumber(FLAGS_PRINT));
            ann.Put(PdfName.TYPE, PdfName.ANNOT);
            ann.SetPage();
            PdfIndirectReference refi      = ann.IndirectReference;
            PdfAction            action    = PdfAction.Rendition(clipTitle, fs, mimeType, refi);
            PdfIndirectReference actionRef = writer.AddToBody(action).IndirectReference;

            // for play on display add trigger event
            if (playOnDisplay)
            {
                PdfDictionary aa = new PdfDictionary();
                aa.Put(new PdfName("PV"), actionRef);
                ann.Put(PdfName.AA, aa);
            }
            ann.Put(PdfName.A, actionRef);
            return(ann);
        }
コード例 #5
0
        /** Creates a JavaScript action. If the JavaScript is smaller than
         * 50 characters it will be placed as a string, otherwise it will
         * be placed as a compressed stream.
         * @param code the JavaScript code
         * @param writer the writer for this action
         * @param unicode select JavaScript unicode. Note that the internal
         * Acrobat JavaScript engine does not support unicode,
         * so this may or may not work for you
         * @return the JavaScript action
         */
        public static PdfAction JavaScript(string code, PdfWriter writer, bool unicode)
        {
            PdfAction js = new PdfAction();

            js.Put(PdfName.S, PdfName.JAVASCRIPT);
            if (unicode && code.Length < 50)
            {
                js.Put(PdfName.JS, new PdfString(code, PdfObject.TEXT_UNICODE));
            }
            else if (!unicode && code.Length < 100)
            {
                js.Put(PdfName.JS, new PdfString(code));
            }
            else
            {
                byte[]    b      = PdfEncodings.ConvertToBytes(code, unicode ? PdfObject.TEXT_UNICODE : PdfObject.TEXT_PDFDOCENCODING);
                PdfStream stream = new PdfStream(b);
                stream.FlateCompress();
                js.Put(PdfName.JS, writer.AddToBody(stream).IndirectReference);
            }
            return(js);
        }
コード例 #6
0
ファイル: PdfStamperImp.cs プロジェクト: hjgode/iTextSharpCF
 /** Always throws an <code>UnsupportedOperationException</code>.
 * @param actionType ignore
 * @param action ignore
 * @throws PdfException ignore
 * @see PdfStamper#setPageAction(PdfName, PdfAction, int)
 */
 public override void SetPageAction(PdfName actionType, PdfAction action)
 {
     throw new InvalidOperationException("Use SetPageAction(PdfName actionType, PdfAction action, int page)");
 }
コード例 #7
0
ファイル: PdfStamperImp.cs プロジェクト: hjgode/iTextSharpCF
 /**
 * Sets the open and close page additional action.
 * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE>
 * or <CODE>PdfWriter.PAGE_CLOSE</CODE>
 * @param action the action to perform
 * @param page the page where the action will be applied. The first page is 1
 * @throws PdfException if the action type is invalid
 */
 internal void SetPageAction(PdfName actionType, PdfAction action, int page)
 {
     if (!actionType.Equals(PAGE_OPEN) && !actionType.Equals(PAGE_CLOSE))
         throw new PdfException("Invalid page additional action type: " + actionType.ToString());
     PdfDictionary pg = reader.GetPageN(page);
     PdfDictionary aa = (PdfDictionary)PdfReader.GetPdfObject(pg.Get(PdfName.AA), pg);
     if (aa == null) {
         aa = new PdfDictionary();
         pg.Put(PdfName.AA, aa);
         MarkUsed(pg);
     }
     aa.Put(actionType, action);
     MarkUsed(aa);
 }
コード例 #8
0
        /// <summary>
        /// A set-OCG-state action (PDF 1.5) sets the state of one or more optional content
        /// groups.
        /// or  String  (ON, OFF, or Toggle) followed by one or more optional content group dictionaries
        ///  PdfLayer  or a  PdfIndirectReference  to a  PdfLayer .
        /// The array elements are processed from left to right; each name is applied
        /// to the subsequent groups until the next name is encountered:
        ///
        ///  ON sets the state of subsequent groups to ON
        ///  OFF sets the state of subsequent groups to OFF
        ///  Toggle reverses the state of subsequent groups
        ///
        /// content groups (as specified by the RBGroups entry in the current configuration
        /// dictionary) should be preserved when the states in the
        ///  state  array are applied. That is, if a group is set to ON (either by ON or Toggle) during
        /// processing of the  state  array, any other groups belong to the same radio-button
        /// group are turned OFF. If a group is set to OFF, there is no effect on other groups.
        /// If  false , radio-button state relationships, if any, are ignored
        /// </summary>
        /// <param name="state">an array consisting of any number of sequences beginning with a  PdfName </param>
        /// <param name="preserveRb">if  true , indicates that radio-button state relationships between optional</param>
        /// <returns>the action</returns>
        public static PdfAction SetOcGstate(ArrayList state, bool preserveRb)
        {
            var action = new PdfAction();

            action.Put(PdfName.S, PdfName.Setocgstate);
            var a = new PdfArray();

            for (var k = 0; k < state.Count; ++k)
            {
                var o = state[k];
                if (o == null)
                {
                    continue;
                }

                if (o is PdfIndirectReference)
                {
                    a.Add((PdfIndirectReference)o);
                }
                else if (o is PdfLayer)
                {
                    a.Add(((PdfLayer)o).Ref);
                }
                else if (o is PdfName)
                {
                    a.Add((PdfName)o);
                }
                else if (o is string)
                {
                    PdfName name = null;
                    var     s    = (string)o;
                    if (Util.EqualsIgnoreCase(s, "on"))
                    {
                        name = PdfName.On;
                    }
                    else if (Util.EqualsIgnoreCase(s, "off"))
                    {
                        name = PdfName.OFF;
                    }
                    else if (Util.EqualsIgnoreCase(s, "toggle"))
                    {
                        name = PdfName.Toggle;
                    }
                    else
                    {
                        throw new ArgumentException("A string '" + s + " was passed in state. Only 'ON', 'OFF' and 'Toggle' are allowed.");
                    }

                    a.Add(name);
                }
                else
                {
                    throw new ArgumentException("Invalid type was passed in state: " + o.GetType());
                }
            }
            action.Put(PdfName.State, a);
            if (!preserveRb)
            {
                action.Put(PdfName.Preserverb, PdfBoolean.Pdffalse);
            }

            return(action);
        }
コード例 #9
0
 /** When the document opens this <CODE>action</CODE> will be
 * invoked.
 * @param action the action to be invoked
 */
 public virtual void SetOpenAction(PdfAction action) {
     pdf.SetOpenAction(action);
 }
コード例 #10
0
 /** Additional-actions defining the actions to be taken in
 * response to various trigger events affecting the document
 * as a whole. The actions types allowed are: <CODE>DOCUMENT_CLOSE</CODE>,
 * <CODE>WILL_SAVE</CODE>, <CODE>DID_SAVE</CODE>, <CODE>WILL_PRINT</CODE>
 * and <CODE>DID_PRINT</CODE>.
 *
 * @param actionType the action type
 * @param action the action to execute in response to the trigger
 * @throws PdfException on invalid action type
 */
 public override void SetAdditionalAction(PdfName actionType, PdfAction action) {
     if (!(actionType.Equals(DOCUMENT_CLOSE) ||
     actionType.Equals(WILL_SAVE) ||
     actionType.Equals(DID_SAVE) ||
     actionType.Equals(WILL_PRINT) ||
     actionType.Equals(DID_PRINT))) {
         throw new PdfException(MessageLocalization.GetComposedMessage("invalid.additional.action.type.1", actionType.ToString()));
     }
     PdfDictionary aa = reader.Catalog.GetAsDict(PdfName.AA);
     if (aa == null) {
         if (action == null)
             return;
         aa = new PdfDictionary();
         reader.Catalog.Put(PdfName.AA, aa);
     }
     MarkUsed(aa);
     if (action == null)
         aa.Remove(actionType);
     else
         aa.Put(actionType, action);
 }
コード例 #11
0
 internal void SetPageAction(PdfName actionType, PdfAction action) {
     if (pageAA == null) {
         pageAA = new PdfDictionary();
     }
     pageAA.Put(actionType, action);
 }
コード例 #12
0
 internal PdfAction GetLocalGotoAction(String name) {
     PdfAction action;
     Destination dest;
     if (localDestinations.ContainsKey(name))
         dest = localDestinations[name];
     else
         dest = new Destination();
     if (dest.action == null) {
         if (dest.reference == null) {
             dest.reference = writer.PdfIndirectReference;
         }
         action = new PdfAction(dest.reference);
         dest.action = action;
         localDestinations[name] = dest;
     }
     else {
         action = dest.action;
     }
     return action;
 }
コード例 #13
0
ファイル: PdfOutline.cs プロジェクト: EnergonV/BestCS
        /**
         * Constructs a <CODE>PdfOutline</CODE>.
         * <P>
         * This is the constructor for an <CODE>outline entry</CODE>. The open mode is
         * <CODE>true</CODE>.
         *
         * @param parent the parent of this outline item
         * @param action the <CODE>PdfAction</CODE> for this outline item
         * @param title the title of this outline item
         */

        public PdfOutline(PdfOutline parent, PdfAction action, Paragraph title) : this(parent, action, title, true)
        {
        }
コード例 #14
0
ファイル: PdfOutline.cs プロジェクト: EnergonV/BestCS
 /**
  * Constructs a <CODE>PdfOutline</CODE>.
  * <P>
  * This is the constructor for an <CODE>outline entry</CODE>.
  *
  * @param parent the parent of this outline item
  * @param action the <CODE>PdfAction</CODE> for this outline item
  * @param title the title of this outline item
  * @param open <CODE>true</CODE> if the children are visible
  */
 public PdfOutline(PdfOutline parent, PdfAction action, PdfString title, bool open) : this(parent, action, title.ToString(), open)
 {
 }
コード例 #15
0
ファイル: PdfOutline.cs プロジェクト: EnergonV/BestCS
 /**
  * Constructs a <CODE>PdfOutline</CODE>.
  * <P>
  * This is the constructor for an <CODE>outline entry</CODE>. The open mode is
  * <CODE>true</CODE>.
  *
  * @param parent the parent of this outline item
  * @param action the <CODE>PdfAction</CODE> for this outline item
  * @param title the title of this outline item
  */
 public PdfOutline(PdfOutline parent, PdfAction action, PdfString title) : this(parent, action, title, true)
 {
 }
コード例 #16
0
ファイル: PdfOutline.cs プロジェクト: EnergonV/BestCS
 /**
  * Constructs a <CODE>PdfOutline</CODE>.
  * <P>
  * This is the constructor for an <CODE>outline entry</CODE>.
  *
  * @param parent the parent of this outline item
  * @param action the <CODE>PdfAction</CODE> for this outline item
  * @param title the title of this outline item
  * @param open <CODE>true</CODE> if the children are visible
  */
 public PdfOutline(PdfOutline parent, PdfAction action, string title, bool open) : base()
 {
     this.action = action;
     InitOutline(parent, title, open);
 }
コード例 #17
0
 public void SetPageAction(PdfName actionType, PdfAction action, int page);
コード例 #18
0
 /// <summary>
 /// Constructs a  PdfOutline .
 ///
 /// This is the constructor for an  outline entry .
 /// </summary>
 /// <param name="parent">the parent of this outline item</param>
 /// <param name="action">the  PdfAction  for this outline item</param>
 /// <param name="title">the title of this outline item</param>
 /// <param name="open"> true  if the children are visible</param>
 public PdfOutline(PdfOutline parent, PdfAction action, string title, bool open)
 {
     _action = action;
     InitOutline(parent, title, open);
 }
コード例 #19
0
 /**
  * Constructs a <CODE>PdfOutline</CODE>.
  * <P>
  * This is the constructor for an <CODE>outline entry</CODE>. The open mode is
  * <CODE>true</CODE>.
  *
  * @param parent the parent of this outline item
  * @param action the <CODE>PdfAction</CODE> for this outline item
  * @param title the title of this outline item
  */
 public PdfOutline(PdfOutline parent, PdfAction action, PdfString title)
     : this(parent, action, title, true)
 {
 }
コード例 #20
0
ファイル: PdfStamper.cs プロジェクト: zeespogeira/itextsharp
 /** Adds a JavaScript action at the document level. When the document
  * opens all this JavaScript runs. The existing JavaScript will be replaced.
  * @param name the name for the JavaScript snippet in the name tree
  * @param js the JavaScript code
  */
 public virtual void AddJavaScript(String name, String js)
 {
     stamper.AddJavaScript(name, PdfAction.JavaScript(js, stamper, !PdfEncodings.IsPdfDocEncoding(js)));
 }
コード例 #21
0
        /**
         * Constructs a <CODE>PdfChunk</CODE>-object.
         *
         * @param chunk the original <CODE>Chunk</CODE>-object
         * @param action the <CODE>PdfAction</CODE> if the <CODE>Chunk</CODE> comes from an <CODE>Anchor</CODE>
         */

        internal PdfChunk(Chunk chunk, PdfAction action)
        {
            value = chunk.Content;

            iTextSharp.text.Font f = chunk.Font;
            float size             = f.Size;

            if (size == iTextSharp.text.Font.UNDEFINED)
            {
                size = 12;
            }
            BaseFont bf = f.BaseFont;
            int      family;
            int      style = f.Style;

            if (bf == null)
            {
                // translation of the font-family to a PDF font-family
                if (style == iTextSharp.text.Font.UNDEFINED)
                {
                    style = iTextSharp.text.Font.NORMAL;
                }
                switch (f.Family)
                {
                case iTextSharp.text.Font.COURIER:
                    switch (style & iTextSharp.text.Font.BOLDITALIC)
                    {
                    case iTextSharp.text.Font.BOLD:
                        family = PdfFont.COURIER_BOLD;
                        break;

                    case iTextSharp.text.Font.ITALIC:
                        family = PdfFont.COURIER_OBLIQUE;
                        break;

                    case iTextSharp.text.Font.BOLDITALIC:
                        family = PdfFont.COURIER_BOLDOBLIQUE;
                        break;

                    default:
                    case iTextSharp.text.Font.NORMAL:
                        family = PdfFont.COURIER;
                        break;
                    }
                    break;

                case iTextSharp.text.Font.TIMES_NEW_ROMAN:
                    switch (style & iTextSharp.text.Font.BOLDITALIC)
                    {
                    case iTextSharp.text.Font.BOLD:
                        family = PdfFont.TIMES_BOLD;
                        break;

                    case iTextSharp.text.Font.ITALIC:
                        family = PdfFont.TIMES_ITALIC;
                        break;

                    case iTextSharp.text.Font.BOLDITALIC:
                        family = PdfFont.TIMES_BOLDITALIC;
                        break;

                    default:
                    case iTextSharp.text.Font.NORMAL:
                        family = PdfFont.TIMES_ROMAN;
                        break;
                    }
                    break;

                case iTextSharp.text.Font.SYMBOL:
                    family = PdfFont.SYMBOL;
                    break;

                case iTextSharp.text.Font.ZAPFDINGBATS:
                    family = PdfFont.ZAPFDINGBATS;
                    break;

                default:
                case iTextSharp.text.Font.HELVETICA:
                    switch (style & iTextSharp.text.Font.BOLDITALIC)
                    {
                    case iTextSharp.text.Font.BOLD:
                        family = PdfFont.HELVETICA_BOLD;
                        break;

                    case iTextSharp.text.Font.ITALIC:
                        family = PdfFont.HELVETICA_OBLIQUE;
                        break;

                    case iTextSharp.text.Font.BOLDITALIC:
                        family = PdfFont.HELVETICA_BOLDOBLIQUE;
                        break;

                    default:
                    case iTextSharp.text.Font.NORMAL:
                        family = PdfFont.HELVETICA;
                        break;
                    }
                    break;
                }
                // creation of the PdfFont with the right size
                font = new PdfFont(family, size);
            }
            else
            {
                // bold simulation
                if ((style & iTextSharp.text.Font.BOLD) != 0)
                {
                    attributes.Add(Chunk.TEXTRENDERMODE, new Object[] { PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, size / 30f, null });
                }
                // italic simulation
                if ((style & iTextSharp.text.Font.ITALIC) != 0)
                {
                    attributes.Add(Chunk.SKEW, new float[] { 0, ITALIC_ANGLE });
                }

                font = new PdfFont(bf, size);
            }



            // other style possibilities
            Hashmap attr = chunk.Attributes;

            if (attr != null)
            {
                foreach (string name in attr.Keys)
                {
                    if (keysAttributes.ContainsKey(name))
                    {
                        attributes.Add(name, attr[name]);
                    }
                    else if (keysNoStroke.ContainsKey(name))
                    {
                        noStroke.Add(name, attr[name]);
                    }
                }
                if ("".Equals(attr[Chunk.GENERICTAG]))
                {
                    attributes.Add(Chunk.GENERICTAG, chunk.Content);
                }
            }
            if (f.isUnderlined())
            {
                attributes.Add(Chunk.UNDERLINE, null);
            }
            if (f.isStrikethru())
            {
                attributes.Add(Chunk.STRIKETHRU, null);
            }
            if (action != null)
            {
                attributes.Add(Chunk.ACTION, action);
            }
            // the color can't be stored in a PdfFont
            noStroke.Add(Chunk.COLOR, f.Color);
            noStroke.Add(Chunk.ENCODING, font.Font.Encoding);
            Object[] obj = (Object[])attributes[Chunk.IMAGE];
            if (obj == null)
            {
                image = null;
            }
            else
            {
                image         = (Image)obj[0];
                offsetX       = ((float)obj[1]);
                offsetY       = ((float)obj[2]);
                changeLeading = bool.Parse(obj[3].ToString());
            }
            font.Image     = image;
            encoding       = font.Font.Encoding;
            splitCharacter = (ISplitCharacter)noStroke[Chunk.SPLITCHARACTER];
            if (splitCharacter == null)
            {
                splitCharacter = this;
            }
        }
コード例 #22
0
 internal void SetOpenAction(PdfAction action) {
     openActionAction = action;
     openActionName = null;
 }
コード例 #23
0
        /// <summary>
        /// Constructs a  PdfChunk -object.
        /// </summary>
        /// <param name="chunk">the original  Chunk -object</param>
        /// <param name="action">the  PdfAction  if the  Chunk  comes from an  Anchor </param>

        internal PdfChunk(Chunk chunk, PdfAction action)
        {
            _thisChunk[0] = this;
            value         = chunk.Content;

            Font  f    = chunk.Font;
            float size = f.Size;

            if (size.ApproxEquals(text.Font.UNDEFINED))
            {
                size = 12;
            }
            BaseFont = f.BaseFont;
            BaseFont bf    = f.BaseFont;
            int      style = f.Style;

            if (style == text.Font.UNDEFINED)
            {
                style = text.Font.NORMAL;
            }
            if (BaseFont == null)
            {
                // translation of the font-family to a PDF font-family
                BaseFont = f.GetCalculatedBaseFont(false);
            }
            else
            {
                // bold simulation
                if ((style & text.Font.BOLD) != 0)
                {
                    Attributes[Chunk.TEXTRENDERMODE] = new object[] { PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, size / 30f, null }
                }
                ;
                // italic simulation
                if ((style & text.Font.ITALIC) != 0)
                {
                    Attributes[Chunk.SKEW] = new[] { 0, ItalicAngle }
                }
                ;
            }
            font = new PdfFont(BaseFont, size);
            // other style possibilities
            Hashtable attr = chunk.Attributes;

            if (attr != null)
            {
                foreach (DictionaryEntry entry in attr)
                {
                    string name = (string)entry.Key;
                    if (_keysAttributes.ContainsKey(name))
                    {
                        Attributes[name] = entry.Value;
                    }
                    else if (_keysNoStroke.ContainsKey(name))
                    {
                        NoStroke[name] = entry.Value;
                    }
                }
                if ("".Equals(attr[Chunk.GENERICTAG]))
                {
                    Attributes[Chunk.GENERICTAG] = chunk.Content;
                }
            }
            if (f.IsUnderlined())
            {
                object[]   obj    = { null, new[] { 0, 1f / 15, 0, -1f / 3, 0 } };
                object[][] unders = Utilities.AddToArray((object[][])Attributes[Chunk.UNDERLINE], obj);
                Attributes[Chunk.UNDERLINE] = unders;
            }
            if (f.IsStrikethru())
            {
                object[]   obj    = { null, new[] { 0, 1f / 15, 0, 1f / 3, 0 } };
                object[][] unders = Utilities.AddToArray((object[][])Attributes[Chunk.UNDERLINE], obj);
                Attributes[Chunk.UNDERLINE] = unders;
            }
            if (action != null)
            {
                Attributes[Chunk.ACTION] = action;
            }
            // the color can't be stored in a PdfFont
            NoStroke[Chunk.COLOR]    = f.Color;
            NoStroke[Chunk.ENCODING] = font.Font.Encoding;
            object[] obj2 = (object[])Attributes[Chunk.IMAGE];
            if (obj2 == null)
            {
                image = null;
            }
            else
            {
                Attributes.Remove(Chunk.HSCALE); // images are scaled in other ways
                image         = (Image)obj2[0];
                OffsetX       = ((float)obj2[1]);
                OffsetY       = ((float)obj2[2]);
                changeLeading = (bool)obj2[3];
            }
            font.Image = image;
            object hs = Attributes[Chunk.HSCALE];

            if (hs != null)
            {
                font.HorizontalScaling = (float)hs;
            }
            encoding       = font.Font.Encoding;
            SplitCharacter = (ISplitCharacter)NoStroke[Chunk.SPLITCHARACTER];
            if (SplitCharacter == null)
            {
                SplitCharacter = DefaultSplitCharacter.Default;
            }
        }
コード例 #24
0
 /** Always throws an <code>UnsupportedOperationException</code>.
 * @param actionType ignore
 * @param action ignore
 * @throws PdfException ignore
 * @see PdfStamper#setPageAction(PdfName, PdfAction, int)
 */    
 public override void SetPageAction(PdfName actionType, PdfAction action) {
     throw new InvalidOperationException(MessageLocalization.GetComposedMessage("use.setpageaction.pdfname.actiontype.pdfaction.action.int.page"));
 }
コード例 #25
0
 internal static void CreateOutlineAction(PdfDictionary outline, Dictionary <String, Object> map, PdfWriter writer, bool namedAsNames)
 {
     try {
         String action = GetVal(map, "Action");
         if ("GoTo".Equals(action))
         {
             String p;
             if ((p = GetVal(map, "Named")) != null)
             {
                 if (namedAsNames)
                 {
                     outline.Put(PdfName.DEST, new PdfName(p));
                 }
                 else
                 {
                     outline.Put(PdfName.DEST, new PdfString(p, null));
                 }
             }
             else if ((p = GetVal(map, "Page")) != null)
             {
                 PdfArray        ar = new PdfArray();
                 StringTokenizer tk = new StringTokenizer(p);
                 int             n  = int.Parse(tk.NextToken());
                 ar.Add(writer.GetPageReference(n));
                 if (!tk.HasMoreTokens())
                 {
                     ar.Add(PdfName.XYZ);
                     ar.Add(new float[] { 0, 10000, 0 });
                 }
                 else
                 {
                     String fn = tk.NextToken();
                     if (fn.StartsWith("/"))
                     {
                         fn = fn.Substring(1);
                     }
                     ar.Add(new PdfName(fn));
                     for (int k = 0; k < 4 && tk.HasMoreTokens(); ++k)
                     {
                         fn = tk.NextToken();
                         if (fn.Equals("null"))
                         {
                             ar.Add(PdfNull.PDFNULL);
                         }
                         else
                         {
                             ar.Add(new PdfNumber(fn));
                         }
                     }
                 }
                 outline.Put(PdfName.DEST, ar);
             }
         }
         else if ("GoToR".Equals(action))
         {
             String        p;
             PdfDictionary dic = new PdfDictionary();
             if ((p = GetVal(map, "Named")) != null)
             {
                 dic.Put(PdfName.D, new PdfString(p, null));
             }
             else if ((p = GetVal(map, "NamedN")) != null)
             {
                 dic.Put(PdfName.D, new PdfName(p));
             }
             else if ((p = GetVal(map, "Page")) != null)
             {
                 PdfArray        ar = new PdfArray();
                 StringTokenizer tk = new StringTokenizer(p);
                 ar.Add(new PdfNumber(tk.NextToken()));
                 if (!tk.HasMoreTokens())
                 {
                     ar.Add(PdfName.XYZ);
                     ar.Add(new float[] { 0, 10000, 0 });
                 }
                 else
                 {
                     String fn = tk.NextToken();
                     if (fn.StartsWith("/"))
                     {
                         fn = fn.Substring(1);
                     }
                     ar.Add(new PdfName(fn));
                     for (int k = 0; k < 4 && tk.HasMoreTokens(); ++k)
                     {
                         fn = tk.NextToken();
                         if (fn.Equals("null"))
                         {
                             ar.Add(PdfNull.PDFNULL);
                         }
                         else
                         {
                             ar.Add(new PdfNumber(fn));
                         }
                     }
                 }
                 dic.Put(PdfName.D, ar);
             }
             String file = GetVal(map, "File");
             if (dic.Size > 0 && file != null)
             {
                 dic.Put(PdfName.S, PdfName.GOTOR);
                 dic.Put(PdfName.F, new PdfString(file));
                 String nw = GetVal(map, "NewWindow");
                 if (nw != null)
                 {
                     if (nw.Equals("true"))
                     {
                         dic.Put(PdfName.NEWWINDOW, PdfBoolean.PDFTRUE);
                     }
                     else if (nw.Equals("false"))
                     {
                         dic.Put(PdfName.NEWWINDOW, PdfBoolean.PDFFALSE);
                     }
                 }
                 outline.Put(PdfName.A, dic);
             }
         }
         else if ("URI".Equals(action))
         {
             String uri = GetVal(map, "URI");
             if (uri != null)
             {
                 PdfDictionary dic = new PdfDictionary();
                 dic.Put(PdfName.S, PdfName.URI);
                 dic.Put(PdfName.URI, new PdfString(uri));
                 outline.Put(PdfName.A, dic);
             }
         }
         else if ("JS".Equals(action))
         {
             String code = GetVal(map, "Code");
             if (code != null)
             {
                 outline.Put(PdfName.A, PdfAction.JavaScript(code, writer));
             }
         }
         else if ("Launch".Equals(action))
         {
             String file = GetVal(map, "File");
             if (file != null)
             {
                 PdfDictionary dic = new PdfDictionary();
                 dic.Put(PdfName.S, PdfName.LAUNCH);
                 dic.Put(PdfName.F, new PdfString(file));
                 outline.Put(PdfName.A, dic);
             }
         }
     }
     catch  {
         // empty on purpose
     }
 }
コード例 #26
0
 /**
 * Use this method to add a JavaScript action at the document level.
 * When the document opens, all this JavaScript runs.
 * @param js The JavaScript action
 */
 public virtual void AddJavaScript(PdfAction js) {
     pdf.AddJavaScript(js);
 }
コード例 #27
0
        public override PdfAnnotation CreateAnnotation(float llx, float lly, float urx, float ury, PdfAction action, PdfName subtype)
        {
            PdfAnnotation a = base.CreateAnnotation(llx, lly, urx, ury, action, subtype);

            if (!PdfName.POPUP.Equals(subtype))
            {
                a.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT));
            }
            return(a);
        }
コード例 #28
0
 /** Sets the open and close page additional action.
 * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE>
 * or <CODE>PdfWriter.PAGE_CLOSE</CODE>
 * @param action the action to perform
 * @throws PdfException if the action type is invalid
 */    
 public virtual void SetPageAction(PdfName actionType, PdfAction action) {
     if (!actionType.Equals(PAGE_OPEN) && !actionType.Equals(PAGE_CLOSE))
         throw new PdfException(MessageLocalization.GetComposedMessage("invalid.page.additional.action.type.1", actionType.ToString()));
     pdf.SetPageAction(actionType, action);
 }
コード例 #29
0
 public override void SetAction(PdfAction action, float llx, float lly, float urx, float ury)
 {
     ((PdfStamperImp)writer).AddAnnotation(new PdfAnnotation(writer, llx, lly, urx, ury, action), ps.pageN);
 }
コード例 #30
0
ファイル: PdfChunk.cs プロジェクト: RawanRadi/Simple-PDFMerge
        /**
         * Constructs a <CODE>PdfChunk</CODE>-object.
         *
         * @param chunk the original <CODE>Chunk</CODE>-object
         * @param action the <CODE>PdfAction</CODE> if the <CODE>Chunk</CODE> comes from an <CODE>Anchor</CODE>
         */

        internal PdfChunk(Chunk chunk, PdfAction action)
        {
            value = chunk.Content;

            Font  f    = chunk.Font;
            float size = f.Size;

            if (size == iTextSharp.text.Font.UNDEFINED)
            {
                size = 12;
            }
            baseFont = f.BaseFont;
            //BaseFont bf = f.BaseFont;
            int style = f.Style;

            if (style == iTextSharp.text.Font.UNDEFINED)
            {
                style = iTextSharp.text.Font.NORMAL;
            }
            if (baseFont == null)
            {
                // translation of the font-family to a PDF font-family
                baseFont = f.GetCalculatedBaseFont(false);
            }
            else
            {
                // bold simulation
                if ((style & iTextSharp.text.Font.BOLD) != 0)
                {
                    attributes[Chunk.TEXTRENDERMODE] = new Object[] { PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, size / 30f, null }
                }
                ;
                // italic simulation
                if ((style & iTextSharp.text.Font.ITALIC) != 0)
                {
                    attributes[Chunk.SKEW] = new float[] { 0, ITALIC_ANGLE }
                }
                ;
            }
            font = new PdfFont(baseFont, size);
            // other style possibilities
            Dictionary <string, object> attr = chunk.Attributes;

            if (attr != null)
            {
                foreach (KeyValuePair <string, object> entry in attr)
                {
                    string name = entry.Key;
                    if (keysAttributes.ContainsKey(name))
                    {
                        attributes[name] = entry.Value;
                    }
                    else if (keysNoStroke.ContainsKey(name))
                    {
                        noStroke[name] = entry.Value;
                    }
                }
                if (attr.ContainsKey(Chunk.GENERICTAG) && "".Equals(attr[Chunk.GENERICTAG]))
                {
                    attributes[Chunk.GENERICTAG] = chunk.Content;
                }
            }
            if (f.IsUnderlined())
            {
                Object[]   obj  = { null, new float[] { 0, UNDERLINE_THICKNESS, 0, UNDERLINE_OFFSET, 0 } };
                Object[][] obja = null;
                if (attributes.ContainsKey(Chunk.UNDERLINE))
                {
                    obja = (Object[][])attributes[Chunk.UNDERLINE];
                }
                Object[][] unders = Utilities.AddToArray(obja, obj);
                attributes[Chunk.UNDERLINE] = unders;
            }
            if (f.IsStrikethru())
            {
                Object[]   obj  = { null, new float[] { 0, 1f / 15, 0, 1f / 3, 0 } };
                Object[][] obja = null;
                if (attributes.ContainsKey(Chunk.UNDERLINE))
                {
                    obja = (Object[][])attributes[Chunk.UNDERLINE];
                }
                Object[][] unders = Utilities.AddToArray(obja, obj);
                attributes[Chunk.UNDERLINE] = unders;
            }
            if (action != null)
            {
                attributes[Chunk.ACTION] = action;
            }
            // the color can't be stored in a PdfFont
            noStroke[Chunk.COLOR]    = f.Color;
            noStroke[Chunk.ENCODING] = font.Font.Encoding;
            Object lh;

            if (attributes.TryGetValue(Chunk.LINEHEIGHT, out lh))
            {
                changeLeading = true;
                leading       = (float)lh;
            }

            Object[] obj2 = null;
            if (attributes.ContainsKey(Chunk.IMAGE))
            {
                obj2 = (Object[])attributes[Chunk.IMAGE];
            }
            if (obj2 == null)
            {
                image = null;
            }
            else
            {
                attributes.Remove(Chunk.HSCALE); // images are scaled in other ways
                image         = (Image)obj2[0];
                offsetX       = ((float)obj2[1]);
                offsetY       = ((float)obj2[2]);
                changeLeading = (bool)obj2[3];
            }
            object hs;

            if (attributes.TryGetValue(Chunk.HSCALE, out hs))
            {
                font.HorizontalScaling = (float)hs;
            }
            encoding = font.Font.Encoding;
            if (noStroke.ContainsKey(Chunk.SPLITCHARACTER))
            {
                splitCharacter = (ISplitCharacter)noStroke[Chunk.SPLITCHARACTER];
            }
            else
            {
                splitCharacter = DefaultSplitCharacter.DEFAULT;
            }
            accessibleElement = chunk;
        }
コード例 #31
0
 /**
  * Constructs a new <CODE>PdfAnnotation</CODE> of subtype link (Action).
  */
 public PdfAnnotation(PdfWriter writer, float llx, float lly, float urx, float ury, PdfAction action)
 {
     this.writer = writer;
     Put(PdfName.SUBTYPE, PdfName.LINK);
     Put(PdfName.RECT, new PdfRectangle(llx, lly, urx, ury));
     Put(PdfName.A, action);
     Put(PdfName.BORDER, new PdfBorderArray(0, 0, 0));
     Put(PdfName.C, new PdfColor(0x00, 0x00, 0xFF));
 }
コード例 #32
0
ファイル: PdfStamperImp.cs プロジェクト: hjgode/iTextSharpCF
 /** Additional-actions defining the actions to be taken in
 * response to various trigger events affecting the document
 * as a whole. The actions types allowed are: <CODE>DOCUMENT_CLOSE</CODE>,
 * <CODE>WILL_SAVE</CODE>, <CODE>DID_SAVE</CODE>, <CODE>WILL_PRINT</CODE>
 * and <CODE>DID_PRINT</CODE>.
 *
 * @param actionType the action type
 * @param action the action to execute in response to the trigger
 * @throws PdfException on invalid action type
 */
 public override void SetAdditionalAction(PdfName actionType, PdfAction action)
 {
     if (!(actionType.Equals(DOCUMENT_CLOSE) ||
     actionType.Equals(WILL_SAVE) ||
     actionType.Equals(DID_SAVE) ||
     actionType.Equals(WILL_PRINT) ||
     actionType.Equals(DID_PRINT))) {
         throw new PdfException("Invalid additional action type: " + actionType.ToString());
     }
     PdfDictionary aa = (PdfDictionary)PdfReader.GetPdfObject(reader.Catalog.Get(PdfName.AA));
     if (aa == null) {
         if (action == null)
             return;
         aa = new PdfDictionary();
         reader.Catalog.Put(PdfName.AA, aa);
     }
     MarkUsed(aa);
     if (action == null)
         aa.Remove(actionType);
     else
         aa.Put(actionType, action);
 }
コード例 #33
0
 /**
  * Constructs a <CODE>PdfOutline</CODE>.
  * <P>
  * This is the constructor for an <CODE>outline entry</CODE>. The open mode is
  * <CODE>true</CODE>.
  *
  * @param parent the parent of this outline item
  * @param action the <CODE>PdfAction</CODE> for this outline item
  * @param title the title of this outline item
  */
 public PdfOutline(PdfOutline parent, PdfAction action, Paragraph title)
     : this(parent, action, title, true)
 {
 }
コード例 #34
0
 /**
  * Constructs a <CODE>PdfOutline</CODE>.
  * <P>
  * This is the constructor for an <CODE>outline entry</CODE>.
  *
  * @param parent the parent of this outline item
  * @param action the <CODE>PdfAction</CODE> for this outline item
  * @param title the title of this outline item
  * @param open <CODE>true</CODE> if the children are visible
  */
 public PdfOutline(PdfOutline parent, PdfAction action, string title, bool open)
     : base()
 {
     this.action = action;
     InitOutline(parent, title, open);
 }
コード例 #35
0
        public void CreateTaggedPdf13() {
            InitializeDocument("13");

            Paragraph p = new Paragraph();
            Chunk chunk = new Chunk("Please visit ");
            p.Add(chunk);

            PdfAction action = new PdfAction("http://itextpdf.com");
            chunk = new Chunk("http://itextpdf.com",
                              new Font(Font.FontFamily.HELVETICA, Font.UNDEFINED, Font.UNDERLINE, BaseColor.BLUE));
            chunk.SetAction(action);
            p.Add(chunk);
            p.Add(new Chunk(" for more details."));
            document.Add(p);
            document.Close();
//            int[] nums = new int[] {5};
//            CheckNums(nums);
            CompareResults("13");
        }
コード例 #36
0
 /**
  * Constructs a <CODE>PdfOutline</CODE>.
  * <P>
  * This is the constructor for an <CODE>outline entry</CODE>.
  *
  * @param parent the parent of this outline item
  * @param action the <CODE>PdfAction</CODE> for this outline item
  * @param title the title of this outline item
  * @param open <CODE>true</CODE> if the children are visible
  */
 public PdfOutline(PdfOutline parent, PdfAction action, PdfString title, bool open)
     : this(parent, action, title.ToString(), open)
 {
 }
コード例 #37
0
        /// <summary>
        /// Constructs a new  PdfAnnotation  of subtype link (Action).
        /// </summary>

        public PdfAnnotation(PdfWriter writer, float llx, float lly, float urx, float ury, PdfAction action)
        {
            Writer = writer;
            Put(PdfName.Subtype, PdfName.Link);
            Put(PdfName.Rect, new PdfRectangle(llx, lly, urx, ury));
            Put(PdfName.A, action);
            Put(PdfName.Border, new PdfBorderArray(0, 0, 0));
            Put(PdfName.C, new PdfColor(0x00, 0x00, 0xFF));
        }
コード例 #38
0
 /**
  * Constructs a <CODE>PdfOutline</CODE>.
  * <P>
  * This is the constructor for an <CODE>outline entry</CODE>.
  *
  * @param parent the parent of this outline item
  * @param action the <CODE>PdfAction</CODE> for this outline item
  * @param title the title of this outline item
  * @param open <CODE>true</CODE> if the children are visible
  */
 public PdfOutline(PdfOutline parent, PdfAction action, Paragraph title, bool open)
     : base()
 {
     StringBuilder buf = new StringBuilder();
     foreach (Chunk chunk in title.Chunks) {
         buf.Append(chunk.Content);
     }
     this.action = action;
     InitOutline(parent, buf.ToString(), open);
 }
コード例 #39
0
        public static PdfAnnotation CreateLink(PdfWriter writer, Rectangle rect, PdfName highlight, PdfAction action)
        {
            PdfAnnotation annot = CreateLink(writer, rect, highlight);

            annot.PutEx(PdfName.A, action);
            return(annot);
        }
コード例 #40
0
 /** Implements an action in an area.
 * @param action the <CODE>PdfAction</CODE>
 * @param llx the lower left x corner of the activation area
 * @param lly the lower left y corner of the activation area
 * @param urx the upper right x corner of the activation area
 * @param ury the upper right y corner of the activation area
 */
 internal void SetAction(PdfAction action, float llx, float lly, float urx, float ury) {
     AddAnnotation(new PdfAnnotation(writer, llx, lly, urx, ury, action));
 }
コード例 #41
0
        /**
         * Constructs a new <CODE>PdfAnnotation</CODE> of subtype link (Action).
         */

        public PdfFormField(PdfWriter writer, float llx, float lly, float urx, float ury, PdfAction action) : base(writer, llx, lly, urx, ury, action)
        {
            Put(PdfName.TYPE, PdfName.ANNOT);
            Put(PdfName.SUBTYPE, PdfName.WIDGET);
            annotation = true;
        }
コード例 #42
0
 internal void AddJavaScript(String name, PdfAction js) {
     if (js.Get(PdfName.JS) == null)
         throw new ArgumentException(MessageLocalization.GetComposedMessage("only.javascript.actions.are.allowed"));
     documentLevelJS[name] = writer.AddToBody(js).IndirectReference;
 }
コード例 #43
0
        /// <summary>
        /// Constructs a new  PdfAnnotation  of subtype link (Action).
        /// </summary>

        public PdfFormField(PdfWriter writer, float llx, float lly, float urx, float ury, PdfAction action) : base(writer, llx, lly, urx, ury, action)
        {
            Put(PdfName.TYPE, PdfName.Annot);
            Put(PdfName.Subtype, PdfName.Widget);
            Annotation = true;
        }
コード例 #44
0
 internal void AddAdditionalAction(PdfName actionType, PdfAction action)  {
     if (additionalActions == null)  {
         additionalActions = new PdfDictionary();
     }
     if (action == null)
         additionalActions.Remove(actionType);
     else
         additionalActions.Put(actionType, action);
     if (additionalActions.Size == 0)
         additionalActions = null;
 }
コード例 #45
0
 /**
  * Sets the field value as a <CODE>PDFAction</CODE>.
  * For example, this method allows setting a form submit button action using {@link PdfAction#createSubmitForm(String, Object[], int)}.
  * This method creates an <CODE>A</CODE> entry for the specified field in the underlying FDF file.
  * Method contributed by Philippe Laflamme (plaflamme)
  * @param field the fully qualified field name
  * @param action the field's action
  * @return <CODE>true</CODE> if the value was inserted,
  * <CODE>false</CODE> if the name is incompatible with
  * an existing field
  * @since	2.1.5
  */
 virtual public bool SetFieldAsAction(String field, PdfAction action)
 {
     return(SetField(field, action));
 }
コード例 #46
0
        /**
        * Signals that an <CODE>Element</CODE> was added to the <CODE>Document</CODE>.
        *
        * @param element the element to add
        * @return <CODE>true</CODE> if the element was added, <CODE>false</CODE> if not.
        * @throws DocumentException when a document isn't open yet, or has been closed
        */
        public override bool Add(IElement element) {
            if (writer != null && writer.IsPaused()) {
                return false;
            }
            if (element.Type != Element.DIV) {
                FlushFloatingElements();
            }
            switch (element.Type) {
                
                // Information (headers)
                case Element.HEADER:
                    info.Addkey(((Meta)element).Name, ((Meta)element).Content);
                    break;
                case Element.TITLE:
                    info.AddTitle(((Meta)element).Content);
                    break;
                case Element.SUBJECT:
                    info.AddSubject(((Meta)element).Content);
                    break;
                case Element.KEYWORDS:
                    info.AddKeywords(((Meta)element).Content);
                    break;
                case Element.AUTHOR:
                    info.AddAuthor(((Meta)element).Content);
                    break;
                case Element.CREATOR:
                    info.AddCreator(((Meta)element).Content);
                    break;
                case Element.LANGUAGE:
                    SetLanguage(((Meta)element).Content);
                    break;
                case Element.PRODUCER:
                    // you can not change the name of the producer
                    info.AddProducer();
                    break;
                case Element.CREATIONDATE:
                    // you can not set the creation date, only reset it
                    info.AddCreationDate();
                    break;
                    
                    // content (text)
                case Element.CHUNK: {
                    // if there isn't a current line available, we make one
                    if (line == null) {
                        CarriageReturn();
                    }
                    
                    // we cast the element to a chunk
                    PdfChunk chunk = new PdfChunk((Chunk) element, anchorAction, tabSettings);
                    // we try to add the chunk to the line, until we succeed
                    {
                        PdfChunk overflow;
                        while ((overflow = line.Add(chunk)) != null) {
                            CarriageReturn();
                            bool newlineSplit = chunk.IsNewlineSplit();
                            chunk = overflow;
                            if (!newlineSplit)
                                chunk.TrimFirstSpace();
                        }
                    }
                    pageEmpty = false;
                    if (chunk.IsAttribute(Chunk.NEWPAGE)) {
                        NewPage();
                    }
                    break;
                }
                case Element.ANCHOR: {
                    Anchor anchor = (Anchor) element;
                    String url = anchor.Reference;
                    leading = anchor.Leading;
                    PushLeading();
                    if (url != null) {
                        anchorAction = new PdfAction(url);
                    }
                    
                    // we process the element
                    element.Process(this);
                    anchorAction = null;
                    PopLeading();
                    break;
                }
                case Element.ANNOTATION: {
                    if (line == null) {
                        CarriageReturn();
                    }
                    Annotation annot = (Annotation) element;
                    Rectangle rect = new Rectangle(0, 0);
                    if (line != null)
                        rect = new Rectangle(annot.GetLlx(IndentRight - line.WidthLeft), annot.GetUry(IndentTop - currentHeight - 20), annot.GetUrx(IndentRight - line.WidthLeft + 20), annot.GetLly(IndentTop - currentHeight));
                    PdfAnnotation an = PdfAnnotationsImp.ConvertAnnotation(writer, annot, rect);
                    annotationsImp.AddPlainAnnotation(an);
                    pageEmpty = false;
                    break;
                }
                case Element.PHRASE: {
                    TabSettings backupTabSettings = tabSettings;
                    if (((Phrase)element).TabSettings != null)
                        tabSettings = ((Phrase)element).TabSettings;

                    // we cast the element to a phrase and set the leading of the document
                    leading = ((Phrase) element).TotalLeading;
                    PushLeading();
                    // we process the element
                    element.Process(this);
                    tabSettings = backupTabSettings;
                    PopLeading();
                    break;
                }
                case Element.PARAGRAPH: {
                    TabSettings backupTabSettings = tabSettings;
                    if (((Phrase)element).TabSettings != null)
                        tabSettings = ((Phrase)element).TabSettings;

                    // we cast the element to a paragraph
                    Paragraph paragraph = (Paragraph) element;
                    if (IsTagged(writer))
                    {
                        FlushLines();
                        text.OpenMCBlock(paragraph);
                    }
                    AddSpacing(paragraph.SpacingBefore, leading, paragraph.Font);
                    
                    // we adjust the parameters of the document
                    alignment = paragraph.Alignment;
                    leading = paragraph.TotalLeading;
                    PushLeading();
                    
                    CarriageReturn();
                    // we don't want to make orphans/widows
                    if (currentHeight + line.Height + leading > IndentTop - IndentBottom) {
                        NewPage();
                    }

                    indentation.indentLeft += paragraph.IndentationLeft;
                    indentation.indentRight += paragraph.IndentationRight;
                    
                    CarriageReturn();

                    IPdfPageEvent pageEvent = writer.PageEvent;
                    if (pageEvent != null && !isSectionTitle)
                        pageEvent.OnParagraph(writer, this, IndentTop - currentHeight);
                    
                    // if a paragraph has to be kept together, we wrap it in a table object
                    if (paragraph.KeepTogether) {
                        CarriageReturn();
                        PdfPTable table = new PdfPTable(1);
                        table.KeepTogether = paragraph.KeepTogether;
                        table.WidthPercentage = 100f;
                        PdfPCell cell = new PdfPCell();
                        cell.AddElement(paragraph);
                        cell.Border = Rectangle.NO_BORDER;
                        cell.Padding = 0;
                        table.AddCell(cell);
                        indentation.indentLeft -= paragraph.IndentationLeft;
                        indentation.indentRight -= paragraph.IndentationRight;
                        this.Add(table);
                        indentation.indentLeft += paragraph.IndentationLeft;
                        indentation.indentRight += paragraph.IndentationRight;
                    }
                    else {
                        line.SetExtraIndent(paragraph.FirstLineIndent);
                        element.Process(this);
                        CarriageReturn();
                        AddSpacing(paragraph.SpacingAfter, paragraph.TotalLeading, paragraph.Font);
                    }
                    
                    if (pageEvent != null && !isSectionTitle)
                        pageEvent.OnParagraphEnd(writer, this, IndentTop - currentHeight);
                    
                    alignment = Element.ALIGN_LEFT;
                    indentation.indentLeft -= paragraph.IndentationLeft;
                    indentation.indentRight -= paragraph.IndentationRight;
                    CarriageReturn();
                    tabSettings = backupTabSettings;
                    PopLeading();
                    if (IsTagged(writer))
                    {
                        FlushLines();
                        text.CloseMCBlock(paragraph);
                    }
                    break;
                }
                case Element.SECTION:
                case Element.CHAPTER: {
                    // Chapters and Sections only differ in their constructor
                    // so we cast both to a Section
                    Section section = (Section) element;
                    IPdfPageEvent pageEvent = writer.PageEvent;
                    
                    bool hasTitle = section.NotAddedYet && section.Title != null;
                    
                    // if the section is a chapter, we begin a new page
                    if (section.TriggerNewPage) {
                        NewPage();
                    }

                    if (hasTitle) {
                        float fith = IndentTop - currentHeight;
                        int rotation = pageSize.Rotation;
                        if (rotation == 90 || rotation == 180)
                            fith = pageSize.Height - fith;
                        PdfDestination destination = new PdfDestination(PdfDestination.FITH, fith);
                        while (currentOutline.Level >= section.Depth) {
                            currentOutline = currentOutline.Parent;
                        }
                        PdfOutline outline = new PdfOutline(currentOutline, destination, section.GetBookmarkTitle(), section.BookmarkOpen);
                        currentOutline = outline;
                    }
                    
                    // some values are set
                    CarriageReturn();
                    indentation.sectionIndentLeft += section.IndentationLeft;
                    indentation.sectionIndentRight += section.IndentationRight;                    
                    if (section.NotAddedYet && pageEvent != null)
                        if (element.Type == Element.CHAPTER)
                            pageEvent.OnChapter(writer, this, IndentTop - currentHeight, section.Title);
                        else
                            pageEvent.OnSection(writer, this, IndentTop - currentHeight, section.Depth, section.Title);
                    
                    // the title of the section (if any has to be printed)
                    if (hasTitle) {
                        isSectionTitle = true;
                        Add(section.Title);
                        isSectionTitle = false;
                    }
                    indentation.sectionIndentLeft += section.Indentation;
                    // we process the section
                    element.Process(this);
                    // some parameters are set back to normal again
                    indentation.sectionIndentLeft -= (section.IndentationLeft + section.Indentation);
                    indentation.sectionIndentRight -= section.IndentationRight;
                    
                    if (section.ElementComplete && pageEvent != null)
                        if (element.Type == Element.CHAPTER)
                            pageEvent.OnChapterEnd(writer, this, IndentTop - currentHeight);
                        else
                            pageEvent.OnSectionEnd(writer, this, IndentTop - currentHeight);
                    
                    break;
                }
                case Element.LIST: {
                    // we cast the element to a List
                    List list = (List) element;
                    if (IsTagged(writer))
                    {
                        FlushLines();
                        text.OpenMCBlock(list);
                    }
                    if (list.Alignindent) {
                        list.NormalizeIndentation();
                    }
                    // we adjust the document
                    indentation.listIndentLeft += list.IndentationLeft;
                    indentation.indentRight += list.IndentationRight;
                    // we process the items in the list
                    element.Process(this);
                    // some parameters are set back to normal again
                    indentation.listIndentLeft -= list.IndentationLeft;
                    indentation.indentRight -= list.IndentationRight;
                    CarriageReturn();
                    if (IsTagged(writer))
                    {
                        FlushLines();
                        text.CloseMCBlock(list);
                    }
                    break;
                }
                case Element.LISTITEM: {
                    // we cast the element to a ListItem
                    ListItem listItem = (ListItem) element;
                    if (IsTagged(writer)) {
                        FlushLines();
                        text.OpenMCBlock(listItem);
                    }
                    AddSpacing(listItem.SpacingBefore, leading, listItem.Font);
                    
                    // we adjust the document
                    alignment = listItem.Alignment;
                    indentation.listIndentLeft += listItem.IndentationLeft;
                    indentation.indentRight += listItem.IndentationRight;
                    leading = listItem.TotalLeading;
                    PushLeading();
                    CarriageReturn();
                    // we prepare the current line to be able to show us the listsymbol
                    line.ListItem = listItem;
                    // we process the item
                    element.Process(this);

                    AddSpacing(listItem.SpacingAfter, listItem.TotalLeading, listItem.Font);
                    
                    // if the last line is justified, it should be aligned to the left
                    if (line.HasToBeJustified()) {
                        line.ResetAlignment();
                    }
                    // some parameters are set back to normal again
                    CarriageReturn();
                    indentation.listIndentLeft -= listItem.IndentationLeft;
                    indentation.indentRight -= listItem.IndentationRight;
                    PopLeading();
                    if (IsTagged(writer))
                    {
                        FlushLines();
                        text.CloseMCBlock(listItem.ListBody);
                        text.CloseMCBlock(listItem);
                    }
                    break;
                }
                case Element.RECTANGLE: {
                    Rectangle rectangle = (Rectangle) element;
                    graphics.Rectangle(rectangle);
                    pageEmpty = false;
                    break;
                }
                case Element.PTABLE: {
                    PdfPTable ptable = (PdfPTable)element;
                    if (ptable.Size <= ptable.HeaderRows)
                        break; //nothing to do

                    // before every table, we add a new line and flush all lines
                    EnsureNewLine();
                    FlushLines();
                    
                    AddPTable(ptable);
                    pageEmpty = false;
                    NewLine();
                    break;
                }
                case Element.JPEG:
                case Element.JPEG2000:
                case Element.JBIG2:
                case Element.IMGRAW:
                case Element.IMGTEMPLATE: {
                    //carriageReturn(); suggestion by Marc Campforts
                    if(IsTagged(writer)) {
                        FlushLines();
                        text.OpenMCBlock((Image)element);
                    }
                    Add((Image)element);
                    if(IsTagged(writer)) {
                        FlushLines();
                        text.CloseMCBlock((Image)element);
                    }
                    break;
                }
                case Element.YMARK: {
                    IDrawInterface zh = (IDrawInterface)element;
                    zh.Draw(graphics, IndentLeft, IndentBottom, IndentRight, IndentTop, IndentTop - currentHeight - (leadingStack.Count > 0 ? leading : 0));
                    pageEmpty = false;
                    break;
                }
                case Element.MARKED: {
                    MarkedObject mo;
                    if (element is MarkedSection) {
                        mo = ((MarkedSection)element).Title;
                        if (mo != null) {
                            mo.Process(this);
                        }
                    }
                    mo = (MarkedObject)element;
                    mo.Process(this);
                    break;
                }
                case Element.WRITABLE_DIRECT:
                    if (null != writer) {
                        ((IWriterOperation)element).Write(writer, this);
                    }
                    break;
                case Element.DIV:
                    EnsureNewLine();
                    FlushLines();
                    AddDiv((PdfDiv)element);
                    pageEmpty = false;
                    //newLine();
                    break;
                default:
                    return false;
            }
            lastElementType = element.Type;
            return true;
        }
コード例 #47
0
 /** Implements an action in an area.
  * @param action the <CODE>PdfAction</CODE>
  * @param llx the lower left x corner of the activation area
  * @param lly the lower left y corner of the activation area
  * @param urx the upper right x corner of the activation area
  * @param ury the upper right y corner of the activation area
  */
 public virtual void SetAction(PdfAction action, float llx, float lly, float urx, float ury)
 {
     pdf.SetAction(action, llx, lly, urx, ury);
 }
コード例 #48
0
 /**
 * Sets the open and close page additional action.
 * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE>
 * or <CODE>PdfWriter.PAGE_CLOSE</CODE>
 * @param action the action to perform
 * @param page the page where the action will be applied. The first page is 1
 * @throws PdfException if the action type is invalid
 */    
 internal void SetPageAction(PdfName actionType, PdfAction action, int page) {
     if (!actionType.Equals(PAGE_OPEN) && !actionType.Equals(PAGE_CLOSE))
         throw new PdfException(MessageLocalization.GetComposedMessage("invalid.page.additional.action.type.1", actionType.ToString()));
     PdfDictionary pg = reader.GetPageN(page);
     PdfDictionary aa = (PdfDictionary)PdfReader.GetPdfObject(pg.Get(PdfName.AA), pg);
     if (aa == null) {
         aa = new PdfDictionary();
         pg.Put(PdfName.AA, aa);
         MarkUsed(pg);
     }
     aa.Put(actionType, action);
     MarkUsed(aa);
 }
コード例 #49
0
 /**
  * Sets the open and close page additional action.
  * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE>
  * or <CODE>PdfWriter.PAGE_CLOSE</CODE>
  * @param action the action to perform
  * @param page the page where the action will be applied. The first page is 1
  * @throws PdfException if the action type is invalid
  */
 public void SetPageAction(PdfName actionType, PdfAction action, int page)
 {
     stamper.SetPageAction(actionType, action, page);
 }
コード例 #50
0
 /**
 * @see com.lowagie.text.pdf.PdfWriter#setOpenAction(com.lowagie.text.pdf.PdfAction)
 */
 public override void SetOpenAction(PdfAction action) {
     openAction = action;
 }
コード例 #51
0
ファイル: StampContent.cs プロジェクト: bmictech/iTextSharp
 public override void SetAction(PdfAction action, float llx, float lly, float urx, float ury)
 {
     ((PdfStamperImp)writer).AddAnnotation(new PdfAnnotation(writer, llx, lly, urx, ury, action), ps.pageN);
 }
コード例 #52
0
 /**
 * Use this method to add a JavaScript action at the document level.
 * When the document opens, all this JavaScript runs.
 * @param name The name of the JS Action in the name tree
 * @param js The JavaScript action
 */
 public void AddJavaScript(String name, PdfAction js) {
     pdf.AddJavaScript(name, js);
 }
コード例 #53
0
 /**
  * Constructs a <CODE>PdfChunk</CODE>-object.
  *
  * @param chunk     the original <CODE>Chunk</CODE>-object
  * @param action    the <CODE>PdfAction</CODE> if the <CODE>Chunk</CODE> comes from an <CODE>Anchor</CODE>
  * @param tabSettings  the Phrase tab settings
  */
 internal PdfChunk(Chunk chunk, PdfAction action, TabSettings tabSettings)
     : this(chunk, action) {
     if (tabSettings != null) {
         if (!attributes.ContainsKey(Chunk.TABSETTINGS)
             || attributes[Chunk.TABSETTINGS] == null)
         attributes[Chunk.TABSETTINGS] = tabSettings;
     }
 }
コード例 #54
0
 /** Additional-actions defining the actions to be taken in
 * response to various trigger events affecting the document
 * as a whole. The actions types allowed are: <CODE>DOCUMENT_CLOSE</CODE>,
 * <CODE>WILL_SAVE</CODE>, <CODE>DID_SAVE</CODE>, <CODE>WILL_PRINT</CODE>
 * and <CODE>DID_PRINT</CODE>.
 *
 * @param actionType the action type
 * @param action the action to execute in response to the trigger
 * @throws PdfException on invalid action type
 */
 public virtual void SetAdditionalAction(PdfName actionType, PdfAction action) {
     if (!(actionType.Equals(DOCUMENT_CLOSE) ||
     actionType.Equals(WILL_SAVE) ||
     actionType.Equals(DID_SAVE) ||
     actionType.Equals(WILL_PRINT) ||
     actionType.Equals(DID_PRINT))) {
         throw new PdfException(MessageLocalization.GetComposedMessage("invalid.additional.action.type.1", actionType.ToString()));
     }
     pdf.AddAdditionalAction(actionType, action);
 }
コード例 #55
0
 /**
 * Sets the open and close page additional action.
 * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE>
 * or <CODE>PdfWriter.PAGE_CLOSE</CODE>
 * @param action the action to perform
 * @param page the page where the action will be applied. The first page is 1
 * @throws PdfException if the action type is invalid
 */    
 virtual public void SetPageAction(PdfName actionType, PdfAction action, int page) {
     stamper.SetPageAction(actionType, action, page);
 }
コード例 #56
0
      /**
       * Constructs a <CODE>PdfChunk</CODE>-object.
       *
       * @param chunk the original <CODE>Chunk</CODE>-object
       * @param action the <CODE>PdfAction</CODE> if the <CODE>Chunk</CODE> comes from an <CODE>Anchor</CODE>
       */
 
      internal PdfChunk(Chunk chunk, PdfAction action) {
          thisChunk[0] = this;
          value = chunk.Content;
      
          Font f = chunk.Font;
          float size = f.Size;
          if (size == iTextSharp.text.Font.UNDEFINED)
              size = 12;
          baseFont = f.BaseFont;
          BaseFont bf = f.BaseFont;
          int style = f.Style;
          if (style == iTextSharp.text.Font.UNDEFINED) {
              style = iTextSharp.text.Font.NORMAL;
          }
          if (baseFont == null) {
              // translation of the font-family to a PDF font-family
              baseFont = f.GetCalculatedBaseFont(false);
          }
          else{
              // bold simulation
              if ((style & iTextSharp.text.Font.BOLD) != 0)
                  attributes[Chunk.TEXTRENDERMODE] = new Object[]{PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, size / 30f, null};
              // italic simulation
              if ((style & iTextSharp.text.Font.ITALIC) != 0)
                  attributes[Chunk.SKEW] = new float[]{0, ITALIC_ANGLE};
          }
          font = new PdfFont(baseFont, size);
          // other style possibilities
          Dictionary<string,object> attr = chunk.Attributes;
          if (attr != null) {
              foreach (KeyValuePair<string,object> entry in attr) {
                  string name = entry.Key;
                  if (keysAttributes.ContainsKey(name)) {
                      attributes[name] = entry.Value;
                  }
                  else if (keysNoStroke.ContainsKey(name)) {
                      noStroke[name] = entry.Value;
                  }
              }
              if (attr.ContainsKey(Chunk.GENERICTAG) && "".Equals(attr[Chunk.GENERICTAG])) {
                  attributes[Chunk.GENERICTAG] = chunk.Content;
              }
          }
          if (f.IsUnderlined()) {
              Object[] obj = {null, new float[]{0, 1f / 15, 0, -1f / 3, 0}};
              Object[][] obja = null;
              if (attributes.ContainsKey(Chunk.UNDERLINE))
                  obja = (Object[][])attributes[Chunk.UNDERLINE];
              Object[][] unders = Utilities.AddToArray(obja, obj);
              attributes[Chunk.UNDERLINE] = unders;
          }
          if (f.IsStrikethru()) {
              Object[] obj = {null, new float[]{0, 1f / 15, 0, 1f / 3, 0}};
              Object[][] obja = null;
              if (attributes.ContainsKey(Chunk.UNDERLINE))
                  obja = (Object[][])attributes[Chunk.UNDERLINE];
              Object[][] unders = Utilities.AddToArray(obja, obj);
              attributes[Chunk.UNDERLINE] = unders;
          }
          if (action != null)
              attributes[Chunk.ACTION] = action;
          // the color can't be stored in a PdfFont
          noStroke[Chunk.COLOR] = f.Color;
          noStroke[Chunk.ENCODING] = font.Font.Encoding;
          Object[] obj2 = null;
          if (attributes.ContainsKey(Chunk.IMAGE))
              obj2 = (Object[])attributes[Chunk.IMAGE];
          if (obj2 == null)
              image = null;
          else {
              attributes.Remove(Chunk.HSCALE); // images are scaled in other ways
              image = (Image)obj2[0];
              offsetX = ((float)obj2[1]);
              offsetY = ((float)obj2[2]);
              changeLeading = (bool)obj2[3];
          }
          font.Image = image;
          object hs;
          attributes.TryGetValue(Chunk.HSCALE, out hs);
          if (hs != null)
              font.HorizontalScaling = (float)hs;
          encoding = font.Font.Encoding;
          if (noStroke.ContainsKey(Chunk.SPLITCHARACTER))
              splitCharacter = (ISplitCharacter)noStroke[Chunk.SPLITCHARACTER];
          else
              splitCharacter = DefaultSplitCharacter.DEFAULT;
      }
コード例 #57
0
        /**
         * Constructs a <CODE>PdfChunk</CODE>-object.
         *
         * @param chunk the original <CODE>Chunk</CODE>-object
         * @param action the <CODE>PdfAction</CODE> if the <CODE>Chunk</CODE> comes from an <CODE>Anchor</CODE>
         */

        internal PdfChunk(Chunk chunk, PdfAction action)
        {
            thisChunk[0] = this;
            value        = chunk.Content;

            Font  f    = chunk.Font;
            float size = f.Size;

            if (size == iTextSharp.text.Font.UNDEFINED)
            {
                size = 12;
            }
            baseFont = f.BaseFont;
            BaseFont bf    = f.BaseFont;
            int      style = f.Style;

            if (style == iTextSharp.text.Font.UNDEFINED)
            {
                style = iTextSharp.text.Font.NORMAL;
            }
            if (baseFont == null)
            {
                // translation of the font-family to a PDF font-family
                baseFont = f.GetCalculatedBaseFont(false);
            }
            else
            {
                // bold simulation
                if ((style & iTextSharp.text.Font.BOLD) != 0)
                {
                    attributes[Chunk.TEXTRENDERMODE] = new Object[] { PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, size / 30f, null }
                }
                ;
                // italic simulation
                if ((style & iTextSharp.text.Font.ITALIC) != 0)
                {
                    attributes[Chunk.SKEW] = new float[] { 0, ITALIC_ANGLE }
                }
                ;
            }
            font = new PdfFont(baseFont, size);
            // other style possibilities
            Hashtable attr = chunk.Attributes;

            if (attr != null)
            {
                foreach (string name in attr.Keys)
                {
                    if (keysAttributes.ContainsKey(name))
                    {
                        attributes[name] = attr[name];
                    }
                    else if (keysNoStroke.ContainsKey(name))
                    {
                        noStroke[name] = attr[name];
                    }
                }
                if ("".Equals(attr[Chunk.GENERICTAG]))
                {
                    attributes[Chunk.GENERICTAG] = chunk.Content;
                }
            }
            if (f.IsUnderlined())
            {
                Object[]   obj    = { null, new float[] { 0, 1f / 15, 0, -1f / 3, 0 } };
                Object[][] unders = Chunk.AddToArray((Object[][])attributes[Chunk.UNDERLINE], obj);
                attributes[Chunk.UNDERLINE] = unders;
            }
            if (f.IsStrikethru())
            {
                Object[]   obj    = { null, new float[] { 0, 1f / 15, 0, 1f / 3, 0 } };
                Object[][] unders = Chunk.AddToArray((Object[][])attributes[Chunk.UNDERLINE], obj);
                attributes[Chunk.UNDERLINE] = unders;
            }
            if (action != null)
            {
                attributes[Chunk.ACTION] = action;
            }
            // the color can't be stored in a PdfFont
            noStroke[Chunk.COLOR]    = f.Color;
            noStroke[Chunk.ENCODING] = font.Font.Encoding;
            Object[] obj2 = (Object[])attributes[Chunk.IMAGE];
            if (obj2 == null)
            {
                image = null;
            }
            else
            {
                attributes.Remove(Chunk.HSCALE); // images are scaled in other ways
                image         = (Image)obj2[0];
                offsetX       = ((float)obj2[1]);
                offsetY       = ((float)obj2[2]);
                changeLeading = (bool)obj2[3];
            }
            font.Image = image;
            object hs = attributes[Chunk.HSCALE];

            if (hs != null)
            {
                font.HorizontalScaling = (float)hs;
            }
            encoding       = font.Font.Encoding;
            splitCharacter = (ISplitCharacter)noStroke[Chunk.SPLITCHARACTER];
            if (splitCharacter == null)
            {
                splitCharacter = this;
            }
        }