internal override void WriteObject(PDFWriter writer)
        {
            PDFPage dest = null;

            //pdf.AppendFormat(CultureInfo.InvariantCulture,
            //  "{0} 0 obj\n<<\n/Type/Annot\n/Subtype/Link\n" +
            //  "/Rect[{1} {2} {3} {4}]\n/BS<</Type/Border>>\n/Border[0 0 0]\n/C[0 0 0]\n",
            //  ObjectID.ObjectNumber, rect.X1, rect.Y1, rect.X2, rect.Y2);

            // Older Adobe Reader versions uses a border width of 0 as default value if neither Border nor BS are present.
            // But the PDF Reference specifies:
            // "If neither the Border nor the BS entry is present, the border is drawn as a solid line with a width of 1 point."
            // After this issue was fixed in newer Reader versions older PDFSharp created documents show an ugly solid border.
            // The following hack fixes this by specifying a 0 width border.
            if (Elements[PDFAnnotation.Keys.BS] == null)
            {
                Elements[PDFAnnotation.Keys.BS] = new PDFLiteral("<</Type/Border/W 0>>");
            }

            // May be superfluous. See comment above.
            if (Elements[PDFAnnotation.Keys.Border] == null)
            {
                Elements[PDFAnnotation.Keys.Border] = new PDFLiteral("[0 0 0]");
            }

            switch (_linkType)
            {
            case LinkType.None:
                break;

            case LinkType.Document:
                // destIndex > Owner.PageCount can happen when rendering pages using PDFSharp directly.
                int destIndex = _destPage;
                if (destIndex > Owner.PageCount)
                {
                    destIndex = Owner.PageCount;
                }
                destIndex--;
                dest = Owner.Pages[destIndex];
                //pdf.AppendFormat("/Dest[{0} 0 R/XYZ null null 0]\n", dest.ObjectID);
                Elements[Keys.Dest] = new PDFLiteral("[{0} 0 R/XYZ null null 0]", dest.ObjectNumber);
                break;

            case LinkType.Web:
                //pdf.AppendFormat("/A<</S/URI/URI{0}>>\n", PDFEncoders.EncodeAsLiteral(url));
                Elements[PDFAnnotation.Keys.A] = new PDFLiteral("<</S/URI/URI{0}>>",     //PDFEncoders.EncodeAsLiteral(url));
                                                                PDFEncoders.ToStringLiteral(_url, PDFStringEncoding.WinAnsiEncoding, writer.SecurityHandler));
                break;

            case LinkType.File:
                //pdf.AppendFormat("/A<</Type/Action/S/Launch/F<</Type/Filespec/F{0}>> >>\n",
                //  PDFEncoders.EncodeAsLiteral(url));
                Elements[PDFAnnotation.Keys.A] = new PDFLiteral("<</Type/Action/S/Launch/F<</Type/Filespec/F{0}>> >>",
                                                                //PDFEncoders.EncodeAsLiteral(url));
                                                                PDFEncoders.ToStringLiteral(_url, PDFStringEncoding.WinAnsiEncoding, writer.SecurityHandler));
                break;
            }
            base.WriteObject(writer);
        }
示例#2
0
        /// <summary>
        /// Writes the specified value to the PDF stream.
        /// </summary>
        public void Write(PDFString value)
        {
            WriteSeparator(CharCat.Delimiter);
#if true
            PDFStringEncoding encoding = (PDFStringEncoding)(value.Flags & PDFStringFlags.EncodingMask);
            string            pdf      = (value.Flags & PDFStringFlags.HexLiteral) == 0 ?
                                         PDFEncoders.ToStringLiteral(value.Value, encoding, SecurityHandler) :
                                         PDFEncoders.ToHexStringLiteral(value.Value, encoding, SecurityHandler);
            WriteRaw(pdf);
#else
            switch (value.Flags & PDFStringFlags.EncodingMask)
            {
            case PDFStringFlags.Undefined:
            case PDFStringFlags.PDFDocEncoding:
                if ((value.Flags & PDFStringFlags.HexLiteral) == 0)
                {
                    WriteRaw(PDFEncoders.DocEncode(value.Value, false));
                }
                else
                {
                    WriteRaw(PDFEncoders.DocEncodeHex(value.Value, false));
                }
                break;

            case PDFStringFlags.WinAnsiEncoding:
                throw new NotImplementedException("Unexpected encoding: WinAnsiEncoding");

            case PDFStringFlags.Unicode:
                if ((value.Flags & PDFStringFlags.HexLiteral) == 0)
                {
                    WriteRaw(PDFEncoders.DocEncode(value.Value, true));
                }
                else
                {
                    WriteRaw(PDFEncoders.DocEncodeHex(value.Value, true));
                }
                break;

            case PDFStringFlags.StandardEncoding:
            case PDFStringFlags.MacRomanEncoding:
            case PDFStringFlags.MacExpertEncoding:
            default:
                throw new NotImplementedException("Unexpected encoding");
            }
#endif
            _lastCat = CharCat.Delimiter;
        }