private void button3_Click(object sender, System.EventArgs e) { // step 1: create the C1PdfDocument object C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument(); // step 2: add content to the page Font font = new Font("Arial", 12); RectangleF rc = pdf.PageRectangle; rc.Inflate(-72, -72); pdf.DrawStringRtf(@"To {\b boldly} go where {\i no one} has gone before!", font, Brushes.Black, rc); // step 3: save the document to a file string fileName = tempdir + "hello world.pdf"; pdf.Save(fileName); System.Diagnostics.Process.Start(fileName); }
private void button6_Click(object sender, System.EventArgs e) { // get rtf template string rtfHdr = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033" + @"{\fonttbl{\f0\fswiss\fcharset0 Arial;}{\f1\froman\fprq2\fcharset0 Book Antiqua;}}" + @"{\colortbl ;\red0\green0\blue0;}\viewkind4\uc1\pard\f0\fs20\par" + @"\pard\tx1440\tx2880\tx4320\tx5760\cf1\b\f1\fs24 Directory Report created on <<TODAY>>\par" + @"\ul\par Name\tab Extension\tab Size\tab Date\tab Attributes\par"; string rtfEntry = @"\cf0\ulnone\b0\f0\fs16 <<NAME>>\tab <<EXT>>\tab <<SIZE>>\tab <<DATE>>\tab <<ATTS>>\par"; // build rtf string StringBuilder sb = new StringBuilder(); sb.Append(rtfHdr.Replace("<<TODAY>>", DateTime.Today.ToShortDateString())); foreach (string file in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "*.bmp")) { string s = rtfEntry; FileInfo fi = new FileInfo(file); s = s.Replace("<<NAME>>", Path.GetFileNameWithoutExtension(file)); s = s.Replace("<<EXT>>", fi.Extension); s = s.Replace("<<SIZE>>", string.Format("{0:#,##0}", fi.Length)); s = s.Replace("<<DATE>>", fi.LastWriteTime.ToShortDateString()); s = s.Replace("<<ATTS>>", fi.Attributes.ToString()); sb.Append(s); } sb.Append("}"); // render it C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument(); RectangleF rc = pdf.PageRectangle; rc.Inflate(-72, -72); pdf.DrawStringRtf(sb.ToString(), Font, Brushes.Black, rc); // save and show string fileName = tempdir + "dir.pdf"; pdf.Save(fileName); System.Diagnostics.Process.Start(fileName); }
private void button19_Click(object sender, System.EventArgs e) { C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument(); // set up to draw Font font = new Font("Tahoma", 14); RectangleF rc = new RectangleF(100, 100, 300, 28); // measure RTF text and adjust the rectangle to fit string text = @"Short {\b RTF} snippet with some {\b bold} and some {\i italics} in it."; rc.Y = rc.Bottom + 12; rc.Height = pdf.MeasureStringRtf(text, font, rc.Width).Height; // render RTF snippet pdf.DrawStringRtf(text, font, Brushes.Blue, rc); pdf.DrawRectangle(Pens.Black, rc); // save the document to a file string fileName = tempdir + "rtf.pdf"; pdf.Save(fileName); System.Diagnostics.Process.Start(fileName); }