/// <summary> /// Displaying the current cell's data as a Wingdings symbol. /// </summary> public WingdingsSymbolField() { if (!FontFactory.IsRegistered(WingdingsFontPath)) { FontFactory.Register(WingdingsFontPath); } }
public static void Register(string name) { if (!FontFactory.IsRegistered(name)) { var path = $"{Environment.GetFolderPath(Environment.SpecialFolder.Windows)}\\Fonts\\{name}.tff"; FontFactory.Register(path); } }
/// <summary> /// Creates a new font from model. /// </summary> /// <param name="font">Font to create.</param> /// <returns> /// A new <see cref="Font"/> that contains specified font from model. /// </returns> public static Font CreateFont(FontModel font) { Logger.Instance.Debug(""); Logger.Instance.Debug(" Assembly: iTin.Utilities.Pdf, Namespace: iTin.Utilities.Pdf.Helpers, Class: PdfHelper"); Logger.Instance.Debug($" Creates a new font from model"); Logger.Instance.Debug($" > Signature: ({typeof(Font)}) CreateFont({typeof(FontModel)})"); Logger.Instance.Debug($" > font: {font}"); if (font == null) { font = FontModel.DefaultFont; } int registeredFonts = FontFactory.RegisteredFonts.Count; if (registeredFonts <= 14) { FontFactory.RegisterDirectories(); } int style = Font.NORMAL; if (font.Italic.AsBoolean()) { style = Font.ITALIC; } if (font.Bold.AsBoolean()) { style |= Font.BOLD; } if (font.Underline.AsBoolean()) { style |= Font.UNDERLINE; } Font validFont; var isFontRegistered = FontFactory.IsRegistered(font.Name); if (isFontRegistered) { validFont = FontFactory.GetFont( font.Name, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, font.Size, style, new BaseColor(font.GetColor())); } else { var baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, FontFactory.DefaultEncoding, BaseFont.EMBEDDED); validFont = new Font(baseFont, font.Size, style, new BaseColor(font.GetColor())); } return(validFont); }
public iTextSharp.text.Font getFont(string fontName) { if (!FontFactory.IsRegistered(fontName)) { var fontPath = "fonts\\" + fontName; FontFactory.Register(fontPath); } return(FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); }
private static Font RegistrerFont(string fontname, float Size, int Style, BaseColor Color) { if (!FontFactory.IsRegistered(fontname)) { string fontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), $"{fontname.ToLower()}.ttf"); FontFactory.Register(fontPath); } return(FontFactory.GetFont(fontname, Size, Style, Color)); }
public static iTextSharp.text.Font GetFont(string FontName, string FontPath, bool IsFullPath = false) { if (!FontFactory.IsRegistered(FontName)) { var fontPath = IsFullPath ? FontPath : Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\" + FontPath; FontFactory.Register(fontPath); } return(FontFactory.GetFont(FontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); }
public static Font GetUnicodeFont( string fontName, string fontFilePath, float size, int style, BaseColor color) { if (!FontFactory.IsRegistered(fontName)) { FontFactory.Register(fontFilePath); } return(FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, size, style, color)); }
private static Font GetFont(string fontName, string filename) { if (!FontFactory.IsRegistered(fontName)) { var fontPath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\" + filename; FontFactory.Register(fontPath); } return(FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); }
public static Font GetFont() { if (!FontFactory.IsRegistered(FontName)) { FontFactory.Register(PublicMethods.map_path(FontAddress)); } return(FontFactory.GetFont(FontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); }
public Font GetTHSarabunNew() { var fontName = "THSarabunNew"; if (!FontFactory.IsRegistered(fontName)) { var fontPath = this.path + "\\Fonts\\THSarabunNew.ttf"; FontFactory.Register(fontPath); } return(FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); }
public iTextSharp.text.Font GetZHFont() // chinese font { var fontName = "simhei"; if (!FontFactory.IsRegistered(fontName)) { var fontPath = Server.MapPath("~") + "images\\fonts\\simhei.ttf"; FontFactory.Register(fontPath); } return(FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); }
public static Font GetTahoma() { var fontName = "Tahoma"; if (!FontFactory.IsRegistered(fontName)) { var fontPath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\tahoma.ttf"; FontFactory.Register(fontPath); } return(FontFactory.GetFont(fontName, BaseFont.CP1250, 8, Font.NORMAL)); }
public static Font GetTahomaFont() { const string fontName = "Tahoma"; if (!FontFactory.IsRegistered(fontName)) { var fontPath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\tahoma.ttf"; FontFactory.Register(fontPath); } return(FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); }
private static iTextSharp.text.Font GetFont(string fontName, int fontSize) { if (!FontFactory.IsRegistered(fontName)) { FontFactory.Register(Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\" + fontName + ".ttf"); } return(FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, fontSize)); }
F GetVerdana(float taille, int style = F.NORMAL, BaseColor color = null) { color = color ?? new BaseColor(111, 111, 111); var fontName = "Verdana"; if (!FontFactory.IsRegistered(fontName) && File.Exists(_fontFilePath)) { FontFactory.Register(_fontFilePath); } return(FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, taille, style, color)); }
public iTextSharp.text.Font GetTextFont() { var fontName = "Ubuntu"; if (!FontFactory.IsRegistered(fontName)) { var fontPath = Server.MapPath("~") + "images\\fonts\\Ubuntu-Regular.ttf"; FontFactory.Register(fontPath); } return(FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); }
public static iTextSharp.text.Font GetTahoma() { var fontName = "Tahoma"; if (!FontFactory.IsRegistered(fontName)) { var fontPath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\tahoma.ttf"; FontFactory.Register(fontPath); } return(FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 22f, Font.BOLD)); }
public VisitorPDF(Document doc) { pdf = doc; if (!FontFactory.IsRegistered("Arial")) { var fontPath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\arial.ttf"; FontFactory.Register(fontPath); } fonte = FontFactory.GetFont("Arial", 10); fonteTitulo = FontFactory.GetFont("Arial", 14); }
private static void registerFonts(string mainFontPath, string defaultFontPath) { if (!FontFactory.IsRegistered(mainFontPath)) { FontFactory.Register(mainFontPath); } if (!FontFactory.IsRegistered(defaultFontPath)) { FontFactory.Register(defaultFontPath); } }
/** * Retrieves a font from the FontFactory based on some style attributes. * Looks for the font-family, font-size, font-weight, font-style and color. * Takes the default encoding and embedded value. * * @param styleAttributes * a Properties object containing keys and values * @return an iText Font object */ public Font RetrieveFont(Properties styleAttributes) { String fontname = null; String encoding = FontFactory.DefaultEncoding; bool embedded = FontFactory.DefaultEmbedding; float size = Font.UNDEFINED; int style = Font.NORMAL; Color color = null; String value = (String)styleAttributes[MarkupTags.CSS_KEY_FONTFAMILY]; if (value != null) { if (value.IndexOf(",") == -1) { fontname = value.Trim(); } else { String tmp; while (value.IndexOf(",") != -1) { tmp = value.Substring(0, value.IndexOf(",")).Trim(); if (FontFactory.IsRegistered(tmp)) { fontname = tmp; break; } else { value = value.Substring(value.IndexOf(",") + 1); } } } } if ((value = (String)styleAttributes[MarkupTags.CSS_KEY_FONTSIZE]) != null) { size = MarkupParser.ParseLength(value); } if ((value = (String)styleAttributes[MarkupTags.CSS_KEY_FONTWEIGHT]) != null) { style |= Font.GetStyleValue(value); } if ((value = (String)styleAttributes[MarkupTags.CSS_KEY_FONTSTYLE]) != null) { style |= Font.GetStyleValue(value); } if ((value = (String)styleAttributes[MarkupTags.CSS_KEY_COLOR]) != null) { color = MarkupParser.DecodeColor(value); } return(FontFactory.GetFont(fontname, encoding, embedded, size, style, color)); }
public BaseFont getTHSarabun() { string fontName = "THSarabunNew"; if (!FontFactory.IsRegistered(fontName)) { var fontPath = _hostingEnvironment.ContentRootPath + "\\Fonts\\THSarabunNew.ttf"; FontFactory.Register(fontPath); } FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); return(BaseFont.CreateFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED));; }
public static iTextSharp.text.Font GetTahoma() { const string fontName = "Iranian Sans"; if (FontFactory.IsRegistered(fontName)) { return(FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); } var fontPath = HttpContext.Current.Server.MapPath("~/Content/Fonts/irsans.ttf"); FontFactory.Register(fontPath); return(FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); }
/// <summary> /// Method for importing an external font so that it can be used while writing. /// </summary> /// <remarks> /// The method is able to read a font file and import it so it can be used to write. /// The name given to the font is used when referencing it in the writing methods. /// Some fonts such as Wingdings can lead to errors. /// </remarks> /// <param name="name">Name wanted for the font, with which it can be referenced later</param> /// <param name="path">Path of the .ttf file used to import the font</param> public void AddNewFont(string name, string path) { if (!FontFactory.IsRegistered(name)) { if (!File.Exists(path)) { throw new Exception("Fount file not found in the specified path"); } FontFactory.Register(path); fonts.Add(name, fonts.Count); } var baseFont = FontFactory.GetFont(name, BaseFont.IDENTITY_H, BaseFont.EMBEDDED).GetCalculatedBaseFont(false); FontList.Add(baseFont); }
public static Font GerarFonte(tipoFonte tipo, int tamanho, int style, BaseColor corFonte) { Font fonteRetorno = null; string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Etx\\"; if (!File.Exists(path + "ARIALN.TTF") || !File.Exists(path + "ariblk.ttf") || !File.Exists(path + "ARIAL.TTF")) { ExportarFontes(path); } switch (tipo) { case tipoFonte.ArialNarrow: path += "ARIALN.TTF"; if (!FontFactory.IsRegistered(tipoFonte.ArialNarrow.ToString())) { FontFactory.Register(path, tipoFonte.ArialNarrow.ToString()); } fonteRetorno = FontFactory.GetFont(tipoFonte.ArialNarrow.ToString(), tamanho, style, corFonte); break; case tipoFonte.ArialBlack: path += "ariblk.ttf"; if (!FontFactory.IsRegistered("Arial Black")) { FontFactory.Register(path, "Arial Black"); } fonteRetorno = FontFactory.GetFont("Arial Black", BaseFont.CP1252, BaseFont.NOT_EMBEDDED, tamanho, style, corFonte); break; case tipoFonte.Arial: path += "ARIAL.TTF"; if (!FontFactory.IsRegistered("ARIAL")) { FontFactory.Register(path, "ARIAL"); } fonteRetorno = FontFactory.GetFont("ARIAL", BaseFont.CP1252, BaseFont.NOT_EMBEDDED, tamanho, style, corFonte); break; } return(fonteRetorno); }
private static IResult TryRegisterFont(string fontName, string fontFullPath) { try { var isRegistered = FontFactory.IsRegistered(fontName); if (isRegistered) { return(BooleanResult.SuccessResult); } var path = iTinIO.Path.PathResolver(fontFullPath); FontFactory.Register(path, fontName); return(BooleanResult.SuccessResult); } catch (Exception ex) { return(BooleanResult.FromException(ex)); } }
public void Verify_Issue12_CanBe_Processed() { Document document = new Document(PageSize.A4.Rotate()); PdfPTable table = new PdfPTable(7); //actual width of table in points table.TotalWidth = 800f; //fix the absolute width of the table table.LockedWidth = true; table.HorizontalAlignment = Element.ALIGN_CENTER; table.SpacingBefore = 20f; table.SpacingAfter = 20f; document.SetMargins(5, 5, 5, 5); if (!FontFactory.IsRegistered("Arial")) { throw new InvalidOperationException(); } Font arial = FontFactory.GetFont("Arial"); //BaseFont font = BaseFont.CreateFont(arial., BaseFont.CP1250, BaseFont.EMBEDDED); Font font8 = new Font(arial.BaseFont, 8, Font.NORMAL); Font font12 = new Font(arial.BaseFont, 12, Font.NORMAL); Font font14 = new Font(arial.BaseFont, 14, Font.NORMAL); Font font16 = new Font(arial.BaseFont, 16, Font.BOLD); var filePath = TestUtils.GetOutputFileName(); var fs = new FileStream(filePath, FileMode.Create); PdfWriter.GetInstance(document, fs); document.AddAuthor(TestUtils.Author); document.Open(); var cell = new PdfPCell(new Phrase("ZG£OSZENIE/AKTUALIZACJA PRZEZ PODMIOT PROWADZ¥CY SERWIS KAS LUB PROWADZ¥CY SERWIS G£سWNY DANYCH DOTYCZ¥CYCH KASY" /*, font14*/)); cell.Rowspan = 2; cell.Colspan = 5; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Nr dokumentu: 123/456/789")); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Phrase("Data przyjêcia dokumentu:" + DateTime.Now.ToString("dd.MM.yyyy"))); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Phrase("MIEJSCE SK£ADANIA ZAWIADOMIENIA", font16)); cell.Colspan = 7; table.AddCell(cell); cell = new PdfPCell(new Phrase("Naczelnik Urzêdu Skarbowego do ktَrego skierowane jest zawiadomienie: " + "UrZ_Nazwa", font12)); cell.Colspan = 7; table.AddCell(cell); cell = new PdfPCell(new Phrase("Ulica: " + "UrZ_Ulica", font12)); cell.Colspan = 5; table.AddCell(cell); cell = new PdfPCell(new Phrase("Nr domu: " + "UrZ_NrDomu", font12)); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Phrase("Miejscowoœو: " + "UrZ_Miasto", font12)); cell.Colspan = 5; table.AddCell(cell); cell = new PdfPCell(new Phrase("Kod pocztowy: " + "UrZ_KodPocztowy", font12)); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Phrase("DANE IDENTYFIKACYJNE SPRZEDAWCY KAS", font16)); cell.Colspan = 7; table.AddCell(cell); cell = new PdfPCell(new Phrase("Nazwa (imiê i nazwisko): TRON Computers Sp. z o.o.", font12)); cell.Colspan = 7; table.AddCell(cell); cell = new PdfPCell(new Phrase("Numer identyfikacyjny: 6332058814", font12)); cell.Colspan = 3; table.AddCell(cell); cell = new PdfPCell(new Phrase("REGON / PESEL: 89050315795", font12)); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Phrase("Telefon 32 4731002", font12)); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Phrase("Wojewَdztwo: Œl¹skie", font12)); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Phrase("Gmina / Dzielnica: Jastrzêbie-Zdrَj", font12)); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Phrase("Ulica: 11 Listopada", font12)); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Phrase("Nr domu: 71", font12)); cell.Colspan = 1; table.AddCell(cell); cell = new PdfPCell(new Phrase("Nr lokalu: ", font12)); cell.Colspan = 1; table.AddCell(cell); cell = new PdfPCell(new Phrase("Miejscowoœو: Jastrzêbie-Zdrَj", font12)); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Phrase("Kod pocztowy: 44-335", font12)); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Phrase("Poczta: Jastrzêbie-Zdrَj", font12)); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Phrase("DANE IDENTYFIKACYJNE PRODUCENTA (IMPORTERA) SPRZEDAWANYCH KAS", font16)); cell.Colspan = 7; table.AddCell(cell); cell = new PdfPCell(new Phrase("Nazwa (imiê i nazwisko) oraz adres", font12)); cell.Colspan = 5; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Typ / Model kasy", font12)); cell.Colspan = 2; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("ELZAB" + "\n" + "Jakaœ tam" + "\n" + "32-456" + " " + "Zabrze", font14)); cell.Colspan = 5; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.MinimumHeight = 60; table.AddCell(cell); cell = new PdfPCell(new Phrase("JOTA", font14)); cell.Colspan = 2; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("MIEJSCE INSTALACJI KAS REJESTRUJACYCH", font16)); cell.Colspan = 7; table.AddCell(cell); cell = new PdfPCell(new Phrase("Dane identyfikacyjne podatnika:\nNazwa, dok³adny adres, NIP,\nMiejsce instalacji", font12)); cell.Colspan = 2; cell.Rowspan = 2; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Typ / Model kasy", font12)); cell.Rowspan = 2; cell.Colspan = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Numery kasy / Data", font12)); cell.Colspan = 3; cell.Rowspan = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Uwagi Urzêdu Skarbowego", font12)); cell.Colspan = 1; cell.Rowspan = 2; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Unikatowy\nData fiskalizacji", font12)); cell.Colspan = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Fabryczny", font12)); cell.Colspan = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Ewidencyjny", font12)); cell.Colspan = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Test Test", font12)); cell.Colspan = 2; cell.Rowspan = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("JOTA", font12)); cell.Rowspan = 1; cell.Colspan = 1; cell.MinimumHeight = 120; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Test Test", font12)); cell.Colspan = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Test Test", font12)); cell.Colspan = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Test Test", font12)); cell.Colspan = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Coœ tam napisze, ؟eby nie by³o :D", font12)); cell.Colspan = 1; cell.Rowspan = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); cell = new PdfPCell(new Phrase("Test Test", font12)); cell.Colspan = 3; cell.Rowspan = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_BOTTOM; cell.MinimumHeight = 100; table.AddCell(cell); cell = new PdfPCell(new Phrase("Test Test", font12)); cell.Rowspan = 1; cell.Colspan = 4; cell.MinimumHeight = 100; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_BOTTOM; table.AddCell(cell); document.Add(table); document.Close(); fs.Dispose(); TestUtils.VerifyPdfFileIsReadable(filePath); }
public ActionResult AccountsReceivableReport(String DateAsOf, Int32 CompanyId, Int32 BranchId, Int32 AccountId) { // ======================== // PDF settings and Formats // ======================== MemoryStream workStream = new MemoryStream(); Rectangle rectangle = new Rectangle(PageSize.A3); Document document = new Document(rectangle, 72, 72, 72, 72); document.SetMargins(30f, 30f, 30f, 30f); PdfWriter.GetInstance(document, workStream).CloseStream = false; document.Open(); // =================== // Fonts Customization // =================== var fontName = "Calibri"; if (!FontFactory.IsRegistered(fontName)) { var fontPath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\calibri.ttf"; FontFactory.Register(fontPath); } Font fontArial17Bold = FontFactory.GetFont("Tahoma", 17, Font.BOLD); Font fontArial11 = FontFactory.GetFont("Tahoma", 11); Font fontArial9Bold = FontFactory.GetFont("Tahoma", 9, Font.BOLD); Font fontArial9 = FontFactory.GetFont("Tahoma", 9); Font fontArial9Italic = FontFactory.GetFont("Tahoma", 9, Font.ITALIC); Font fontArial12Bold = FontFactory.GetFont("Tahoma", 12, Font.BOLD); Font fontArial10Bold = FontFactory.GetFont("Tahoma", 10, Font.BOLD); // ==== // line // ==== Paragraph line = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 4.5F))); // ============== // Company Detail // ============== var companyName = (from d in db.MstCompanies where d.Id == CompanyId select d).FirstOrDefault().Company; var address = (from d in db.MstCompanies where d.Id == CompanyId select d).FirstOrDefault().Address; var contactNo = (from d in db.MstCompanies where d.Id == CompanyId select d).FirstOrDefault().ContactNumber; // ================= // table main header // ================= PdfPTable headerPage = new PdfPTable(2); float[] widthsCellsHeaderPage = new float[] { 100f, 75f }; headerPage.SetWidths(widthsCellsHeaderPage); headerPage.WidthPercentage = 100; headerPage.AddCell(new PdfPCell(new Phrase(companyName, fontArial17Bold)) { Border = 0 }); headerPage.AddCell(new PdfPCell(new Phrase("Accounts Receivable", fontArial17Bold)) { Border = 0, HorizontalAlignment = 2 }); headerPage.AddCell(new PdfPCell(new Phrase(address, fontArial11)) { Border = 0, PaddingTop = 5f }); headerPage.AddCell(new PdfPCell(new Phrase("Date as of " + Convert.ToDateTime(DateAsOf).ToString("MM-dd-yyyy", CultureInfo.InvariantCulture), fontArial11)) { Border = 0, PaddingTop = 5f, HorizontalAlignment = 2, }); headerPage.AddCell(new PdfPCell(new Phrase(contactNo, fontArial11)) { Border = 0, PaddingTop = 5f }); headerPage.AddCell(new PdfPCell(new Phrase("Printed " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToString("hh:mm:ss tt"), fontArial11)) { Border = 0, PaddingTop = 5f, HorizontalAlignment = 2 }); document.Add(headerPage); document.Add(line); // ============== // Sales Invoices // ============== var salesInvoices = from d in db.TrnSalesInvoices where d.SIDate <= Convert.ToDateTime(DateAsOf) && d.MstBranch.CompanyId == Convert.ToInt32(CompanyId) && d.BranchId == Convert.ToInt32(BranchId) && d.MstArticle.AccountId == Convert.ToInt32(AccountId) && d.BalanceAmount > 0 && d.IsLocked == true select new { SIId = d.Id, Branch = d.MstBranch.Branch, AccountId = d.MstArticle.AccountId, AccountCode = d.MstArticle.MstAccount.AccountCode, Account = d.MstArticle.MstAccount.Account, SINumber = d.SINumber, SIDate = d.SIDate.ToShortDateString(), CustomerId = d.CustomerId, Customer = d.MstArticle.Article, DocumentReference = d.DocumentReference, DueDate = d.SIDate.AddDays(Convert.ToInt32(d.MstTerm.NumberOfDays)).ToShortDateString(), BalanceAmount = d.BalanceAmount, CurrentAmount = ComputeAge(0, Convert.ToDateTime(DateAsOf).Subtract(d.SIDate.AddDays(Convert.ToInt32(d.MstTerm.NumberOfDays))).Days, d.BalanceAmount), Age30Amount = ComputeAge(1, Convert.ToDateTime(DateAsOf).Subtract(d.SIDate.AddDays(Convert.ToInt32(d.MstTerm.NumberOfDays))).Days, d.BalanceAmount), Age60Amount = ComputeAge(2, Convert.ToDateTime(DateAsOf).Subtract(d.SIDate.AddDays(Convert.ToInt32(d.MstTerm.NumberOfDays))).Days, d.BalanceAmount), Age90Amount = ComputeAge(3, Convert.ToDateTime(DateAsOf).Subtract(d.SIDate.AddDays(Convert.ToInt32(d.MstTerm.NumberOfDays))).Days, d.BalanceAmount), Age120Amount = ComputeAge(4, Convert.ToDateTime(DateAsOf).Subtract(d.SIDate.AddDays(Convert.ToInt32(d.MstTerm.NumberOfDays))).Days, d.BalanceAmount) }; if (salesInvoices.Any()) { // ============ // Branch Title // ============ var branch = from d in db.MstBranches where d.Id == BranchId select d; String branchName = "N/A"; if (branch.Any()) { branchName = branch.FirstOrDefault().Branch; } PdfPTable branchTitle = new PdfPTable(1); float[] widthCellsBranchTitle = new float[] { 100f }; branchTitle.SetWidths(widthCellsBranchTitle); branchTitle.WidthPercentage = 100; branchTitle.AddCell(new PdfPCell(new Phrase(branchName, fontArial12Bold)) { Border = 0, HorizontalAlignment = 0, PaddingTop = 10f }); document.Add(branchTitle); // ============= // Account Title // ============= PdfPTable accountTitle = new PdfPTable(1); float[] widthCellsAccountTitle = new float[] { 100f }; accountTitle.SetWidths(widthCellsAccountTitle); accountTitle.WidthPercentage = 100; accountTitle.AddCell(new PdfPCell(new Phrase(salesInvoices.FirstOrDefault().AccountCode + " - " + salesInvoices.FirstOrDefault().Account, fontArial12Bold)) { Border = 0, HorizontalAlignment = 0, PaddingBottom = 5f }); document.Add(accountTitle); // ===== // Space // ===== PdfPTable spaceTable = new PdfPTable(1); float[] widthCellsSpaceTable = new float[] { 100f }; spaceTable.SetWidths(widthCellsSpaceTable); spaceTable.WidthPercentage = 100; spaceTable.AddCell(new PdfPCell(new Phrase(" ", fontArial10Bold)) { Border = 0, PaddingTop = 5f }); document.Add(spaceTable); // ====================== // Receiving Receipt Data // ====================== PdfPTable tableHeader = new PdfPTable(10); float[] widthCellsTableHeader = new float[] { 100f, 100f, 120f, 100f, 100f, 100f, 100f, 100f, 100f, 100f }; tableHeader.SetWidths(widthCellsTableHeader); tableHeader.WidthPercentage = 100; tableHeader.AddCell(new PdfPCell(new Phrase("SI Number", fontArial9Bold)) { HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 6f }); tableHeader.AddCell(new PdfPCell(new Phrase("SI Date", fontArial9Bold)) { HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 6f }); tableHeader.AddCell(new PdfPCell(new Phrase("Document Ref.", fontArial9Bold)) { HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 6f }); tableHeader.AddCell(new PdfPCell(new Phrase("Due Date", fontArial9Bold)) { HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 6f }); tableHeader.AddCell(new PdfPCell(new Phrase("Balance", fontArial9Bold)) { HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 6f }); tableHeader.AddCell(new PdfPCell(new Phrase("Current", fontArial9Bold)) { HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 6f }); tableHeader.AddCell(new PdfPCell(new Phrase("30 Days", fontArial9Bold)) { HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 6f }); tableHeader.AddCell(new PdfPCell(new Phrase("60 Days", fontArial9Bold)) { HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 6f }); tableHeader.AddCell(new PdfPCell(new Phrase("90 Days", fontArial9Bold)) { HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 6f }); tableHeader.AddCell(new PdfPCell(new Phrase("Over 120 Days", fontArial9Bold)) { HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 6f }); document.Add(tableHeader); var salesInvoiceGroupedCustomers = from d in salesInvoices group d by new { CustomerId = d.CustomerId, Customer = d.Customer } into g select new { CustomerId = g.Key.CustomerId, Customer = g.Key.Customer, BalanceAmount = g.Sum(d => d.BalanceAmount) }; if (salesInvoiceGroupedCustomers.Any()) { Decimal accountSubTotalBalanceAmount = 0; Decimal accountSubTotalCurrentAmount = 0; Decimal accountSubTotalAge30Amount = 0; Decimal accountSubTotalAge60Amount = 0; Decimal accountSubTotalAge90Amount = 0; Decimal accountSubTotalAge120AmountAmount = 0; foreach (var salesInvoiceGroupedCustomer in salesInvoiceGroupedCustomers) { // ============= // Customer Name // ============= PdfPTable customerName = new PdfPTable(1); float[] widthCellsCustomerName = new float[] { 100f }; customerName.SetWidths(widthCellsCustomerName); customerName.WidthPercentage = 100; customerName.AddCell(new PdfPCell(new Phrase(salesInvoiceGroupedCustomer.Customer, fontArial10Bold)) { Border = 0, HorizontalAlignment = 0, PaddingTop = 9f, PaddingBottom = 6f }); document.Add(customerName); var salesInvoicesComputeAges = from d in salesInvoices where d.CustomerId == salesInvoiceGroupedCustomer.CustomerId select new { SINumber = d.SINumber, SIDate = d.SIDate, DocumentReference = d.DocumentReference, BalanceAmount = d.BalanceAmount, DueDate = d.DueDate, CurrentAmount = d.CurrentAmount, Age30Amount = d.Age30Amount, Age60Amount = d.Age60Amount, Age90Amount = d.Age90Amount, Age120Amount = d.Age120Amount }; if (salesInvoicesComputeAges.Any()) { Decimal subTotalBalanceAmount = 0; Decimal subTotalCurrentAmount = 0; Decimal subTotalAge30Amount = 0; Decimal subTotalAge60Amount = 0; Decimal subTotalAge90Amount = 0; Decimal subTotalAge120AmountAmount = 0; PdfPTable data = new PdfPTable(10); float[] widthCellsData = new float[] { 100f, 100f, 120f, 100f, 100f, 100f, 100f, 100f, 100f, 100f }; data.SetWidths(widthCellsData); data.WidthPercentage = 100; foreach (var salesInvoicesWithComputeAge in salesInvoicesComputeAges) { subTotalBalanceAmount += salesInvoicesWithComputeAge.BalanceAmount; subTotalCurrentAmount += salesInvoicesWithComputeAge.CurrentAmount; subTotalAge30Amount += salesInvoicesWithComputeAge.Age30Amount; subTotalAge60Amount += salesInvoicesWithComputeAge.Age60Amount; subTotalAge90Amount += salesInvoicesWithComputeAge.Age90Amount; subTotalAge120AmountAmount += salesInvoicesWithComputeAge.Age120Amount; data.AddCell(new PdfPCell(new Phrase(salesInvoicesWithComputeAge.SINumber, fontArial9)) { HorizontalAlignment = 0, PaddingTop = 1f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 0 }); data.AddCell(new PdfPCell(new Phrase(salesInvoicesWithComputeAge.SIDate, fontArial9)) { HorizontalAlignment = 0, PaddingTop = 1f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 0 }); data.AddCell(new PdfPCell(new Phrase(salesInvoicesWithComputeAge.DocumentReference, fontArial9)) { HorizontalAlignment = 0, PaddingTop = 1f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 0 }); data.AddCell(new PdfPCell(new Phrase(salesInvoicesWithComputeAge.DueDate, fontArial9)) { HorizontalAlignment = 0, PaddingTop = 1f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 0 }); data.AddCell(new PdfPCell(new Phrase(salesInvoicesWithComputeAge.BalanceAmount.ToString("#,##0.00"), fontArial9)) { HorizontalAlignment = 2, PaddingTop = 1f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 0 }); data.AddCell(new PdfPCell(new Phrase(salesInvoicesWithComputeAge.CurrentAmount.ToString("#,##0.00"), fontArial9)) { HorizontalAlignment = 2, PaddingTop = 1f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 0 }); data.AddCell(new PdfPCell(new Phrase(salesInvoicesWithComputeAge.Age30Amount.ToString("#,##0.00"), fontArial9)) { HorizontalAlignment = 2, PaddingTop = 1f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 0 }); data.AddCell(new PdfPCell(new Phrase(salesInvoicesWithComputeAge.Age60Amount.ToString("#,##0.00"), fontArial9)) { HorizontalAlignment = 2, PaddingTop = 1f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 0 }); data.AddCell(new PdfPCell(new Phrase(salesInvoicesWithComputeAge.Age90Amount.ToString("#,##0.00"), fontArial9)) { HorizontalAlignment = 2, PaddingTop = 1f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 0 }); data.AddCell(new PdfPCell(new Phrase(salesInvoicesWithComputeAge.Age120Amount.ToString("#,##0.00"), fontArial9)) { HorizontalAlignment = 2, PaddingTop = 1f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 0 }); } // ========= // Sub Total // ========= data.AddCell(new PdfPCell(new Phrase(salesInvoiceGroupedCustomer.Customer + " Total", fontArial9Bold)) { Colspan = 4, HorizontalAlignment = 2, PaddingTop = 6f, PaddingBottom = 6f, PaddingRight = 10f, PaddingLeft = 10f, Border = 1 }); data.AddCell(new PdfPCell(new Phrase(subTotalBalanceAmount.ToString("#,##0.00"), fontArial9Bold)) { HorizontalAlignment = 2, PaddingTop = 6f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 1 }); data.AddCell(new PdfPCell(new Phrase(subTotalCurrentAmount.ToString("#,##0.00"), fontArial9Bold)) { HorizontalAlignment = 2, PaddingTop = 6f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 1 }); data.AddCell(new PdfPCell(new Phrase(subTotalAge30Amount.ToString("#,##0.00"), fontArial9Bold)) { HorizontalAlignment = 2, PaddingTop = 6f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 1 }); data.AddCell(new PdfPCell(new Phrase(subTotalAge60Amount.ToString("#,##0.00"), fontArial9Bold)) { HorizontalAlignment = 2, PaddingTop = 6f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 1 }); data.AddCell(new PdfPCell(new Phrase(subTotalAge90Amount.ToString("#,##0.00"), fontArial9Bold)) { HorizontalAlignment = 2, PaddingTop = 6f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 1 }); data.AddCell(new PdfPCell(new Phrase(subTotalAge120AmountAmount.ToString("#,##0.00"), fontArial9Bold)) { HorizontalAlignment = 2, PaddingTop = 6f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f, Border = 1 }); document.Add(data); accountSubTotalBalanceAmount = accountSubTotalBalanceAmount + subTotalBalanceAmount; accountSubTotalCurrentAmount = accountSubTotalCurrentAmount + subTotalCurrentAmount; accountSubTotalAge30Amount = accountSubTotalAge30Amount + subTotalAge30Amount; accountSubTotalAge60Amount = accountSubTotalAge60Amount + subTotalAge60Amount; accountSubTotalAge90Amount = accountSubTotalAge90Amount + subTotalAge90Amount; accountSubTotalAge120AmountAmount = accountSubTotalAge120AmountAmount + subTotalAge120AmountAmount; } } document.Add(spaceTable); document.Add(spaceTable); // ============================ // Account Title with Sub Total // ============================ PdfPTable accountTitleSubTotal = new PdfPTable(10); float[] widthsCellsAccountTitleSubTotal = new float[] { 100f, 100f, 120f, 100f, 100f, 100f, 100f, 100f, 100f, 100f }; accountTitleSubTotal.SetWidths(widthsCellsAccountTitleSubTotal); accountTitleSubTotal.WidthPercentage = 100; accountTitleSubTotal.AddCell(new PdfPCell(new Phrase(salesInvoices.FirstOrDefault().AccountCode + " - " + salesInvoices.FirstOrDefault().Account + " Total", fontArial9Bold)) { Colspan = 4, HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 6f, PaddingRight = 10f, PaddingLeft = 10f }); accountTitleSubTotal.AddCell(new PdfPCell(new Phrase(accountSubTotalBalanceAmount.ToString("#,##0.00"), fontArial9Bold)) { HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f }); accountTitleSubTotal.AddCell(new PdfPCell(new Phrase(accountSubTotalCurrentAmount.ToString("#,##0.00"), fontArial9Bold)) { HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f }); accountTitleSubTotal.AddCell(new PdfPCell(new Phrase(accountSubTotalAge30Amount.ToString("#,##0.00"), fontArial9Bold)) { HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f }); accountTitleSubTotal.AddCell(new PdfPCell(new Phrase(accountSubTotalAge60Amount.ToString("#,##0.00"), fontArial9Bold)) { HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f }); accountTitleSubTotal.AddCell(new PdfPCell(new Phrase(accountSubTotalAge90Amount.ToString("#,##0.00"), fontArial9Bold)) { HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f }); accountTitleSubTotal.AddCell(new PdfPCell(new Phrase(accountSubTotalAge120AmountAmount.ToString("#,##0.00"), fontArial9Bold)) { HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 6f, PaddingRight = 5f, PaddingLeft = 5f }); document.Add(accountTitleSubTotal); } } document.Close(); byte[] byteInfo = workStream.ToArray(); workStream.Write(byteInfo, 0, byteInfo.Length); workStream.Position = 0; return(new FileStreamResult(workStream, "application/pdf")); }
public void getPdfPartitura(Partitura partitura) { if (!FontFactory.IsRegistered("Night-Braille")) { FontFactory.RegisterFamily("Night-Braille", "Night-Braille", @"C:\Windows\Fonts"); FontFactory.RegisterDirectories(); } Font fontBraille = FontFactory.GetFont("Night-Braille", 30, 0); if (!FontFactory.IsRegistered("LASSUS")) { FontFactory.RegisterFamily("LASSUS", "ttfNormal", @"C:\Windows\Fonts"); FontFactory.RegisterDirectories(); } Font fontPartitura = FontFactory.GetFont("LASSUS", 60, 0); Font fontArial = FontFactory.GetFont("Arial", 15, 1); Font fontArial2 = FontFactory.GetFont("Arial", 15, 0); Document doc = new Document(iTextSharp.text.PageSize.A4, 20, 20, 20, 20); string exeFile = (new System.Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath; string exeDir = Path.GetDirectoryName(exeFile); string fullPath = Path.Combine(exeDir, "..\\..\\pdf\\file.pdf"); FileStream arquivo = new FileStream(fullPath, FileMode.Create); PdfWriter writer = PdfWriter.GetInstance(doc, arquivo); doc.Open(); doc.AddAuthor("Cleiton de Sousa, Raphael Duarte, Douglas Rodrigues, e DEUS, só ele sabe como isso funciona"); doc.AddCreator("Partitura Braille"); doc.AddKeywords("PDF partitura Braille"); doc.AddTitle(partitura.Titulo); Paragraph para = new Paragraph(new Phrase("Partitura: " + partitura.Titulo, fontArial)); doc.Add(para); para = new Paragraph(new Phrase(partitura.TextoPartitura + "=", fontPartitura)); doc.Add(para); para = new Paragraph(new Phrase(" ", fontArial)); doc.Add(para); para = new Paragraph(new Phrase(" ", fontArial)); doc.Add(para); para = new Paragraph(new Phrase(" ", fontArial)); doc.Add(para); para = new Paragraph(new Phrase("Partitura: " + partitura.Titulo, fontBraille)); doc.Add(para); para = new Paragraph(new Phrase(partitura.BraillePartitura, fontBraille)); doc.Add(para); doc.NewPage(); para = new Paragraph(new Phrase("Letra da Partitura: " + partitura.Titulo, fontArial)); doc.Add(para); para = new Paragraph(new Phrase(" ", fontArial)); doc.Add(para); para = new Paragraph(new Phrase(partitura.LetraPartitura, fontArial2)); doc.Add(para); para = new Paragraph(new Phrase(" ", fontArial)); doc.Add(para); para = new Paragraph(new Phrase(" ", fontArial)); doc.Add(para); para = new Paragraph(new Phrase(" ", fontArial)); doc.Add(para); para = new Paragraph(new Phrase(" ", fontArial)); doc.Add(para); para = new Paragraph(new Phrase("Letra da Partitura em Braille: " + partitura.Titulo, fontBraille)); doc.Add(para); para = new Paragraph(new Phrase(partitura.LetraPartitura, fontBraille)); doc.Add(para); doc.Close(); arquivo.Close(); System.Diagnostics.Process.Start(fullPath); }