private static void CreateTextMarkupAnnotations(PDFFixedDocument document, PDFFont font) { PDFBrush blackBrush = new PDFBrush(); PDFPage page = document.Pages.Add(); page.Canvas.DrawString("Text markup annotations", font, blackBrush, 50, 50); PDFTextMarkupAnnotationType[] tmat = new PDFTextMarkupAnnotationType[] { PDFTextMarkupAnnotationType.Highlight, PDFTextMarkupAnnotationType.Squiggly, PDFTextMarkupAnnotationType.StrikeOut, PDFTextMarkupAnnotationType.Underline }; PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions(); sao.Brush = blackBrush; sao.Font = font; PDFStringLayoutOptions slo = new PDFStringLayoutOptions(); slo.HorizontalAlign = PDFStringHorizontalAlign.Center; slo.VerticalAlign = PDFStringVerticalAlign.Bottom; for (int i = 0; i < tmat.Length; i++) { PDFTextMarkupAnnotation tma = new PDFTextMarkupAnnotation(); page.Annotations.Add(tma); tma.DisplayRectangle = new PDFDisplayRectangle(50, 100 + 50 * i, 200, font.Size + 2); tma.TextMarkupType = tmat[i]; slo.X = 150; slo.Y = 100 + 50 * i + font.Size; page.Canvas.DrawString(tmat[i].ToString() + " annotation.", sao, slo); } }
private static void CreateLineAnnotations(PDFFixedDocument document, PDFFont font) { PDFBrush blackBrush = new PDFBrush(); PDFPage page = document.Pages.Add(); page.Canvas.DrawString("Line annotations", font, blackBrush, 50, 50); PDFLineEndSymbol[] les = new PDFLineEndSymbol[] { PDFLineEndSymbol.Circle, PDFLineEndSymbol.ClosedArrow, PDFLineEndSymbol.None, PDFLineEndSymbol.OpenArrow }; for (int i = 0; i < les.Length; i++) { PDFLineAnnotation la = new PDFLineAnnotation(); page.Annotations.Add(la); la.Author = "O2S.Components.PDF4NET"; la.Contents = "I am a line annotation with " + les[i].ToString() + " ending."; la.StartPoint = new PDFPoint(50, 100 + 40 * i); la.EndPoint = new PDFPoint(250, 100 + 40 * i); la.EndLineSymbol = les[i]; page.Canvas.DrawString("Line end symbol: " + les[i].ToString(), font, blackBrush, 270, 100 + 40 * i); } }
private static void CreateUriActions(PDFFixedDocument document, PDFFont font) { PDFPen blackPen = new PDFPen(new PDFRgbColor(0, 0, 0), 1); PDFBrush blackBrush = new PDFBrush(); font.Size = 12; PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions(); sao.Brush = blackBrush; sao.Font = font; PDFStringLayoutOptions slo = new PDFStringLayoutOptions(); slo.HorizontalAlign = PDFStringHorizontalAlign.Center; slo.VerticalAlign = PDFStringVerticalAlign.Middle; for (int i = 0; i < document.Pages.Count; i++) { document.Pages[i].Canvas.DrawString("Uri actions:", font, blackBrush, 400, 420); document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 440, 200, 20); slo.X = 500; slo.Y = 450; document.Pages[i].Canvas.DrawString("Go to o2sol.com", sao, slo); // Create a link annotation on top of the widget. PDFLinkAnnotation link = new PDFLinkAnnotation(); document.Pages[i].Annotations.Add(link); link.DisplayRectangle = new PDFDisplayRectangle(400, 440, 200, 20); // Create an uri action and attach it to the link. PDFUriAction uriAction = new PDFUriAction(); uriAction.URI = "http://www.o2sol.com"; link.Action = uriAction; } }
private void ApplyFont(Style onStyle, PDFFont font) { onStyle.SetValue(StyleKeys.FontFamilyKey, font.Selector); onStyle.SetValue(StyleKeys.FontSizeKey, font.Size); onStyle.SetValue(StyleKeys.FontBoldKey, (font.FontStyle & Drawing.FontStyle.Bold) > 0); onStyle.SetValue(StyleKeys.FontItalicKey, (font.FontStyle & Drawing.FontStyle.Italic) > 0); }
public void Font_CreateFontTest() { Scryber.Styles.FontStyle target = new Scryber.Styles.FontStyle(); PDFFont expected = new PDFFont(PDFStyleConst.DefaultFontFamily, PDFStyleConst.DefaultFontSize); PDFFont actual; actual = target.CreateFont(); Assert.AreEqual(expected, actual, "Default not the same"); target.FontFamily = (PDFFontSelector)"Symbol"; expected = new PDFFont(StandardFont.Symbol, PDFStyleConst.DefaultFontSize); actual = target.CreateFont(); Assert.AreEqual(expected, actual, "Symbol not the same"); target.FontSize = 40; expected = new PDFFont(StandardFont.Symbol, 40); actual = target.CreateFont(); Assert.AreEqual(expected, actual, "Symbol 40pt not the same"); target.FontFamily = (PDFFontSelector)"Bauhaus 92"; target.FontBold = true; target.FontItalic = true; target.FontSize = new PDFUnit(10, PageUnits.Millimeters); expected = new PDFFont("Bauhaus 92", new PDFUnit(10, PageUnits.Millimeters), Scryber.Drawing.FontStyle.Bold | Scryber.Drawing.FontStyle.Italic); actual = target.CreateFont(); Assert.AreEqual(expected, actual, "Bauhaus not the same"); }
public void GetFullName_Test1() { string family = "Sans-Serif"; bool bold = false; // TODO: Initialize to an appropriate value bool italic = false; // TODO: Initialize to an appropriate value string expected = family; string actual = PDFFont.GetFullName(family, bold, italic); Assert.AreEqual(expected, actual); bold = true; expected = "Sans-Serif,Bold"; actual = PDFFont.GetFullName(family, bold, italic); Assert.AreEqual(expected, actual); italic = true; expected = "Sans-Serif,Bold Italic"; actual = PDFFont.GetFullName(family, bold, italic); Assert.AreEqual(expected, actual); bold = false; expected = "Sans-Serif,Italic"; actual = PDFFont.GetFullName(family, bold, italic); Assert.AreEqual(expected, actual); }
public void GetHashCode_Test() { PDFFont one = new PDFFont("Sans-Serif", 12, FontStyle.Bold); PDFFont two = new PDFFont("Sans-Serif", 12, FontStyle.Bold); int expected = one.GetHashCode(); int actual = two.GetHashCode(); Assert.AreEqual(expected, actual); two = new PDFFont("Sans-Serif", 12, FontStyle.Italic); expected = one.GetHashCode(); actual = two.GetHashCode(); Assert.AreNotEqual(expected, actual); two = new PDFFont("Sans-Serif", 24, FontStyle.Bold); expected = one.GetHashCode(); actual = two.GetHashCode(); Assert.AreNotEqual(expected, actual); two = new PDFFont("Times", 12, FontStyle.Bold); expected = one.GetHashCode(); actual = two.GetHashCode(); Assert.AreNotEqual(expected, actual); }
private static void CreateInkAnnotations(PDFFixedDocument document, PDFFont font) { PDFBrush blackBrush = new PDFBrush(); Random rnd = new Random(); PDFPage page = document.Pages.Add(); page.Canvas.DrawString("Ink annotations", font, blackBrush, 50, 50); // The ink annotation will contain 3 lines, each one with 10 points. PDFPoint[][] points = new PDFPoint[3][]; for (int i = 0; i < points.Length; i++) { points[i] = new PDFPoint[10]; for (int j = 0; j < points[i].Length; j++) { points[i][j] = new PDFPoint(rnd.NextDouble() * page.Width, rnd.NextDouble() * page.Height); } } PDFInkAnnotation ia = new PDFInkAnnotation(); page.Annotations.Add(ia); ia.Contents = "I am an ink annotation."; ia.InkColor = new PDFRgbColor(255, 0, 255); ia.InkWidth = 5; ia.Points = points; }
protected override void DoDataBind(PDFDataContext context, bool includechildren) { base.DoDataBind(context, includechildren); var doc = context.Document; if (null != doc && null != this.Source && null != this.FontFamily) { PDFFontDefinition definition; if (this.TryGetFont(doc, context, out definition)) { string name = PDFFont.GetFullName(this.FontFamily.FamilyName, this.FontBold, this.FontItalic); //PDFFontResource resource = PDFFontResource.Load(definition, name); doc.EnsureResource(PDFFontResource.FontDefnResourceType, name, definition); } else { context.TraceLog.Add(TraceLevel.Warning, "CSS", "The font for " + this.Source.ToString() + " with name " + this.FontFamily + " could not be loaded"); } } else { context.TraceLog.Add(TraceLevel.Warning, "CSS", "No font-family or src was specified for the @font-face rule."); } }
public void Equals_Test2() { PDFFont one = new PDFFont("Sans-Serif", 12, FontStyle.Bold); PDFFont two = new PDFFont("Sans-Serif", 12, FontStyle.Bold); bool actual = one.Equals(two); Assert.IsTrue(actual); actual = two.Equals(one); Assert.IsTrue(actual); //Change font family two = new PDFFont("Times", 12, FontStyle.Bold); actual = one.Equals(two); Assert.IsFalse(actual); //Change size two = new PDFFont("Sans-Serif", 24, FontStyle.Bold); actual = one.Equals(two); Assert.IsFalse(actual); //Change style two = new PDFFont("Sans-Serif", 12, FontStyle.Bold | FontStyle.Italic); actual = one.Equals(two); Assert.IsFalse(actual); }
private static void CreateJavaScriptActions(PDFFixedDocument document, PDFFont font) { PDFPen blackPen = new PDFPen(new PDFRgbColor(0, 0, 0), 1); PDFBrush blackBrush = new PDFBrush(); font.Size = 12; PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions(); sao.Brush = blackBrush; sao.Font = font; PDFStringLayoutOptions slo = new PDFStringLayoutOptions(); slo.HorizontalAlign = PDFStringHorizontalAlign.Center; slo.VerticalAlign = PDFStringVerticalAlign.Middle; for (int i = 0; i < document.Pages.Count; i++) { document.Pages[i].Canvas.DrawString("JavaScript actions:", font, blackBrush, 400, 480); document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 500, 200, 20); slo.X = 500; slo.Y = 510; document.Pages[i].Canvas.DrawString("Click me", sao, slo); // Create a link annotation on top of the widget. PDFLinkAnnotation link = new PDFLinkAnnotation(); document.Pages[i].Annotations.Add(link); link.DisplayRectangle = new PDFDisplayRectangle(400, 500, 200, 20); // Create a Javascript action and attach it to the link. PDFJavaScriptAction jsAction = new PDFJavaScriptAction(); jsAction.Script = "app.alert({cMsg: \"JavaScript action: you are now on page " + (i + 1) + "\", cTitle: \"O2S.Components.PDF4NET Actions Sample\"});"; link.Action = jsAction; } }
private static string GetPDFFontEncodingName(PDFFont font) { if (string.IsNullOrEmpty(font.Encoding)) { return("Custom"); } if (string.Compare(PDFFont.EncodingWinAnsiEncoding, font.Encoding, true) == 0) { return("Ansi"); } if (string.Compare(PDFFont.EncodingStandardEncoding, font.Encoding, true) == 0) { return("Standard"); } if (string.Compare(PDFFont.EncodingPDFDocEncoding, font.Encoding, true) == 0) { return("PDF"); } if (string.Compare(PDFFont.EncodingMacExpertEncoding, font.Encoding, true) == 0) { return("MAC Expert"); } if (string.Compare(PDFFont.EncodingMacRomanEncoding, font.Encoding, true) == 0) { return("MAC Roman"); } return(font.Encoding); }
private static void CreateLaunchActions(PDFFixedDocument document, PDFFont font) { PDFPen blackPen = new PDFPen(new PDFRgbColor(0, 0, 0), 1); PDFBrush blackBrush = new PDFBrush(); font.Size = 12; PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions(); sao.Brush = blackBrush; sao.Font = font; PDFStringLayoutOptions slo = new PDFStringLayoutOptions(); slo.HorizontalAlign = PDFStringHorizontalAlign.Center; slo.VerticalAlign = PDFStringVerticalAlign.Middle; for (int i = 0; i < document.Pages.Count; i++) { document.Pages[i].Canvas.DrawString("Launch actions:", font, blackBrush, 400, 360); document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 380, 200, 20); slo.X = 500; slo.Y = 390; document.Pages[i].Canvas.DrawString("Launch samples explorer", sao, slo); // Create a link annotation on top of the widget. PDFLinkAnnotation link = new PDFLinkAnnotation(); document.Pages[i].Annotations.Add(link); link.DisplayRectangle = new PDFDisplayRectangle(400, 380, 200, 20); // Create a launch action and attach it to the link. PDFLaunchAction launchAction = new PDFLaunchAction(); launchAction.FileName = "O2S.Components.PDF4NET.SamplesExplorer.Win.exe"; link.Action = launchAction; } }
PDFPage CreateNewPage(PDFFont font, string serialNumber) { var headerPen = new PDFPen(Color.DarkSlateBlue, 120); var serialfont = new PDFFont(FontType.Helvetica, 16, PDF.Drawing.FontStyle.Regular); var companyNameFont = new PDFFont(FontType.Helvetica, 30, PDF.Drawing.FontStyle.Bold); pageNumber++; PDFPage page = pdfDocument.AddPage(); page.Height = 1000; page.Width = 700; page.DrawLine(headerPen, 0, 0, 700, 0); page.DrawString(LabelConstant.Title, serialfont, Color.White, 10, 50); page.DrawString(LabelConstant.SerialNumber + serialNumber, serialfont, Color.White, 550, 50); page.DrawString(LabelConstant.CompanyName, companyNameFont, Color.White, 230, 40); page.DrawString(LabelConstant.TradeMark, font, Color.White, 450, 20); page.DrawString(LabelConstant.Page + pageNumber, font, Color.Black, 600, 980); page.DrawString(LabelConstant.Website, font, Color.Black, PDFcoordinates.siteX, PDFcoordinates.siteY); page.DrawString(DateTime.UtcNow.ToString("dd/MM/yyy HH:mm:sss UTC"), font, Color.White, PDFcoordinates.dateX, PDFcoordinates.dateY); page.DrawString("0.1.9.1", font, Color.Black, PDFcoordinates.versionX, PDFcoordinates.versionY); return(page); }
private static string GetPDFFontTypeName(PDFFont font) { if (string.IsNullOrEmpty(font.FontType)) { return(string.Empty); } if (string.Compare(PDFFont.TypeType0, font.FontType, true) == 0) { if (string.Compare(PDFFont.TypeCIDFontType2, font.DescendantCID, true) == 0) { return("TrueType (CID) "); } else { return("Type 2 (CID) "); } } if (string.Compare(PDFFont.TypeType1, font.FontType, true) == 0) { return("Type 1"); } if (string.Compare(PDFFont.TypeType3, font.FontType, true) == 0) { return("Type 3"); } return(font.FontType); }
private static void DrawPharmaBarcodes(PDFPage page, PDFFont titleFont, PDFFont barcodeFont) { PDFBrush brush = new PDFBrush(); PDFPen lightGrayPen = new PDFPen(PDFRgbColor.LightGray, 0.5); page.Canvas.DrawString("Pharma barcodes (barcodes used in the pharmaceutical industry)", titleFont, brush, 40, 20); for (int i = 0; i < 2; i++) { page.Canvas.DrawLine(lightGrayPen, 40, 50 + 100 * i, 570, 50 + 100 * i); } page.Canvas.DrawLine(lightGrayPen, 306, 50, 306, 250); string[] barcodes = new string[] { "Code 32", "Pharmacode", "PZN (Pharma-Zentral-Nummer)" }; PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions(); sao.Brush = brush; sao.Font = barcodeFont; PDFStringLayoutOptions slo = new PDFStringLayoutOptions(); slo.HorizontalAlign = PDFStringHorizontalAlign.Center; slo.VerticalAlign = PDFStringVerticalAlign.Top; slo.X = 173; int sign = 1; for (int i = 0; i < barcodes.Length; i++) { slo.Y = 55 + 100 * (i / 2); page.Canvas.DrawString(barcodes[i], sao, slo); slo.X = slo.X + sign * 266; sign = -sign; } // Code 32 PDFCode32Barcode code32Barcode = new PDFCode32Barcode(); code32Barcode.Data = "54925174"; code32Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom; page.Canvas.DrawBarcode(code32Barcode, 173 - code32Barcode.Width / 2, 70); // Pharmacode PDFPharmacodeBarcode pharmacodeBarcode = new PDFPharmacodeBarcode(); pharmacodeBarcode.Data = "128128"; pharmacodeBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom; page.Canvas.DrawBarcode(pharmacodeBarcode, 173 + 266 - pharmacodeBarcode.Width / 2, 70); // PZN PDFPznBarcode pznBarcode = new PDFPznBarcode(); pznBarcode.Data = "903271"; pznBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom; page.Canvas.DrawBarcode(pznBarcode, 173 - pznBarcode.Width / 2, 170); page.Canvas.CompressAndClose(); }
public void GetDrawingStyle_Test1() { FontStyle fontStyle = FontStyle.Bold; System.Drawing.FontStyle expected = System.Drawing.FontStyle.Bold; System.Drawing.FontStyle actual; actual = PDFFont.GetDrawingStyle(fontStyle); Assert.AreEqual(expected, actual); }
/// <summary> /// Returns true if this font resource refers to the same underlying font as the provided PDFFont /// </summary> /// <param name="font"></param> /// <returns></returns> public bool Equals(PDFFont font) { if (null == font) { throw new ArgumentNullException("font"); } return(this.Definition.FullName == font.FullName); }
private static void DrawBezierCurves(PDFPage page, PDFFont titleFont, PDFFont sectionFont) { PDFBrush brush = new PDFBrush(); PDFPen blackPen = new PDFPen(PDFRgbColor.Black, 1); PDFPen redPen = new PDFPen(PDFRgbColor.Red, 1); PDFBrush blueBrush = new PDFBrush(PDFRgbColor.DarkBlue); PDFRgbColor randomPenColor = new PDFRgbColor(); PDFPen randomPen = new PDFPen(randomPenColor, 1); page.Canvas.DrawString("Bezier curves", titleFont, brush, 20, 50); page.Canvas.DrawLine(blackPen, 20, 210, 600, 210); page.Canvas.DrawLine(blackPen, 306, 70, 306, 350); page.Canvas.DrawRectangle(blueBrush, 39, 339, 2, 2); page.Canvas.DrawRectangle(blueBrush, 279, 79, 2, 2); page.Canvas.DrawRectangle(blueBrush, 499, 299, 2, 2); page.Canvas.DrawRectangle(blueBrush, 589, 69, 2, 2); page.Canvas.DrawBezier(redPen, 40, 340, 280, 80, 500, 300, 590, 70); page.Canvas.DrawString("Random bezier curves clipped to view", sectionFont, brush, 20, 385); PDFPath rectPath = new PDFPath(); rectPath.AddRectangle(20, 400, 570, 300); page.Canvas.SaveGraphicsState(); page.Canvas.SetClip(rectPath); Random rnd = new Random(); for (int i = 0; i < 100; i++) { randomPenColor.R = (byte)rnd.Next(256); randomPenColor.G = (byte)rnd.Next(256); randomPenColor.B = (byte)rnd.Next(256); double x1 = rnd.NextDouble() * page.Width; double y1 = 380 + rnd.NextDouble() * 350; double x2 = rnd.NextDouble() * page.Width; double y2 = 380 + rnd.NextDouble() * 350; double x3 = rnd.NextDouble() * page.Width; double y3 = 380 + rnd.NextDouble() * 350; double x4 = rnd.NextDouble() * page.Width; double y4 = 380 + rnd.NextDouble() * 350; page.Canvas.DrawBezier(randomPen, x1, y1, x2, y2, x3, y3, x4, y4); } page.Canvas.RestoreGraphicsState(); blackPen.DashPattern = null; page.Canvas.DrawPath(blackPen, rectPath); page.Canvas.CompressAndClose(); }
internal string GetFont(PDFResources resources, System.Windows.Media.GlyphTypeface typeFace) { string familyName = typeFace.FamilyNames.Values.FirstOrDefault(); string key = null; if (!fonts.TryGetValue(typeFace, out key)) { key = "R" + resources.ID + "F" + fonts.Count; PDFFont pf = PDFDocument.CreateObject <PDFFont>(); pf.BaseFont = familyName; pf.Subtype = "Type1"; pf.Encoding = "MacRomanEncoding"; resources.Font[key] = pf; var pd = PDFDocument.CreateObject <PDFFontDescriptor>(); pf.FontDescriptor = pd; pd.FontName = familyName; pd.FontFamily = familyName; pd.FontWeight = typeFace.Weight.ToOpenTypeWeight(); pd.XHeight = typeFace.XHeight; pd.CapHeight = typeFace.CapsHeight; pd.StemV = typeFace.StrikethroughThickness; pd.Flags = PDFFontFlags.None; if (typeFace.Weight == FontWeights.Bold) { pd.Flags |= PDFFontFlags.ForceBold; } if (typeFace.Symbol) { pd.Flags |= PDFFontFlags.Symbolic; } else { pd.Flags |= PDFFontFlags.Nonsymbolic; } pd.Ascent = typeFace.AdvanceHeights.Select(x => x.Value).Max() - typeFace.Baseline; pd.Descent = -(typeFace.DistancesFromHorizontalBaselineToBlackBoxBottom.Select(x => x.Value).Max()); pd.FontBBox = new PDFRect(); pd.FontBBox.Width = (int)typeFace.AdvanceWidths.Select(x => x.Value).Sum(); pd.FontBBox.Height = (int)typeFace.AdvanceHeights.Select(x => x.Value).Sum(); fonts[typeFace] = key; } return(key); }
public void SetFont(PDFFont font, float fontSize) { try { this.pageContentStream.setFont(font.PDFBoxFont, fontSize); } catch (java.io.IOException oException) { throw new System.IO.IOException(oException.getMessage()); } }
private static void DrawCmykTiff(PDFPage page, Stream cmykImageStream, PDFFont titleFont) { PDFBrush brush = new PDFBrush(); page.Canvas.DrawString("CMYK TIFF", titleFont, brush, 20, 50); PDFTiffImage cmykTiff = new PDFTiffImage(cmykImageStream); page.Canvas.DrawImage(cmykTiff, 20, 90, 570, 0); page.Canvas.CompressAndClose(); }
public void FamilyName_Test() { string family = "Sans-Serif"; PDFUnit size = 12; PDFFont target = new PDFFont(family, size); Assert.AreEqual(family, target.FamilyName); family = "Times"; target.FamilyName = family; Assert.AreEqual(family, target.FamilyName); }
public void PDFFontConstructor_Test1() { StandardFont font = StandardFont.Helvetica; PDFUnit size = 12; PDFFont target = new PDFFont(font, size); Assert.IsNotNull(target); Assert.AreEqual(target.FamilyName, font.ToString()); Assert.AreEqual(target.Size, size); Assert.AreEqual(target.IsStandard, true); Assert.AreEqual(target.FontStyle, FontStyle.Regular); }
public void PDFFontConstructor_Test() { string family = "Sans-Serif"; PDFUnit size = 12; PDFFont target = new PDFFont(family, size); Assert.IsNotNull(target); Assert.AreEqual(target.FamilyName, family); Assert.AreEqual(target.Size, size); Assert.AreEqual(target.IsStandard, true); Assert.AreEqual(target.FontStyle, FontStyle.Regular); }
public void PDFFontConstructor_Test5() { StandardFont font = StandardFont.Helvetica; PDFUnit size = 20; FontStyle style = FontStyle.Bold | FontStyle.Italic; PDFFont target = new PDFFont(font, size, style); Assert.IsNotNull(target); Assert.AreEqual(target.FamilyName, font.ToString()); Assert.AreEqual(target.Size, size); Assert.AreEqual(target.IsStandard, true); Assert.AreEqual(target.FontStyle, style); }
private static void DrawFormXObjects(PDFPage page, PDFFont titleFont, PDFFont sectionFont) { PDFBrush brush = new PDFBrush(); PDFPen blackPen = new PDFPen(PDFRgbColor.Black, 1); PDFRgbColor randomPenColor = new PDFRgbColor(); PDFPen randomPen = new PDFPen(randomPenColor, 1); PDFRgbColor randomBrushColor = new PDFRgbColor(); PDFBrush randomBrush = new PDFBrush(randomBrushColor); page.Canvas.DrawString("Form XObjects", titleFont, brush, 20, 50); page.Canvas.DrawString("Scaling", sectionFont, brush, 20, 70); // Create the XObject content - random rectangles PDFFormXObject xobject = new PDFFormXObject(300, 300); Random rnd = new Random(); for (int i = 0; i < 100; i++) { randomPenColor.R = (byte)rnd.Next(256); randomPenColor.G = (byte)rnd.Next(256); randomPenColor.B = (byte)rnd.Next(256); randomBrushColor.R = (byte)rnd.Next(256); randomBrushColor.G = (byte)rnd.Next(256); randomBrushColor.B = (byte)rnd.Next(256); double left = rnd.NextDouble() * xobject.Width; double top = rnd.NextDouble() * xobject.Height; double width = rnd.NextDouble() * xobject.Width; double height = rnd.NextDouble() * xobject.Height; double orientation = rnd.Next(360); xobject.Canvas.DrawRectangle(randomPen, randomBrush, left, top, width, height, orientation); } xobject.Canvas.DrawRectangle(blackPen, 0, 0, xobject.Width, xobject.Height); xobject.Canvas.CompressAndClose(); // Draw the form XObject 3 times on the page at different sizes. page.Canvas.DrawFormXObject(xobject, 3, 90, 100, 100); page.Canvas.DrawFormXObject(xobject, 106, 90, 200, 200); page.Canvas.DrawFormXObject(xobject, 309, 90, 300, 300); page.Canvas.DrawString("Flipping", sectionFont, brush, 20, 420); page.Canvas.DrawFormXObject(xobject, 20, 440, 150, 150); page.Canvas.DrawFormXObject(xobject, 200, 440, 150, 150, 0, PDFFlipDirection.VerticalFlip); page.Canvas.DrawFormXObject(xobject, 20, 620, 150, 150, 0, PDFFlipDirection.HorizontalFlip); page.Canvas.DrawFormXObject(xobject, 200, 620, 150, 150, 0, PDFFlipDirection.VerticalFlip | PDFFlipDirection.HorizontalFlip); page.Canvas.CompressAndClose(); }
public void GetDrawingStyle_Test() { string family = "Sans-Serif"; PDFUnit size = 12; PDFFont target = new PDFFont(family, size); System.Drawing.FontStyle actual; actual = target.GetDrawingStyle(); Assert.AreEqual(System.Drawing.FontStyle.Regular, actual); target.FontStyle = FontStyle.Italic | FontStyle.Bold; actual = target.GetDrawingStyle(); Assert.AreEqual(System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic, actual); }
public void PDFFontConstructor_Test6() { string family = "Sans-Serif"; PDFUnit size = 12; FontStyle style = FontStyle.Bold; PDFFont basefont = new PDFFont(family, size, style); style = FontStyle.Italic; PDFFont target = new PDFFont(basefont, style); Assert.IsNotNull(target); Assert.AreEqual(target.FamilyName, basefont.FamilyName); Assert.AreEqual(target.Size, basefont.Size); Assert.AreEqual(target.IsStandard, basefont.IsStandard); Assert.AreEqual(target.FontStyle, style); }
public void FullName_Test() { string family = "Sans-Serif"; PDFUnit size = 12; FontStyle style = FontStyle.Bold | FontStyle.Regular; //Just bold PDFFont target = new PDFFont(family, size, style); string expected = "Sans-Serif,Bold"; string actual = target.FullName; Assert.AreEqual(expected, actual); target = new PDFFont(target, FontStyle.Regular); expected = "Sans-Serif"; actual = target.FullName; Assert.AreEqual(expected, actual); }