public Example_37() { PDF pdf = new PDF(new BufferedStream( new FileStream("Example_37.pdf", FileMode.Create))); FileStream fis = new FileStream("data/testPDFs/wirth.pdf", FileMode.Open); // FileStream fis = new FileStream("data/testPDFs/Smalltalk-and-OO.pdf", FileMode.Open); // FileStream fis = new FileStream("data/testPDFs/InsideSmalltalk1.pdf", FileMode.Open); // FileStream fis = new FileStream("data/testPDFs/InsideSmalltalk2.pdf", FileMode.Open); // FileStream fis = new FileStream("data/testPDFs/Greenbook.pdf", FileMode.Open); // FileStream fis = new FileStream("data/testPDFs/Bluebook.pdf", FileMode.Open); // FileStream fis = new FileStream("data/testPDFs/Orangebook.pdf", FileMode.Open); List <PDFobj> objects = pdf.Read(fis); fis.Close(); Font f1 = new Font( objects, new FileStream("fonts/OpenSans/OpenSans-Regular.ttf.stream", FileMode.Open, FileAccess.Read), Font.STREAM); f1.SetSize(72f); TextLine line = new TextLine(f1, "This is a test!"); line.SetLocation(50f, 350f); line.SetColor(Color.peru); List <PDFobj> pages = pdf.GetPageObjects(objects); foreach (PDFobj pageObj in pages) { GraphicsState gs = new GraphicsState(); gs.SetAlphaStroking(0.75f); // Set alpha for stroking operations gs.SetAlphaNonStroking(0.75f); // Set alpha for nonstroking operations pageObj.SetGraphicsState(gs, objects); Page page = new Page(pdf, pageObj); page.AddResource(f1, objects); page.SetBrushColor(Color.blue); page.DrawString(f1, "Hello, World!", 50f, 200f); line.DrawOn(page); page.Complete(objects); // The graphics stack is unwinded automatically } pdf.AddObjects(objects); /* * List<Image> images = new List<Image>(); * foreach (PDFobj obj in objects.Values) { * if (obj.GetValue("/Subtype").Equals("/Image")) { * float w = float.Parse(obj.GetValue("/Width")); * float h = float.Parse(obj.GetValue("/Height")); * if (w > 500f && h > 500f) { * images.Add(new Image(pdf, obj)); * } * } * } * * Font f1 = new Font(pdf, CoreFont.HELVETICA); * f1.SetSize(72f); * * Page page = null; * foreach (Image image in images) { * page = new Page(pdf, A4.PORTRAIT); * * GraphicsState gs = new GraphicsState(); * gs.Set_CA(0.7f); // Stroking alpha * gs.Set_ca(0.7f); // Nonstroking alpha * page.SetGraphicsState(gs); * * image.ResizeToFit(page, true); * * // image.FlipUpsideDown(true); * // image.SetLocation(0f, -image.GetHeight()); * * // image.SetRotate(ClockWise._180_degrees); * // image.SetLocation(0f, 0f); * * image.DrawOn(page); * * TextLine text = new TextLine(f1, "Hello, World!"); * text.SetColor(Color.blue); * text.SetLocation(150f, 150f); * text.DrawOn(page); * * page.SetGraphicsState(new GraphicsState()); * } */ pdf.Complete(); }
public Example_31() { PDF pdf = new PDF(new BufferedStream( new FileStream("Example_31.pdf", FileMode.Create))); Page page = new Page(pdf, Letter.PORTRAIT); Font f1 = new Font(pdf, new FileStream("fonts/Noto/NotoSansDevanagari-Regular.ttf.stream", FileMode.Open, FileAccess.Read), Font.STREAM); f1.SetSize(15f); Font f2 = new Font(pdf, new FileStream("fonts/Droid/DroidSans.ttf.stream", FileMode.Open, FileAccess.Read), Font.STREAM); f2.SetSize(15f); StringBuilder buf = new StringBuilder(); StreamReader reader = new StreamReader( new FileStream("data/marathi.txt", FileMode.Open, FileAccess.Read)); String line = null; while ((line = reader.ReadLine()) != null) { buf.Append(line + "\n"); } reader.Close(); TextBox textBox = new TextBox(f1, buf.ToString(), 500f, 300f); textBox.SetFallbackFont(f2); textBox.SetLocation(50f, 50f); textBox.SetNoBorders(); textBox.DrawOn(page); String str = "असम के बाद UP में भी CM कैंडिडेट का ऐलान करेगी BJP?"; TextLine textLine = new TextLine(f1, str); textLine.SetFallbackFont(f2); textLine.SetLocation(50f, 175f); textLine.DrawOn(page); page.SetPenColor(Color.blue); page.SetBrushColor(Color.blue); page.FillRect(50f, 200f, 200f, 200f); GraphicsState gs = new GraphicsState(); gs.SetAlphaStroking(0.5f); // The stroking alpha constant gs.SetAlphaNonStroking(0.5f); // The nonstroking alpha constant page.SetGraphicsState(gs); page.SetPenColor(Color.green); page.SetBrushColor(Color.green); page.FillRect(100f, 250f, 200f, 200f); page.SetPenColor(Color.red); page.SetBrushColor(Color.red); page.FillRect(150, 300, 200f, 200f); // Reset the parameters to the default values page.SetGraphicsState(new GraphicsState()); page.SetPenColor(Color.orange); page.SetBrushColor(Color.orange); page.FillRect(200, 350, 200f, 200f); page.SetBrushColor(0x00003865); page.FillRect(50, 550, 200f, 200f); pdf.Complete(); }
public Example_16() { PDF pdf = new PDF(new BufferedStream( new FileStream("Example_16.pdf", FileMode.Create))); Font f1 = new Font(pdf, CoreFont.HELVETICA); f1.SetSize(14f); Page page = new Page(pdf, Letter.PORTRAIT); Dictionary <String, Int32> colors = new Dictionary <String, Int32>(); colors["Lorem"] = Color.blue; colors["ipsum"] = Color.red; colors["dolor"] = Color.green; colors["ullamcorper"] = Color.gray; f1.SetSize(72f); GraphicsState gs = new GraphicsState(); gs.SetAlphaStroking(0.5f); // Set alpha for stroking operations gs.SetAlphaNonStroking(0.5f); // Set alpha for nonstroking operations page.SetGraphicsState(gs); TextLine text = new TextLine(f1, "Hello, World"); text.SetLocation(50f, 300f); text.DrawOn(page); String latinText = File.ReadAllText("data/latin.txt"); f1.SetSize(14f); TextBox textBox = new TextBox(f1, latinText); textBox.SetLocation(50f, 50f); textBox.SetWidth(400f); // If no height is specified the height will be calculated based on the text. // textBox.SetHeight(400f); // textBox.SetVerticalAlignment(Align.TOP); // textBox.SetVerticalAlignment(Align.BOTTOM); // textBox.SetVerticalAlignment(Align.CENTER); textBox.SetBgColor(Color.whitesmoke); textBox.SetTextColors(colors); // Find x and y without actually drawing the text box. // float[] xy = textBox.DrawOn(page, false); float[] xy = textBox.DrawOn(page); page.SetGraphicsState(new GraphicsState()); // Reset GS Box box = new Box(); box.SetLocation(xy[0], xy[1]); box.SetSize(20f, 20f); box.DrawOn(page); pdf.Complete(); }