/// <summary> /// Returns PDF string representation /// </summary> public string ToPdfString() { var r = TextAdapter.FormatFloat((float)R / byte.MaxValue); var g = TextAdapter.FormatFloat((float)G / byte.MaxValue); var b = TextAdapter.FormatFloat((float)B / byte.MaxValue); return COLOR_PDF_FORMAT.Args(r, g, b); }
/// <summary> /// Returns PDF string representation on the line primitive /// </summary> /// <returns></returns> public override string ToPdfString() { return(BEZIER_TO_FORMAT.Args(TextAdapter.FormatFloat(FirstControlX), TextAdapter.FormatFloat(FirstControlY), TextAdapter.FormatFloat(SecondControlX), TextAdapter.FormatFloat(SecondControlY), TextAdapter.FormatFloat(EndX), TextAdapter.FormatFloat(EndY))); }
/// <summary> /// Writes PDF text element into file stream /// </summary> /// <param name="text">PDF text element</param> internal void Write(TextElement text) { var escapedText = TextAdapter.FixEscapes(text.Content); var pdfStreamBuilder = new StringBuilder(); pdfStreamBuilder.AppendLine("q"); pdfStreamBuilder.AppendLine("BT"); pdfStreamBuilder.AppendFormatLine("{0} {1} Tf", text.Font.GetResourceReference(), TextAdapter.FormatFloat(text.FontSize)); pdfStreamBuilder.AppendFormatLine("{0} rg", text.Color.ToPdfString()); pdfStreamBuilder.AppendFormatLine("{0} {1} Td", TextAdapter.FormatFloat(text.X), TextAdapter.FormatFloat(text.Y)); pdfStreamBuilder.AppendFormatLine("({0}) Tj", escapedText); pdfStreamBuilder.AppendLine("ET"); pdfStreamBuilder.Append("Q"); writeStreamedObject(text.ObjectId, pdfStreamBuilder.ToString()); }
/// <summary> /// Writes PDF rectangle element into file stream /// </summary> /// <param name="rectangle">PDF rectangle element</param> internal void Write(RectangleElement rectangle) { var x = TextAdapter.FormatFloat(rectangle.X); var y = TextAdapter.FormatFloat(rectangle.Y); var w = TextAdapter.FormatFloat(rectangle.X1 - rectangle.X); var h = TextAdapter.FormatFloat(rectangle.Y1 - rectangle.Y); var rectangleContent = new StringBuilder(); rectangleContent.AppendLine("q"); rectangleContent.Append(rectangle.Style.ToPdfString()); rectangleContent.AppendFormatLine("{0} {1} {2} {3} re", x, y, w, h); rectangleContent.AppendLine("B"); rectangleContent.Append("Q"); writeStreamedObject(rectangle.ObjectId, rectangleContent.ToString()); }
/// <summary> /// Returns PDF string representation /// </summary> public string ToPdfString() { var styleBuilder = new StringBuilder(); if (StrokeColor != null) { styleBuilder.AppendFormatLine("{0} RG", StrokeColor.ToPdfString()); } if (FillColor != null) { styleBuilder.AppendFormatLine("{0} rg", FillColor.ToPdfString()); } if (StrokeThickness != null) { styleBuilder.AppendFormatLine("{0} w", TextAdapter.FormatFloat(StrokeThickness.Value)); } if (StrokeType != null) { switch (StrokeType) { case PdfLineType.OutlinedThin: styleBuilder.AppendLine("[2 2] 0 d"); break; case PdfLineType.Outlined: styleBuilder.AppendLine("[4 4] 0 d"); break; case PdfLineType.OutlinedBold: styleBuilder.AppendLine("[6 6] 0 d"); break; } } return(styleBuilder.ToString()); }
/// <summary> /// Writes PDF path into file stream /// </summary> /// <param name="path">PDF path element</param> internal void Write(PathElement path) { var x = TextAdapter.FormatFloat(path.X); var y = TextAdapter.FormatFloat(path.Y); var pathCoordinates = new List <string> { PATH_START_FORMAT.Args(x, y) }; pathCoordinates.AddRange(path.Primitives.Select(p => p.ToPdfString())); var closeTag = path.IsClosed ? "B" : "S"; var pathContent = new StringBuilder(); pathContent.AppendLine("q"); pathContent.Append(path.Style.ToPdfString()); pathContent.AppendFormatLine(string.Join(Constants.SPACE, pathCoordinates)); pathContent.AppendLine(closeTag); pathContent.Append("Q"); writeStreamedObject(path.ObjectId, pathContent.ToString()); }
/// <summary> /// Writes PDF page into file stream /// </summary> /// <param name="page">PDF page</param> internal void Write(PdfPage page) { var resourcesBuilder = new StringBuilder(); var elements = string.Join(Constants.SPACE.ToString(), page.Elements.Select(p => p.GetReference())); var images = string.Join(Constants.SPACE.ToString(), page.Elements.OfType <ImageElement>().Select(p => p.GetCoupledReference())); var fonts = string.Join(Constants.SPACE, page.Fonts.Select(p => FONTS_REFERENCE_FORMAT.Args(p.GetResourceReference(), p.GetReference()))); if (fonts.Length > 0) { resourcesBuilder.AppendFormat(" /Font <<{0}>> ", fonts); } if (images.Length > 0) { resourcesBuilder.AppendFormat(" /XObject <<{0}>> ", images); } var w = TextAdapter.FormatFloat(page.Width); var h = TextAdapter.FormatFloat(page.Height); writeBeginObject(page.ObjectId); writeBeginDictionary(); writeDictionaryEntry("/Type", "/Page"); writeDictionaryEntry("/UserUnit", TextAdapter.FormatFloat(page.UserUnit)); writeDictionaryEntry("/Parent", page.Parent.GetReference()); writeDictionaryEntry("/Resources", DICTIONARY_PDF_FORMAT.Args(resourcesBuilder)); writeDictionaryEntry("/MediaBox", BOX_PDF_FORMAT.Args(w, h)); writeDictionaryEntry("/CropBox", BOX_PDF_FORMAT.Args(w, h)); writeDictionaryEntry("/Rotate", 0); writeDictionaryEntry("/ProcSet", PROC_SET_STRING); if (elements.Length > 0) { writeDictionaryEntry("/Contents", ARRAY_PDF_FORMAT.Args(elements)); } writeEndDictionary(); writeEndObject(); }
/// <summary> /// Returns PDF string representation on the line primitive /// </summary> /// <returns></returns> public override string ToPdfString() { return(LINE_TO_FORMAT.Args(TextAdapter.FormatFloat(EndX), TextAdapter.FormatFloat(EndY))); }