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); }
public void Write(PDFRectangle rect) { const string format = Config.SignificantFigures3; WriteSeparator(CharCat.Delimiter, '/'); WriteRaw(PDFEncoders.Format("[{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "}]", rect.X1, rect.Y1, rect.X2, rect.Y2)); _lastCat = CharCat.Delimiter; }
public void WriteDocStringHex(string text) { WriteSeparator(CharCat.Delimiter); //WriteRaw(PDFEncoders.DocEncodeHex(text)); byte[] bytes = PDFEncoders.DocEncoding.GetBytes(text); bytes = PDFEncoders.FormatStringLiteral(bytes, false, false, true, SecurityHandler); Stream.Write(bytes, 0, bytes.Length); _lastCat = CharCat.Delimiter; }
public void WriteDocString(string text) { WriteSeparator(CharCat.Delimiter); //WriteRaw(PDFEncoders.DocEncode(text, false)); byte[] bytes = PDFEncoders.DocEncoding.GetBytes(text); bytes = PDFEncoders.FormatStringLiteral(bytes, false, false, false, SecurityHandler); Write(bytes); _lastCat = CharCat.Delimiter; }
/// <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; }
/// <summary> /// Setups the shading from the specified brush. /// </summary> internal void SetupFromBrush(XLinearGradientBrush brush, XGraphicsPDFRenderer renderer) { if (brush == null) { throw new ArgumentNullException("brush"); } PDFColorMode colorMode = _document.Options.ColorMode; XColor color1 = ColorSpaceHelper.EnsureColorMode(colorMode, brush._color1); XColor color2 = ColorSpaceHelper.EnsureColorMode(colorMode, brush._color2); PDFDictionary function = new PDFDictionary(); Elements[Keys.ShadingType] = new PDFInteger(2); Elements[Keys.ColorSpace] = colorMode != PDFColorMode.Cmyk ? new PDFName("/DeviceRGB") : new PDFName("/DeviceCMYK"); double x1 = 0, y1 = 0, x2 = 0, y2 = 0; if (brush._useRect) { XPoint pt1 = renderer.WorldToView(brush._rect.TopLeft); XPoint pt2 = renderer.WorldToView(brush._rect.BottomRight); switch (brush._linearGradientMode) { case XLinearGradientMode.Horizontal: x1 = pt1.X; y1 = pt1.Y; x2 = pt2.X; y2 = pt1.Y; break; case XLinearGradientMode.Vertical: x1 = pt1.X; y1 = pt1.Y; x2 = pt1.X; y2 = pt2.Y; break; case XLinearGradientMode.ForwardDiagonal: x1 = pt1.X; y1 = pt1.Y; x2 = pt2.X; y2 = pt2.Y; break; case XLinearGradientMode.BackwardDiagonal: x1 = pt2.X; y1 = pt1.Y; x2 = pt1.X; y2 = pt2.Y; break; } } else { XPoint pt1 = renderer.WorldToView(brush._point1); XPoint pt2 = renderer.WorldToView(brush._point2); x1 = pt1.X; y1 = pt1.Y; x2 = pt2.X; y2 = pt2.Y; } const string format = Config.SignificantFigures3; Elements[Keys.Coords] = new PDFLiteral("[{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "}]", x1, y1, x2, y2); //Elements[Keys.Background] = new PDFRawItem("[0 1 1]"); //Elements[Keys.Domain] = Elements[Keys.Function] = function; //Elements[Keys.Extend] = new PDFRawItem("[true true]"); string clr1 = "[" + PDFEncoders.ToString(color1, colorMode) + "]"; string clr2 = "[" + PDFEncoders.ToString(color2, colorMode) + "]"; function.Elements["/FunctionType"] = new PDFInteger(2); function.Elements["/C0"] = new PDFLiteral(clr1); function.Elements["/C1"] = new PDFLiteral(clr2); function.Elements["/Domain"] = new PDFLiteral("[0 1]"); function.Elements["/N"] = new PDFInteger(1); }