public virtual void Test() { Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); LicenseKey.LoadLicenseFile(Environment.GetEnvironmentVariable("ITEXT7_LICENSEKEY") + "/all-products.xml"); // By default target dir is created during runSamples method. In this particular case we need this // action before due to overriding system out stream new FileInfo(GetDest()).Directory.Create(); TextWriter storedSystemOut = Console.Out; try { using (stream = File.Open((GetDest().Replace(".pdf", "_sout.txt")), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8)) { Console.SetOut(writer); RunSamples(); } } finally { Console.SetOut(storedSystemOut); LicenseKey.UnloadLicenses(); } }
private void button2_Click(object sender, EventArgs e) { if (txtTempPath.Text.Equals("") || txtPDFPath.Text.Equals("") || txtTrial.Text.Equals("")) { string msg = ""; msg = msg + (txtTempPath.Text.Equals("")?"Data Template":"") + "\n"; msg = msg + (txtPDFPath.Text.Equals("") ? "PDF File" : "") + "\n"; msg = msg + (txtTrial.Text.Equals("") ? "Itext Key License" : "") + "\n"; MessageBox.Show("No Selected \n" + msg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // LicenseKey.LoadLicenseFile(@"C:\Users\Arn-Windows\Documents\Visual Studio 2015\Projects\itextkey1590057483769_0.xml"); LicenseKey.LoadLicenseFile(txtTrial.Text); Template template = Pdf2DataExtractor.ParseTemplateFromPDF(txtTempPath.Text); Pdf2DataExtractor extractor = new Pdf2DataExtractor(template); ParsingResult result = extractor.Recognize(txtPDFPath.Text); lblLastName.Text = result.GetResults("LastName").FirstOrDefault().ToString(); lblApplicationNo.Text = result.GetResults("AppliccationNo").FirstOrDefault().ToString(); lblFirstName.Text = result.GetResults("FirstName").FirstOrDefault().ToString(); // lblAddress.Text= result.GetResults("Address").FirstOrDefault().ToString(); foreach (ResultElement item in result.GetResults("Address")) { lblAddress.Text = lblAddress.Text + item.ToString() + "\n"; } //MessageBox.Show("Application NO.= "+ result.GetResults("AppliccationNo").FirstOrDefault()); MessageBox.Show("Data has been Loaded!", "Sucess"); }
public static void Main(String[] args) { FileInfo file = new FileInfo(DEST); file.Directory.Create(); LicenseKey.LoadLicenseFile(new FileStream(KEY, FileMode.Open, FileAccess.Read)); new C01E06_Czech_Russian_Korean_Unicode().CreatePdf(DEST); }
/* Loads the itext license, but the license is expired */ private void LoadItextLicense() { try { LicenseKey.LoadLicenseFile(Program.iTextLicensePath); } catch (LicenseKeyException e) { Debug.WriteLine(e); } }
public virtual void Test() { FontCache.ClearSavedFonts(); FontProgramFactory.ClearRegisteredFonts(); LicenseKey.LoadLicenseFile(Environment.GetEnvironmentVariable("ITEXT7_LICENSEKEY") + "/all-products.xml"); RunSamples(); ResetLicense(); }
/// <summary> /// The main method of this example. /// </summary> /// <param name="args">no arguments are needed to run this example.</param> public static void Main(String[] args) { LicenseKey.LoadLicenseFile(Environment.GetEnvironmentVariable("ITEXT7_LICENSEKEY") + "/itextkey-html2pdf_typography.xml"); FileInfo file = new FileInfo(DEST); file.Directory.Create(); new C07E02_CombineHtml2().CreatePdf(BASEURI, SRC, DEST); }
/// <summary> /// The main method of this example. /// </summary> /// <param name="args">no arguments are needed to run this example.</param> public static void Main(String[] args) { LicenseKey.LoadLicenseFile(Environment.GetEnvironmentVariable("ITEXT7_LICENSEKEY") + "/itextkey-html2pdf_typography.xml"); FileInfo file = new FileInfo(DEST); file.Directory.Create(); new C01E01_HelloWorld().CreatePdf(HTML, DEST); }
/// <summary> /// The main method of this example. /// </summary> /// <param name="args">no arguments are needed to run this example.</param> public static void Main(String[] args) { LicenseKey.LoadLicenseFile(Environment.GetEnvironmentVariable("ITEXT7_LICENSEKEY") + "/itextkey-html2pdf_typography.xml"); FileInfo file = new FileInfo(DEST); file.Directory.Create(); new C07E06_CreateFromURL3().CreatePdf(new Uri(ADDRESS), DEST); }
/// <summary> /// The main method of this example. /// </summary> /// <param name="args">no arguments are needed to run this example.</param> public static void Main(String[] args) { LicenseKey.LoadLicenseFile(Environment.GetEnvironmentVariable("ITEXT7_LICENSEKEY") + "/itextkey-html2pdf_typography.xml"); FileInfo file = new FileInfo(DEST); file.Directory.Create(); new C02E05_PositionImages().CreatePdf(SRC, DEST); }
public static void Main(String[] args) { // Load the license file to use typography features LicenseKey.LoadLicenseFile(Environment.GetEnvironmentVariable("ITEXT7_LICENSEKEY") + "/itextkey-typography.xml"); FileInfo file = new FileInfo(DEST); file.Directory.Create(); new MalayalamCircleAnnotation().CreatePDF(DEST); }
/// <summary> /// The main method of this example. /// </summary> /// <param name="args">no arguments are needed to run this example.</param> public static void Main(String[] args) { LicenseKey.LoadLicenseFile(Environment.GetEnvironmentVariable("ITEXT7_LICENSEKEY") + "/itextkey-html2pdf_typography.xml"); FileInfo file = new FileInfo(DEST); file.Directory.Create(); C07E08_Metadata app = new C07E08_Metadata(); app.CreatePdf(SRC, DEST); }
public static void Main(String[] args) { // Load the license file to use XFA features LicenseKey.LoadLicenseFile(Environment.GetEnvironmentVariable("ITEXT7_LICENSEKEY") + "/all-products.xml"); FileInfo file = new FileInfo(DEST); file.Directory.Create(); new XFARemove().ManipulatePdf(); }
/// <summary> /// The main method of this example. /// </summary> /// <param name="args">no arguments are needed to run this example.</param> public static void Main(String[] args) { LicenseKey.LoadLicenseFile(Environment.GetEnvironmentVariable("ITEXT7_LICENSEKEY") + "/itextkey-html2pdf_typography.xml"); FileInfo file = new FileInfo(DEST); file.Directory.Create(); C04E08_MovieInvoice3 app = new C04E08_MovieInvoice3(); app.CreatePdf(app.GetBytes(XML), app.CreateHtml(XML, XSL), BASEURI, DEST, INTENT); }
public virtual void CreatePdf(String dest) { LicenseKey.LoadLicenseFile(new FileStream(KEY, FileMode.Open, FileAccess.Read)); //Initialize PDF document PdfDocument pdf = new PdfDocument(new PdfWriter(dest)); // Initialize document Document document = new Document(pdf); document.ShowTextAligned("The Strange Case of Dr. Jekyll and Mr. Hyde", 36, 806, TextAlignment.LEFT); document.ShowTextAlignedKerned("The Strange Case of Dr. Jekyll and Mr. Hyde", 36, 790, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0); document.ShowTextAligned("AWAY AGAIN", 36, 774, TextAlignment.LEFT); document.ShowTextAlignedKerned("AWAY AGAIN", 36, 758, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0); document.Close(); }
/// <summary> /// The main method of this example. /// </summary> /// <param name="args">no arguments are needed to run this example.</param> public static void Main(String[] args) { LicenseKey.LoadLicenseFile(Environment.GetEnvironmentVariable("ITEXT7_LICENSEKEY") + "/itextkey-html2pdf_typography.xml"); FileInfo file = new FileInfo(DEST); file.Directory.Create(); C05E03_Invitations app = new C05E03_Invitations(); String[] names = { "Bruno Lowagie", "Ingeborg Willaert", "John Doe" }; int counter = 1; foreach (String name in names) { app.CreatePdf(name, SRC, String.Format(DEST, counter++)); } }
private void button4_Click(object sender, EventArgs e) { LicenseKey.LoadLicenseFile("itextkey1528179689217_0.xml"); int count1 = 0; string DEST = $@"AtyatiBaby.pdf"; using (MySqlConnection conn1 = new MySqlConnection("datasource=127.0.0.1;port=3306;username=root;password=;database=hindi_1;")) { conn1.Open(); MySqlCommand command = new MySqlCommand("SELECT COUNT(amount) FROM data", conn1); using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { //label1.Text = reader[0].ToString(); count1 = Convert.ToInt32(reader[0]); } } } int beta = 0; int gamma = 0; for (int k = 0; k < count1; k++) { gamma = gamma + 1; beta = beta + 1; string line1, line; StreamReader file = new StreamReader("test.txt"); line1 = file.ReadLine(); string[] words1 = line1.Split(' '); // int aa = (Int32.Parse(words1[2])); // int ab = (Int32.Parse(words1[3])); // int ac = (Int32.Parse(words1[4])); //int ad = (Int32.Parse(words1[5])); PdfDocument pdf = new PdfDocument(new PdfWriter("AtyatiBaby" + gamma + ".pdf")); Document document = new Document(pdf); StreamReader file1 = new StreamReader("test.txt"); int count = 0; while ((line = file1.ReadLine()) != null) { count = count + 1; } file1.Close(); string[] Commands = new string[count]; StreamReader file2 = new StreamReader("test.txt"); for (int i = 0; i < count; i++) { Commands[i] = file2.ReadLine(); } file2.Close(); string[] words; int alpha = 0; string temp; while (alpha != count) { temp = Commands[alpha]; words = temp.Split(); if (words[0].Equals("insert_image")) { iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance("yesbank.jpg"); png.ScalePercent(float.Parse(words[1])); float a = (float.Parse(words[2])); float b = (float.Parse(words[3])); float c = (float.Parse(words[4])); float d = (float.Parse(words[5])); // png.SetAbsolutePosition(doc.PageSize.Width - a - b, doc.PageSize.Height - c - d); //doc.Add(png); // Document to add layout elements: paragraphs, images etc // Load image from disk ImageData imageData = ImageDataFactory.Create("yesbank.jpeg"); // Create layout image object and provide parameters. Page number = 1 Image image = new Image(imageData).ScaleAbsolute(100, 200).SetFixedPosition(1, 25, 25); document.Add(image); } /*if (words[0].Equals("insert_bank_officials_signature")) * { * * iTextSharp.text.Image png1 = iTextSharp.text.Image.GetInstance("signature.jpg"); * png1.ScalePercent(float.Parse(words[1])); * float a = (float.Parse(words[2])); * float b = (float.Parse(words[3])); * float c = (float.Parse(words[4])); * float d = (float.Parse(words[5])); * //png1.SetAbsolutePosition(doc.PageSize.Width - a - b, doc.PageSize.Height - c - d); * // doc.Add(png1); * * }*/ if (words[0].Equals("para_write")) { //words[0] = ""; /* string align = words[1]; * words[1] = "\0"; * words[words.Length - 1] = "\0"; * string type = "\0"; * int al = 2, o = 1; * string c = "";*/ //label1.Text = words[3]; words[0] = "\0"; // 0 string align = words[1]; words[1] = "\0"; // 1 words[words.Length - 1] = "\0"; // last " string type = "\0"; int font = (Int32.Parse(words[3])); words[3] = "\0"; // 3 //iTextSharp.text.Font pfont1 = FontFactory.GetFont(iTextSharp.text.Font.FontFamily.TIMES_ROMAN.ToString(), 15, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); // iTextSharp.text.Font pfont11; string color = words[4]; words[4] = "\0"; // 4 words[5] = "\0"; //string path = System.Web.HttpContext.Current.Server.MapPath("C:/Users/Ganesh.P.Nischay/source/repos/WindowsFormsApp2/WindowsFormsApp2/bin/Debug/ARIALUNI.TTF"); //iTextSharp.text.Font fnt = new iTextSharp.text.Font(); //FontFactory.Register(@"C:/Users/Ganesh.P.Nischay/source/repos/WindowsFormsApp2/WindowsFormsApp2/bin/Debug/ARIALUNI.TTF", "CustomAriel"); // fnt = FontFactory.GetFont("CustomAriel", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); string[] arr = { "amount", "balance", "purpose", "date" }; int w = 0; for (int i = 0; i < words.Length; i++) { if (words[i].Equals("_")) { // Excel excel = new Excel(@"C:\Users\Ganesh.P.Nischay\source\repos\WindowsFormsApp2\WindowsFormsApp2\sample3.xlsx", 1); //words[i] = excel.ReadCell(l, o); // string abc1 = excel.ReadCell(al, o); // words[i] = abc1; // excel.close(); // o = o + 1; using (MySqlConnection conn = new MySqlConnection("datasource=127.0.0.1;port=3306;username=root;password=;database=hindi_1;")) { // DO REMEMBER TO OPEN THE CONNECTION!!! conn.Open(); // Connection Established MySqlCommand command = new MySqlCommand("SELECT" + " " + "purpose" + " " + "FROM data " + "WHERE " + "id=" + " " + gamma, conn); // For better readability // text.FontSize = 13; // End the line for the data in the database // text.Text = "Langauge\t | \tUnicodeData" + Environment.NewLine + Environment.NewLine; using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { // Write the data //label1.Text = reader[0].ToString(); words[i] = reader[0].ToString(); //c = reader[0].ToString(); } } } w = w + 1; // o = o + 1; } } for (int i = 1; i < words.Length; i++) { type = type + words[i] + " "; } PdfFont font12501 = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H); Paragraph para = new Paragraph(); para.SetFont(font12501); para.Add(type); if (align.Equals("LEFT")) { para.SetTextAlignment(iText.Layout.Properties.TextAlignment.LEFT); } if (align.Equals("CENTRE")) { para.SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); } document.Add(para); } if (words[0].Equals("blank_line")) { Paragraph para = new Paragraph(); para.Add(new Text("\n")); document.Add(para); } if (words[0].Equals("create_table")) { int rows = (Int32.Parse(words[1])); int col = (Int32.Parse(words[2])); Table table = new Table(col); PdfFont font12501 = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H); table.SetFont(font12501); for (int j = 1; j <= (rows * col); j++) { line = Commands[alpha + j]; string[] words2 = line.Split(' '); words2[0] = ""; words2[1] = ""; words2[words2.Length - 1] = ""; string[] type; int y = 1; string h = string.Join(" ", words2); table.AddCell(h); } float width = (float.Parse(words[3])); //table.PaddingTop = 100; // table.LockedWidth = true; //table.TotalWidth = width; int H_alignment = 0; if (words[4] != "0") { // H_alignment = (Int32.Parse(words[1])); table.SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER); } document.Add(table); } alpha = alpha + 1; } document.Close(); } }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void button3_Click(object sender, EventArgs e) { LicenseKey.LoadLicenseFile("itextkey1528179689217_0.xml"); string line1, line; StreamReader file = new StreamReader("test.txt"); line1 = file.ReadLine(); string[] words1 = line1.Split(' '); /* int aa = (Int32.Parse(words1[2])); * int ab = (Int32.Parse(words1[3])); * int ac = (Int32.Parse(words1[4])); * int ad = (Int32.Parse(words1[5]));*/ //Document doc = new Document(iTextSharp.text.PageSize.LETTER,aa , ab, ac, ad); // PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("Test.pdf", FileMode.Create)); //doc.Open(); PdfDocument pdf = new PdfDocument(new PdfWriter(DEST)); Document document = new Document(pdf); // PdfContentByte pcb = wri.DirectContent; file.Close(); StreamReader file1 = new StreamReader("test.txt"); int count = 0; while ((line = file1.ReadLine()) != null) { count = count + 1; } file1.Close(); string[] Commands = new string[count]; StreamReader file2 = new StreamReader("test.txt"); for (int i = 0; i < count; i++) { Commands[i] = file2.ReadLine(); } file2.Close(); string[] words; int alpha = 0; while (alpha != count) { string temp = Commands[alpha]; words = temp.Split(); if (words[0].Equals("insert_image")) { iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance("yesbank.jpg"); png.ScalePercent(float.Parse(words[1])); float a = (float.Parse(words[2])); float b = (float.Parse(words[3])); float c = (float.Parse(words[4])); float d = (float.Parse(words[5])); //png.SetAbsolutePosition(doc.PageSize.Width -a -b, doc.PageSize.Height -c -d); // png.SetAbsolutePosition(doc.PageSize.Width - a - b, doc.PageSize.Height - c - d); // doc.Add(png); ImageData imageData = ImageDataFactory.Create("C:/Users/Ganesh.P.Nischay/source/repos/WindowsFormsApp2/WindowsFormsApp2/bin/Debug/yesbank.jpg"); // Create layout image object and provide parameters. Page number = 1 Image image = new Image(imageData).ScaleAbsolute(50, 60).SetFixedPosition(1, 530, 790); document.Add(image); } /* if (words[0].Equals("insert_bank_officials_signature")) * { * * iTextSharp.text.Image png1 = iTextSharp.text.Image.GetInstance("signature.jpg"); * png1.ScalePercent(float.Parse(words[1])); * float a = (float.Parse(words[2])); * float b = (float.Parse(words[3])); * float c = (float.Parse(words[4])); * float d = (float.Parse(words[5])); * // png1.SetAbsolutePosition(doc.PageSize.Width - a - b, doc.PageSize.Height -c -d); * //doc.Add(png1); * * }*/ if (words[0].Equals("para_write")) { //label1.Text = words[3]; words[0] = "\0"; // 0 string align = words[1]; words[1] = "\0"; // 1 words[words.Length - 1] = "\0"; // last " string type = "\0"; int fontsize = (Int32.Parse(words[3])); words[3] = "\0"; // 3 //iTextSharp.text.Font pfont1 = FontFactory.GetFont(iTextSharp.text.Font.FontFamily.TIMES_ROMAN.ToString(), 15, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); iTextSharp.text.Font pfont11; string color = words[4]; words[4] = "\0"; // 4 words[5] = "\0"; // 2 string str; str = File.ReadAllText(@"Details.json"); //Details result = JsonConvert.DeserializeObject<Details>(str); Details result = new Details(); //var dictionary = JsonConvert.DeserializeObject<IDictionary>(str); /*foreach(DictionaryEntry entry in dictionary) * { * Console.WriteLine(entry.Key + ": " + entry.Value); * }*/ JObject obj = JObject.Parse(str); for (int i = 0; i < words.Length; i++) { if (words[i].Equals("#amount#")) { string name = (string)obj["amount"]; words[i] = name; } if (words[i].Equals("#balance#")) { string name = (string)obj["balance"]; words[i] = name; } if (words[i].Equals("#purpose#")) { string name = (string)obj["purpose"]; words[i] = name; } if (words[i].Equals("#id#")) { string name = (string)obj["id"]; words[i] = name; } } if (words[2] == "BOLD") { words[2] = "\0"; for (int i = 0; i < words.Length; i++) { type = type + words[i] + " "; } // PdfFont font1250 = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H); // Paragraph para1 = new Paragraph(type, pfont11); PdfFont font1250 = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H); Paragraph para1 = new Paragraph(); para1.SetFont(font1250); para1.Add(type); if (align.Equals("LEFT")) { para1.SetTextAlignment(iText.Layout.Properties.TextAlignment.LEFT); } if (align.Equals("CENTRE")) { para1.SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); } document.Add(para1); } else { words[2] = "\0"; for (int i = 0; i < words.Length; i++) { type = type + words[i] + " "; } PdfFont font1250 = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H); Paragraph para = new Paragraph().SetFontSize(fontsize); para.SetFont(font1250); para.Add(type); if (align.Equals("LEFT")) { para.SetTextAlignment(iText.Layout.Properties.TextAlignment.LEFT); } if (align.Equals("CENTRE")) { para.SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); } document.Add(para); } } int gamma = 1;//////////////////////////////yyyyyy if (words[0].Equals("blank_line")) { Paragraph para = new Paragraph(); para.Add(new Text("\n")); document.Add(para); } if (words[0].Equals("create_table")) { int rows = (Int32.Parse(words[1])); int col = (Int32.Parse(words[2])); Table table = new Table(col); PdfFont font12501 = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H); int control = rows + 1; table.SetFont(font12501); int u = 0; if (words[3].Equals("D")) { for (int j1 = 1; j1 <= rows + 1; j1++) { line = Commands[alpha + j1]; string[] words2 = line.Split(' '); words2[0] = ""; words2[1] = ""; words2[words2.Length - 1] = ""; string str; string h = string.Join(" ", words2); if (j1 == control) { str = File.ReadAllText(@"Details.json"); JObject jo = JObject.Parse(str); u = 9; if (words2[2].Equals("#input#")) { foreach (var result in jo["table"]) { string slno = (string)result["sl no"]; string FirstName = (string)result["FirstName"]; string Last_name = (string)result["Last_name"]; table.AddCell(slno); table.AddCell(FirstName); table.AddCell(Last_name); } // string name = (string)j["table"]; } } if (u != 9) { table.AddCell(h); } } } else { for (int j = 1; j <= (rows * col); j++) { line = Commands[alpha + j]; string[] words2 = line.Split(' '); words2[0] = ""; words2[1] = ""; words2[words2.Length - 1] = ""; string[] type; //int y = 1; string h = string.Join(" ", words2); table.AddCell(h); } } //float width = (float.Parse(words[3])); 570 //table.PaddingTop = 100; // table.LockedWidth = true; //table.TotalWidth = width; int H_alignment = 0; if (words[4] != "0") { // H_alignment = (Int32.Parse(words[1])); table.SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER); //make changes to noepad } document.Add(table); } alpha = alpha + 1; } document.Close(); }
private void button1_Click(object sender, EventArgs e) { LicenseKey.LoadLicenseFile("C:/Users/Toni/Desktop/Fingerprint_Test/itextkey1524180183686_0.xml"); iText.Layout.Element.Image leftIndex = new iText.Layout.Element.Image(ImageDataFactory.Create(LeftIndex)); iText.Layout.Element.Image rightIndex = new iText.Layout.Element.Image(ImageDataFactory.Create(RightIndex)); /* * // Modify PDF located at "source" and save to "target" * PdfDocument pdfDocument = new PdfDocument(new PdfReader(src), new PdfWriter(dest)); * // Document to add layout elements: paragraphs, images etc * Document document = new Document(pdfDocument); * * // Load image from disk * ImageData imageData = ImageDataFactory.Create(LeftIndex); * // Create layout image object and provide parameters. Page number = 1 * iText.Layout.Element.Image image = new iText.Layout.Element.Image(imageData).ScaleAbsolute(100, 200).SetFixedPosition(1, 25, 25); * // This adds the image to the page * document.Add(image); * * // Don't forget to close the document. * // When you use Document, you should close it rather than PdfDocument instance * document.Close(); */ // Read each line of the file into a string array. Each element // of the array is one line of the file. string[] lines = System.IO.File.ReadAllLines(info_src, Encoding.UTF8); //string line1 = System.Text.Encoding.UTF8.GetString(lines[1]); // Display the file contents by using a foreach loop. //Console.OutputEncoding = Encoding.UTF8; //System.Console.OutputEncoding = System.Text.Encoding.UTF8; //System.Console.WriteLine("Contents of WriteLines2.txt = "); textBox1.Text = lines[1]; foreach (string line in lines) { // Use a tab to indent each line of the file. //Console.WriteLine("\t" + line/*, Console.OutputEncoding.UTF8Encoding*/); } var writer = new PdfWriter(dest); var pdf = new PdfDocument(writer); var document = new Document(pdf); document.Add(new Paragraph("Hello World!")); //************************************************************************************ //Russian Part: //Text Constants: String CZECH = "Podivn\u00fd p\u0159\u00edpad Dr. Jekylla a pana Hyda"; String RUSSIAN = "\u0421\u0442\u0440\u0430\u043d\u043d\u0430\u044f " + "\u0438\u0441\u0442\u043e\u0440\u0438\u044f " + "\u0434\u043e\u043a\u0442\u043e\u0440\u0430 " + "\u0414\u0436\u0435\u043a\u0438\u043b\u0430 \u0438 " + "\u043c\u0438\u0441\u0442\u0435\u0440\u0430 " + "\u0425\u0430\u0439\u0434\u0430"; String KOREAN = "\ud558\uc774\ub4dc, \uc9c0\ud0ac, \ub098"; //Font Constants: String FONT = "C:/Users/Toni/Desktop/Fingerprint_Test/FreeSans.ttf"; //"src/main/resources/fonts/FreeSans.ttf"; String HCRBATANG = "C:/Users/Toni/Desktop/Fingerprint_Test/HANBatang.ttf"; //"src/main/resources/fonts/HANBatang.ttf"; //String NAZANIN = "C:/Users/Toni/Desktop/Fingerprint_Test/B Nazanin.ttf"; //"src/main/resources/fonts/HANBatang.ttf"; //Add to Document: PdfFont font1250 = PdfFontFactory.CreateFont(FONT, PdfEncodings.CP1250, true); document.Add(new Paragraph().SetFont(font1250) .Add(CZECH).Add(" by Robert Louis Stevenson")); PdfFont font1251 = PdfFontFactory.CreateFont(FONT, "Cp1251", true); document.Add(new Paragraph().SetFont(font1251) .Add(RUSSIAN).Add(" by Robert Louis Stevenson")); PdfFont fontUnicode = PdfFontFactory.CreateFont(HCRBATANG, PdfEncodings.IDENTITY_H, true); document.Add(new Paragraph().SetFont(fontUnicode) .Add(KOREAN).Add(" by Robert Louis Stevenson")); //End Russian Part //************************************************************************************ /* * //Add Arabic-Inverted * PdfFont fontUnicodeNazanin = * PdfFontFactory.CreateFont(NAZANIN, PdfEncodings.IDENTITY_H, true); * //document.Add(new Paragraph().SetFont(fontUnicodeNazanin) * //.Add("الموافق").Add(" by Ostad")); * * //Add Arabic Correct (?) @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * //itext 7 Equivalent * //Text redText = new Text("Nos formules") * Text redText = new Text("الموافق") * .SetFont(fontUnicodeNazanin) * .SetFontSize(20); * Paragraph p2 = new Paragraph().Add(redText); * //document.Add(p2); * //document.Add(new Phrase("This is a ميسو ɸ", f)); */ /* * //************************************************************************************ * //Style Part: * Style arabic = new Style().SetTextAlignment(TextAlignment.RIGHT).SetBaseDirection(BaseDirection.RIGHT_TO_LEFT). * SetFontSize(20).SetFont(fontUnicodeNazanin); * * //document.Add(new Paragraph("م الموافق").SetFontScript(Character.UnicodeScript.ARABIC).AddStyle(arabic)); * * * //End Style Part * //************************************************************************************ */ /* * var times = PdfFontFactory.CreateFont(NAZANIN, PdfEncodings.IDENTITY_H, true); * Style arabic2 = new Style().SetBaseDirection(BaseDirection.RIGHT_TO_LEFT); * Paragraph p3 = new Paragraph(); * p3.SetFont(NAZANIN); * p3.AddStyle(arabic2); * Text t = new Text("أسبوع"); * p3.Add(t); * //document.Add(p3); */ //************************************************************************************ //Calligraph Part: Document arabicPdf = new Document(new PdfDocument(new PdfWriter("C:/Users/Toni/Desktop/Fingerprint_Test/arabic.pdf"))); // Arabic text starts near the top right corner of the page arabicPdf.SetTextAlignment(TextAlignment.RIGHT); // create a font, and make it the default for the document //PdfFont f = PdfFontFactory.CreateFont("C:/Users/Toni/Desktop/Fingerprint_Test/DroidKufi-Regular.ttf", PdfEncodings.IDENTITY_H, true); //Arial -> OK //Tahoma -> OK //Koodak -> OK //A_Nefel_Botan -> OK //PdfFont f = PdfFontFactory.CreateFont("C:/Windows/Fonts/tahoma.ttf", PdfEncodings.IDENTITY_H, true); PdfFont f = PdfFontFactory.CreateFont("C:/Users/Toni/Desktop/Fingerprint_Test/A_Nefel_Botan.ttf", PdfEncodings.IDENTITY_H, true); //PdfFont f = PdfFontFactory.CreateFont("C:/Windows/Fonts/W_nazanin.ttf", PdfEncodings.IDENTITY_H, true); arabicPdf.SetFont(f); // add content: السلام عليكم (as-salaamu 'aleykum - peace be upon you) //arabicPdf.Add(new Paragraph("أسبوع")); //arabicPdf.Add(new Paragraph("هویج")); arabicPdf.Add(new Paragraph(lines[1])); arabicPdf.Close(); //End Calligraph Part //************************************************************************************ /* * //************************************************************************************ * //Hebrew Part: * * //Use a table so that we can set the text direction * Table table = new Table(1); * //Ensure that wrapping is on, otherwise Right to Left text will not display * //table.DefaultCell.NoWrap = false; * table.AddStyle(arabic); * * table.AddCell(new Cell().SetHorizontalAlignment(HorizontalAlignment.CENTER).Add(p2)); * * * //Create a regex expression to detect hebrew or arabic code points * const string regex_match_arabic_hebrew = @"[\u0600-\u06FF,\u0590-\u05FF]+"; * //if (Regex.IsMatch("מה קורה", regex_match_arabic_hebrew, RegexOptions.IgnoreCase)) * { * table.RunDirection = PdfWriter.RUN_DIRECTION_RTL; * } * * //Create a cell and add text to it * PdfPCell text = new PdfPCell(new Phrase("מה קורה", font)); * //Ensure that wrapping is on, otherwise Right to Left text will not display * text.NoWrap = false; * * //Add the cell to the table * table.AddCell(text); * * //Add the table to the document * document.Add(table); * //End Hebrew Part * //************************************************************************************ */ document.Add(new Paragraph(lines[1])); Paragraph p = new Paragraph("Right Index").Add(rightIndex).Add("Left Index").Add(leftIndex); // Add Paragraph to document document.Add(p); //******************************************************************************************************** //Arabic in pdf using iTextSharp in c# //******************************************************************************************************** /* * //Declare a itextSharp document * //Document document = new Document(PageSize.A4); * //Create our file stream and bind the writer to the document and the stream * //PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(@"D:\Test.Pdf", FileMode.Create)); * * //Open the document for writing * //document.Open(); * * //Add a new page * //document.NewPage(); * * //Reference a Unicode font to be sure that the symbols are present. * BaseFont bfArialUniCode = BaseFont.CreateFont(@"D:\ARIALUNI.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); * //Create a font from the base font * Font font = new Font(bfArialUniCode, 12); * * //Use a table so that we can set the text direction * PdfPTable table = new PdfPTable(1); * //Ensure that wrapping is on, otherwise Right to Left text will not display * table.DefaultCell.NoWrap = false; * * //Create a regex expression to detect hebrew or arabic code points * const string regex_match_arabic_hebrew = @"[\u0600-\u06FF,\u0590-\u05FF]+"; * if (Regex.IsMatch("م الموافق", regex_match_arabic_hebrew, RegexOptions.IgnoreCase)) * { * table.RunDirection = PdfWriter.RUN_DIRECTION_RTL; * } * * //Create a cell and add text to it * PdfPCell text = new PdfPCell(new Phrase(" : " + "من قبل وبين" + " 2007 " + "م الموافق" + " dsdsdsdsds " + "تم إبرام هذا العقد في هذا اليوم ", font)); * //Ensure that wrapping is on, otherwise Right to Left text will not display * text.NoWrap = false; * * //Add the cell to the table * table.AddCell(text); * * //Add the table to the document * document.Add(table); * * //PdfFont f = PdfFontFactory.createFont(FONT, PdfEncodings.IDENTITY_H); * * //********************************************************************* * * //Launch the document if you have a file association set for PDF's * //Process AcrobatReader = new Process(); * //AcrobatReader.StartInfo.FileName = @"D:\Test.Pdf"; * //AcrobatReader.Start(); */ document.Close(); }