public static void MergeFiles(string destinationFile, List<string> files, bool removeMergedFiles) { try { var f = 0; var reader = new PdfReader(files.First()); var numberOfPages = reader.NumberOfPages; var document = new Document(reader.GetPageSizeWithRotation(1)); var writer = PdfWriter.GetInstance(document, new FileStream(destinationFile, FileMode.Create)); document.Open(); var content = writer.DirectContent; while (f < files.Count) { var i = 0; while (i < numberOfPages) { i++; document.SetPageSize(reader.GetPageSizeWithRotation(i)); document.NewPage(); var page = writer.GetImportedPage(reader, i); var rotation = reader.GetPageRotation(i); if (rotation == 90 || rotation == 270) content.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height); else content.AddTemplate(page, 1f, 0, 0, 1f, 0, 0); } f++; if (f < files.Count) { reader = new PdfReader(files[f]); numberOfPages = reader.NumberOfPages; } } document.Close(); if (removeMergedFiles) { DeleteMergedFiles(files); } } catch (Exception e) { var strOb = e.Message; } }
public void GerarPdf(List<Pagamento> listaPagamento) { var doc = new Document(); PdfWriter.GetInstance(doc, new FileStream(@"c:\temp\teste.pdf", FileMode.Create)); doc.Open(); var pagamento = listaPagamento.First(); var corpoEmail = CorpoEmail(); corpoEmail = corpoEmail.Replace("[mes]", pagamento.DataPagamento.ToString("Y")); corpoEmail = corpoEmail.Replace("[canal]", pagamento.Contrato.Vendedor.Nome); corpoEmail = corpoEmail.Replace("[body]", BodyTabelaComissao(listaPagamento)); corpoEmail = corpoEmail.Replace("[foot]", FooterTabelaComissao(listaPagamento)); var hw = new iTextSharp.text.html.simpleparser.HTMLWorker(doc); hw.Parse(new StringReader(corpoEmail)); doc.Close(); //return corpoEmail; }
public static response_item_type[] FillForm(pdf_stamper_request request,string mapping_root_path,string template_root_path, string output_root_path, DataTable data, string fonts_root_path, bool force_unc) { lock (_lock) { try { List<Item> items_with_path = new List<Item>(); mappings mapping = new mappings(); if (File.Exists(mapping_root_path)) mapping = File.ReadAllText(mapping_root_path).DeserializeXml2<mappings>(); FileInfo mapping_path = new FileInfo(mapping_root_path); /* string fox_helper_path = Path.Combine(mapping_path.DirectoryName, "Fox.txt"); if (!File.Exists(fox_helper_path)) { StringBuilder b = new StringBuilder(); b.Append(@" DIMENSION laArray[30,2] laArray[1,1] = 'Obrazac1' laArray[2,1] = 'Obrazac2' laArray[3,1] = 'Obrazac3' laArray[4,1] = 'Obrazac4' laArray[5,1] = 'Obrazac5' laArray[6,1] = 'Obrazac6' laArray[7,1] = 'Obrazac7' laArray[8,1] = 'Obrazac8' laArray[9,1] = 'Obrazac9' laArray[10,1] ='Obrazac10' laArray[11,1] = 'Obrazac11' laArray[12,1] = 'Obrazac12' laArray[13,1] = 'Obrazac13' laArray[14,1] = 'Obrazac14' laArray[15,1] = 'Obrazac15' laArray[16,1] = 'Obrazac16' laArray[17,1] = 'Obrazac17' laArray[18,1] = 'Obrazac18' laArray[19,1] = 'Obrazac19' laArray[20,1] ='Obrazac20' laArray[21,1] = 'Obrazac21' laArray[22,1] = 'Obrazac22' laArray[23,1] = 'Obrazac23' laArray[24,1] = 'Obrazac24' laArray[25,1] = 'Obrazac25' laArray[26,1] = 'Obrazac26' laArray[27,1] = 'Obrazac27' laArray[28,1] = 'Obrazac28' laArray[29,1] = 'Obrazac29' laArray[30,1] ='Obrazac30' "); int current_index = -1; foreach (var item in mapping.mapping_item) { current_index = Int32.Parse(item.pdf_template.ToString().Replace("Obrazac", "")); string source_document_path = item.file_path.Replace("@root", template_root_path); FileInfo info = new FileInfo(source_document_path); string value = string.Format("laArray[{0},2] = '{1}'", current_index, info.Name.Replace(info.Extension,String.Empty)); b.AppendLine(value); } File.WriteAllText(fox_helper_path,b.ToString()); } */ if (data.Rows.Count == 0) { Logging.Singleton.WriteDebug("There is no data in the provided data table!"); foreach (var template in request.pdf_template_list) { mapping_item_type selected = mapping.mapping_item.Where(p => p.pdf_template == template).First(); string source_document_path = selected.file_path.Replace("@root", template_root_path); items_with_path.Add(new Item() { Path = source_document_path, PdfTemplate = template }); } if (request.merge_output == true) { string merged_document_path = Path.Combine(output_root_path, String.Format("{0}_{1}{2}", "merged", DateTime.Now.ToFileTimeUtc().ToString(), ".pdf")); PdfMerge merge = new PdfMerge(); foreach (var item in items_with_path) { merge.AddDocument(item.Path); } merge.EnablePagination = false; merge.Merge(merged_document_path); string result = Convert.ToBase64String(File.ReadAllBytes(merged_document_path)); return new response_item_type[] { new response_item_type() { pdf_template = template.MergedContent, data = force_unc? string.Empty : result, unc_path=merged_document_path } }; } else { List<response_item_type> items = new List<response_item_type>(); foreach (var item in items_with_path) { var temp = new response_item_type() { pdf_template = item.PdfTemplate, data = force_unc ? string.Empty : Convert.ToBase64String(File.ReadAllBytes(item.Path)), unc_path = item.Path }; items.Add(temp); } return items.ToArray(); } } else { DataRow row = data.Rows[0]; string id_pog = string.Empty; if (data.Columns.Contains("id_pog")) id_pog = row["id_pog"].ToString(); if (request.debug_mode) { foreach (DataColumn column in data.Columns) { Logging.Singleton.WriteDebugFormat("Data column [{0}] has a value [{1}]", column.ToString(), row[column].ToString()); } } foreach (var template in request.pdf_template_list) { mapping_item_type selected = mapping.mapping_item.Where(p => p.pdf_template == template).First(); string source_document_path = selected.file_path.Replace("@root", template_root_path); FileInfo f = new FileInfo(source_document_path); string destination_document_path = Path.Combine(output_root_path, String.Format("{0}_{1}_{2}{3}", id_pog.Replace("/","-").Trim(), f.Name.Replace(f.Extension, ""), DateTime.Now.ToFileTimeUtc().ToString(), f.Extension) ); items_with_path.Add(new Item() { Path = destination_document_path, PdfTemplate = template }); PdfReader reader = new PdfReader(source_document_path); using (PdfStamper stamper = new PdfStamper(reader, new FileStream(destination_document_path, FileMode.Create))) { AcroFields fields = stamper.AcroFields; //Full path to the Unicode Arial file //string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF"); //Create a base font object making sure to specify IDENTITY-H //BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); //Create a specific font object //Font f = new Font(bf, 12, Font.NORMAL); iTextSharp.text.pdf.BaseFont baseFont = iTextSharp.text.pdf.BaseFont.CreateFont(Path.Combine(fonts_root_path,"arial.ttf"),"Windows-1250", true); fields.AddSubstitutionFont(baseFont); if (request.debug_mode) { foreach (var key in fields.Fields.Keys) { Logging.Singleton.WriteDebugFormat("Pdf field [{0}]. Data type [{1}]", key, fields.GetFieldType(key)); } } foreach (var key in fields.Fields.Keys) { var items = selected.mapping.Where(p => p.data_field == key); if (items.Count() == 1) { var item = items.First(); if (item.column_name == UNKNOWN) continue; if (data.Columns.Contains(item.column_name)) { string value = row[item.column_name].ToString(); if (item.field_type == data_field_type.CheckBox) { int int_value = 0; bool boolean_value = false; if(Int32.TryParse(value, out int_value)) { value = int_value == 0? "No" : "Yes"; } else if (Boolean.TryParse(value, out boolean_value)) { value = boolean_value == false? "No" : "Yes"; } else { throw new NotImplementedException(string.Format("Invalid Value [{0}] was provided for Check box type field!", value)); } } fields.SetField(key, value); } else { Logging.Singleton.WriteDebugFormat("Column {0} does not belong to table {1}! Check your mappings for template {2}", item.column_name, data.TableName, template); } } else if (items.Count() == 0) { var current = selected.mapping.ToList(); data_field_type field_type = data_field_type.Text; if (key.Contains("Check")) field_type = data_field_type.CheckBox; else if (key.Contains("Radio")) field_type = data_field_type.RadioButton; current.Add(new mapping_type() { column_name = UNKNOWN, data_field = key, field_type = field_type }); selected.mapping = current.ToArray(); File.WriteAllText(mapping_root_path, mapping.SerializeXml()); } else { throw new NotImplementedException(); } } // flatten form fields and close document if (request.read_only || (request.merge_output && request.pdf_template_list.Length > 1)) { Logging.Singleton.WriteDebugFormat("Form flattening requested... Read only {0}, Merge output {1}, Template list count {2}", request.read_only, request.merge_output, request.pdf_template_list.Length); stamper.FormFlattening = true; } stamper.Close(); } } if (items_with_path.Count() == 1) { string path = items_with_path.First().Path; var bytes = File.ReadAllBytes(path); string result = Convert.ToBase64String(bytes); Logging.Singleton.WriteDebugFormat("Response lenght is {0} bytes", bytes.Length); return new response_item_type[] { new response_item_type() { pdf_template = items_with_path.First().PdfTemplate, data = force_unc ? string.Empty : result, unc_path = path } }; //return new response_item_type[] { new response_item_type() { pdf_template = items_with_path.First().PdfTemplate, data = Convert.ToBase64String(new byte[] {1,2,3,4,5,6,7,8,9}) } }; } else { if (request.merge_output == true) { string merged_document_path = Path.Combine(output_root_path, String.Format("{0}_{1}{2}{3}", id_pog.Replace("/","-").Trim(), "merged", DateTime.Now.ToFileTimeUtc().ToString(), ".pdf")); //List<string> file_names = new List<string>(); //foreach (var item in items_with_path) { // file_names.Add(item.Path); //} //var path = MergePdfForms(file_names, merged_document_path); PdfMerge merge = new PdfMerge(); foreach (var item in items_with_path) { merge.AddDocument(item.Path); } merge.EnablePagination = false; merge.Merge(merged_document_path); //using (FileStream file = new FileStream(merged_document_path, FileMode.Create, System.IO.FileAccess.Write)) { // byte[] bytes = new byte[stream.Length]; // stream.Read(bytes, 0, (int)stream.Length); // file.Write(bytes, 0, bytes.Length); // stream.Close(); //} var bytes = File.ReadAllBytes(merged_document_path); string result = Convert.ToBase64String(bytes); Logging.Singleton.WriteDebugFormat("Response lenght is {0} bytes", bytes.Length); return new response_item_type[] { new response_item_type() { pdf_template = template.MergedContent, data = force_unc ? string.Empty : result, unc_path = merged_document_path } }; } else { List<response_item_type> items = new List<response_item_type>(); foreach (var item in items_with_path) { var bytes = File.ReadAllBytes(item.Path); string result = Convert.ToBase64String(bytes); Logging.Singleton.WriteDebugFormat("Response lenght is {0} bytes", bytes.Length); var temp = new response_item_type() { pdf_template = item.PdfTemplate, data = force_unc ? string.Empty : result, unc_path = item.Path }; //var temp = new response_item_type() { pdf_template = item.PdfTemplate, data = Convert.ToBase64String(new byte[] {1,2,3,4,5,6,7,8,9}) }; items.Add(temp); } return items.ToArray(); } } } } catch (Exception ex) { string message = Logging.CreateExceptionMessage(ex); Logging.Singleton.WriteDebug(message); return null; } } }
/// <summary> /// Merges pdf files from a byte list /// </summary> /// <param name="files">list of files to merge</param> /// <returns>memory stream containing combined pdf</returns> public static string MergePdfForms(List<string> file_names, string output) { if (file_names.Count > 1) { List<byte[]> files = new List<byte[]>(); foreach (string file_name in file_names) { var file = File.ReadAllBytes(file_name); files.Add(file); } string[] names; PdfStamper stamper; MemoryStream msTemp = null; PdfReader pdfTemplate = null; PdfReader pdfFile; Document doc; PdfWriter pCopy; MemoryStream msOutput = new MemoryStream(); pdfFile = new PdfReader(files[0]); doc = new Document(); pCopy = new PdfSmartCopy(doc, msOutput); pCopy.PdfVersion = PdfWriter.VERSION_1_7; doc.Open(); for (int k = 0; k < files.Count; k++) { for (int i = 1; i < pdfFile.NumberOfPages + 1; i++) { msTemp = new MemoryStream(); pdfTemplate = new PdfReader(files[k]); stamper = new PdfStamper(pdfTemplate, msTemp); names = new string[stamper.AcroFields.Fields.Keys.Count]; stamper.AcroFields.Fields.Keys.CopyTo(names, 0); foreach (string name in names) { stamper.AcroFields.RenameField(name, name + "_file" + k.ToString()); } stamper.Close(); pdfFile = new PdfReader(msTemp.ToArray()); ((PdfSmartCopy)pCopy).AddPage(pCopy.GetImportedPage(pdfFile, i)); pCopy.FreeReader(pdfFile); } } FileStream f = new FileStream(output, FileMode.Create); msOutput.WriteTo(f); msOutput.Flush(); f.Flush(); pdfFile.Close(); pCopy.Close(); doc.Close(); msOutput.Close(); f.Close(); return output; } else if (file_names.Count == 1) { File.Copy(file_names.First(), output); return output; } return null; }
private void drawTeamPairs(Document doc, UserShows userShow) { var multiDogClasses = new List<MultiDogClasses>(); var multiDogEntries = new List<MultiDogEntry>(); Shows thisShow = new Shows(userShow.ShowID); User currentUser = new User(userShow.Userid); List<ShowClasses> classList = ShowClasses.GetAllClassesForShow(userShow.ShowID).Where(sc => sc.Part == 0).ToList(); multiDogClasses = TeamPairsManager.GetTeamPairClasses(userShow.ShowID); multiDogEntries = TeamPairsManager.GetTeamPairs(userShow.ShowID, userShow.Userid, multiDogClasses); doc.NewPage(); var container = new PdfPTable(new float[] { 200, 200 }); PdfPTable teamPairsTable = new PdfPTable(new float[] { 200, 200 });; int lastClassId = 0; int teamCnt = 0 ; PdfPCell cell; foreach (var entry in multiDogEntries) { if (lastClassId != entry.ClassId) { if (lastClassId != 0) { if (teamCnt % 2 > 0) { cell = new PdfPCell(new Phrase(new Chunk("", dogDetailsInClass))); cell.BorderWidth = 0; container.AddCell(cell); } teamCnt = 0; } lastClassId = entry.ClassId; var classDetails = multiDogClasses.First(x => x.ClassId == entry.ClassId); teamPairsTable = new PdfPTable(new float[] { 200, 200 }); cell = new PdfPCell(new Phrase(new Chunk(string.Format("Class No:{0} - {1}", classDetails.ClassNo, classDetails.ClassName), headerFont))); cell.Colspan = 2; cell.BorderWidth = 0; cell.FixedHeight = 25f; cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT; teamPairsTable.AddCell(cell); cell = new PdfPCell(teamPairsTable); cell.Colspan = 2; cell.BorderWidth = 0; container.AddCell(cell); } teamPairsTable = new PdfPTable(new float[] { 200, 200 }); var teamPairsHeader = new PdfPTable(new float[] { 200, 200, 100 }); var p = new Paragraph(); p.Add(new Phrase(new Chunk("Captain", inClassFont))); p.Add(new Phrase(Chunk.NEWLINE)); p.Add(new Phrase(new Chunk(entry.TeamDetails.Captain.Replace("'", "'"), fontBold))); cell = new PdfPCell(p); cell.BorderWidth = 0; cell.FixedHeight = 30; cell.BorderWidthBottom = 2; teamPairsHeader.AddCell(cell); p = new Paragraph(); p.Add(new Phrase(new Chunk("Team Name", inClassFont))); p.Add(new Phrase(Chunk.NEWLINE)); p.Add(new Phrase(new Chunk(entry.TeamDetails.TeamName.Replace("'", "'"), fontBold))); cell = new PdfPCell(p); cell.BorderWidth = 0; cell.BorderWidthBottom = 2; cell.FixedHeight = 30; teamPairsHeader.AddCell(cell); p = new Paragraph(); p.Add(new Phrase(new Chunk(string.Format(" RO: {0}", entry.RO), inClassFontBold))); cell = new PdfPCell(p); cell.BorderWidth = 0; cell.BorderWidthBottom = 2; cell.BorderWidthLeft = 2; cell.FixedHeight = 30; teamPairsHeader.AddCell(cell); cell = new PdfPCell(teamPairsHeader); cell.Colspan = 2; cell.BorderWidth = 0; teamPairsTable.AddCell(cell); cell = new PdfPCell(new Phrase(new Chunk("Members", dogDetailsInClass))); cell.Colspan = 2; cell.BorderWidth = 0; cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT; teamPairsTable.AddCell(cell); int memcnt = 0; foreach (var members in entry.Members) { if (memcnt == entry.DogCount) { cell = new PdfPCell(); cell.Colspan = 2; cell.BorderWidth = 0; cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT; teamPairsTable.AddCell(cell); cell = new PdfPCell(new Phrase(new Chunk("Reserves", dogDetailsInClass))); cell.Colspan = 2; cell.BorderWidth = 0; cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT; teamPairsTable.AddCell(cell); } cell = new PdfPCell(new Phrase(new Chunk(members.HandlerName.Replace("'","'"), font))); cell.BorderWidth = 0; cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT; teamPairsTable.AddCell(cell); cell = new PdfPCell(new Phrase(new Chunk(members.DogName.Replace("'", "'"), font))); cell.BorderWidth = 0; cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT; teamPairsTable.AddCell(cell); memcnt++; } container.AddCell(new PdfPCell(teamPairsTable)); teamCnt++; } if (teamCnt % 2 > 0) { cell = new PdfPCell(new Phrase(new Chunk("", dogDetailsInClass))); cell.BorderWidth = 0; container.AddCell(cell); } doc.Add(container); }
private PdfPCell AddDogDetails(Dogs d, List<DogClasses> dcList, Color altColor, bool topBorder ) { Paragraph p = new Paragraph(); Phrase ph = new Phrase(); ph.Add(new Chunk(d.KCName, normalFont)); ph.Add(Chunk.NEWLINE); var doginfo = d.KCNumber; if (!string.IsNullOrEmpty(d.DoB)) { doginfo += ","; doginfo += d.DoB; } ph.Add(new Chunk(doginfo, normalFont)); ph.Add(Chunk.NEWLINE); doginfo = d.Breed; if (doginfo.Length > 0) doginfo += ","; doginfo += "Grade " + Dogs.GetDogGrade(d.Grade); ph.Add(new Chunk(doginfo, normalFont)); ph.Add(Chunk.NEWLINE); doginfo = ""; doginfo += Dogs.GetDogHeight(d.Height); doginfo += ","; doginfo += Dogs.GetDogSexType(d.Sex); if (dcList.Any() && dcList.First().Lho == 1) { doginfo += ",LHO"; } ph.Add(new Chunk(doginfo, normalFont)); ph.Add(Chunk.NEWLINE); var cell = new PdfPCell(ph); cell.BorderWidth = 0; cell.BackgroundColor = altColor; if (topBorder) { cell.BorderColorTop = Color.BLACK; cell.BorderWidthTop = 1; } return cell; }
private void ScoreBoardColumnHeaders(ShowClasses showClass, PdfPTable callingListTbl, List<CallingListDto> callingList, float[] colWidths) { if (TeamPairsManager.isMultiDog(showClass.EntryType)) { callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("RO", headerHFont))) { BorderWidth = 0 }); callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Team Name", headerHFont))) { BorderWidth = 0, Colspan = 2 }); } else { if (showClass.Lho == 1 || showClass.Lho == 2) { if (callingList.Any()) { var item = callingList.First(); var cnt = callingList.Count(x => x.Lho == item.Lho); var title = $"{(item.Lho == 0 ? "Full Height " : "Lower Height")} ({cnt})"; callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk(title, headerHFont))) { BorderWidth = 0, Colspan = colWidths.Length, BackgroundColor = Color.LIGHT_GRAY, HorizontalAlignment = Element.ALIGN_CENTER, FixedHeight = 20, BorderColorBottom = Color.BLACK, BorderWidthBottom = 2 }); } else { var title = $"Dont Know (9999)"; callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk(title, headerHFont))) { BorderWidth = 0, Colspan = colWidths.Length, BackgroundColor = Color.LIGHT_GRAY, HorizontalAlignment = Element.ALIGN_CENTER, FixedHeight = 20, BorderColorBottom = Color.BLACK, BorderWidthBottom = 2 }); } } callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("RO", headerHFont))) { BorderWidth = 0 }); callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Ring No", headerHFont))) {BorderWidth = 0}); callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Handler", headerHFont))) { BorderWidth = 0 }); callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Dog Name", headerHFont))) { BorderWidth = 0 }); } callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Clears", headerHFont))) { BorderWidth = 0 }); callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Faults", headerHFont))) { BorderWidth = 0 }); callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Time", headerHFont))) { BorderWidth = 0 }); }
private void BuildPDF(Dictionary<string, ISPage> pageMap, string baseRoom, Dictionary<string, int> chapterPageMap, bool fakeRun) { if (fakeRun) { ISPageHtmlParser.BuildAllISPages(pageMap, baseRoom, filePath).Wait(); } //now that we have all the pages, we'll have to clean them up and decide on pages Dictionary<string, int> ISPageToPhysicalPageMap = new Dictionary<string, int>(); int currentPage = 1; int currentChapter = 1; Random r = new Random(123456); List<string> pagesLeft = new List<string>(pageMap.Count); foreach (string x in pageMap.Keys) { pagesLeft.Add(x); } using (MemoryStream memStream = new MemoryStream()) { Document pdfDoc = new Document(); iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, memStream); HeaderFooter evnt = new HeaderFooter(); if (fakeRun) { evnt.pageByTitle = chapterPageMap; } else { evnt.pageByTitle = new Dictionary<string, int>(); } if (!fakeRun) { writer.PageEvent = evnt; } pdfDoc.Open(); pdfDoc.AddAuthor("test"); pdfDoc.AddTitle("testTitle"); while (pagesLeft.Any()) { string pageToAdd = pagesLeft.First(); if (currentPage > 1) { pagesLeft.Skip(r.Next(pagesLeft.Count)).First(); } pagesLeft.Remove(pageToAdd); if (fakeRun) { chapterPageMap.Add(pageToAdd, writer.PageNumber + 1); } ISPageToPhysicalPageMap.Add(pageToAdd, currentPage); var chapter = GetPDFPage(pageMap[pageToAdd], int.Parse(pageToAdd), chapterPageMap); pdfDoc.Add(chapter); int actualPageLength = fakeRun ? 1 : chapterPageMap[pageToAdd]; currentPage += actualPageLength; currentChapter++; } pdfDoc.Close(); writer.Close(); if (!fakeRun) { File.WriteAllBytes(Path.Combine(filePath, fileName), memStream.GetBuffer()); } } }
public static string generarRecibo(System.Drawing.Image qr, List<CatalogoDeudores.DetalleDeuda> detalles, unidad uni, titular tit, double descuento = 0) { calibri = BaseFont.CreateFont(IncludesPath + "calibri.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); calibri8N = new iTextSharp.text.Font(calibri, 8, iTextSharp.text.Font.NORMAL); calibri8B = new iTextSharp.text.Font(calibri, 8, iTextSharp.text.Font.BOLD); calibri9N = new iTextSharp.text.Font(calibri, 9, iTextSharp.text.Font.NORMAL); calibri9B = new iTextSharp.text.Font(calibri, 9, iTextSharp.text.Font.BOLD); calibri12N = new iTextSharp.text.Font(calibri, 10, iTextSharp.text.Font.NORMAL); calibri12B = new iTextSharp.text.Font(calibri, 10, iTextSharp.text.Font.BOLD); calibri11N = new iTextSharp.text.Font(calibri, 10, iTextSharp.text.Font.NORMAL); calibri11B = new iTextSharp.text.Font(calibri, 10, iTextSharp.text.Font.BOLD); Document doc = new Document(PageSize.A4, milimetroToPoint(12), milimetroToPoint(12), milimetroToPoint(7), 0f); bool exists = System.IO.Directory.Exists(Ruta + "Recibos"); if (!exists) System.IO.Directory.CreateDirectory(Ruta + "Recibos"); string nombre = detalles.First().Edificio + " " + detalles.First().Unidad + " " + DateTime.Now.ToShortDateString().Replace("/", "-"); var output = new FileStream(Ruta + @"Recibos\" + nombre + ".pdf", FileMode.Create); var writer = PdfWriter.GetInstance(doc, output); doc.Open(); addEncabezado(doc, qr); addConceptos(doc, detalles, uni, tit, descuento); doc.Add(new Paragraph(10, " ")); addFirmaSello(doc); doc.Close(); return Ruta + @"Recibos\" + nombre + ".pdf"; }
public static string generarInformeUnidadesEdificio(List<edificio> edificios) { if (edificios.Count == 0) return ""; List<EdificiosUnidadesCoeficientes> edificiosUnidadesCoef = new List<EdificiosUnidadesCoeficientes>(); foreach (var e in edificios) { EdificiosUnidadesCoeficientes euc = new EdificiosUnidadesCoeficientes(); List<unidad> unidades = CatalogoUnidades.getAllUnidadesConTitular(e); List<Coeficientes> coeficientes = CatalogoExpensas.getUnidadesCoeficientes(e); List<sector> sectores = CatalogoSectores.getAllSectores(e); var query = (from u in unidades join c in coeficientes on u.id_unidad equals c.Unidad select new { u.dir_edificio, u.id_unidad, u.titular.nombre, c.Rubro1, c.Rubro2, c.Rubro3, c.Rubro4, c.Rubro5 }).ToList(); List<UnidadCoeficienteTitular> unidadesConCoeficientesYTitiular = new List<UnidadCoeficienteTitular>(); foreach (var item in query) { UnidadCoeficienteTitular uct = new UnidadCoeficienteTitular(); uct.Titular = item.nombre; uct.Unidad = item.id_unidad; uct.sectoresCoef = new List<SectorCoeficiente>(); foreach (var s in sectores) { SectorCoeficiente sc = new SectorCoeficiente(); sc.Nombre = s.descripcion; switch (s.idsector) { case 1: sc.Valor = item.Rubro1.ToString("n2"); break; case 2: sc.Valor = item.Rubro2.ToString("n2"); break; case 3: sc.Valor = item.Rubro3.ToString("n2"); break; case 4: sc.Valor = item.Rubro4.ToString("n2"); break; case 5: sc.Valor = item.Rubro5.ToString("n2"); break; } uct.sectoresCoef.Add(sc); } unidadesConCoeficientesYTitiular.Add(uct); euc.Edificio = e.direccion; euc.unidadesCoeficientes = unidadesConCoeficientesYTitiular; } edificiosUnidadesCoef.Add(euc); } calibri = BaseFont.CreateFont(IncludesPath + "calibri.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); calibri8N = new Font(calibri, 8, Font.NORMAL); calibri8B = new Font(calibri, 8, Font.BOLD); calibri9N = new Font(calibri, 9, Font.NORMAL); calibri9B = new Font(calibri, 9, Font.BOLD); calibri12N = new Font(calibri, 10, Font.NORMAL); calibri12B = new Font(calibri, 10, Font.BOLD); calibri11N = new Font(calibri, 10, Font.NORMAL); calibri11B = new Font(calibri, 10, Font.BOLD); foreach (var eu in edificiosUnidadesCoef) { Document doc = new Document(PageSize.A4, milimetroToPoint(12), milimetroToPoint(12), milimetroToPoint(7), 0f); Directory.CreateDirectory(Ruta + "Listados unidades"); var output = new FileStream(Ruta + @"Listados unidades\\" + eu.Edificio + ".pdf", FileMode.Create); var writer = PdfWriter.GetInstance(doc, output); doc.Open(); PdfPTable t = new PdfPTable(8); t.WidthPercentage = 85; float[] widths = new float[] { 45f, 90f, 45f, 55f, 45f, 45f, 45f, 45f }; t.SetWidths(widths); Paragraph p; addEncabezadoSinQR(doc, eu.Edificio, DateTime.Now.Month + "/" + DateTime.Now.Year); //p = new Paragraph(10, "Consorcio: " + eu.Edificio, calibri9B); //doc.Add(p); //addEncabezado(doc, eu.Edificio, DateTime.Now.Month + "/" + DateTime.Now.Year); p = new Paragraph(10, " ", calibri9B); doc.Add(p); int leading = 9; PdfPCell c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Unidad", calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Titular", calibri8B); p.Alignment = Element.ALIGN_LEFT; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Generales", calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Departamentos", calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Local", calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Cocheras", calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Sum", calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthBottom = 0.1f; p = new Paragraph(leading, "Bauleras", calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); Double gen = 0, dep = 0, coch = 0, loc = 0, baul = 0, su = 0; foreach (var u in eu.unidadesCoeficientes) { String generales = u.sectoresCoef.Where(x => x.Nombre == "Generales").Select(x => x.Valor).SingleOrDefault(); if (generales == null) generales = " "; String departamentos = u.sectoresCoef.Where(x => x.Nombre == "Departamentos").Select(x => x.Valor).SingleOrDefault(); if (departamentos == null) departamentos = " "; String cocheras = u.sectoresCoef.Where(x => x.Nombre == "Cocheras").Select(x => x.Valor).SingleOrDefault(); if (cocheras == null) cocheras = " "; String locales = u.sectoresCoef.Where(x => x.Nombre == "Locales").Select(x => x.Valor).SingleOrDefault(); if (locales == null) locales = " "; String bauleras = u.sectoresCoef.Where(x => x.Nombre == "Bauleras").Select(x => x.Valor).SingleOrDefault(); if (bauleras == null) bauleras = " "; String sum = u.sectoresCoef.Where(x => x.Nombre == "SUM").Select(x => x.Valor).SingleOrDefault(); if (sum == null) sum = " "; if (departamentos != " ") dep += double.Parse(departamentos); if (generales != " ") gen += double.Parse(generales); if (cocheras != " ") coch += double.Parse(cocheras); if (locales != " ") loc += double.Parse(locales); if (bauleras != " ") baul += double.Parse(bauleras); if (sum != " ") su += double.Parse(sum); c = new PdfPCell(); c.Border = 0; p = new Paragraph(leading, u.Unidad, calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; p = new Paragraph(leading, u.Titular, calibri8N); p.Alignment = Element.ALIGN_LEFT; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; p = new Paragraph(leading, generales, calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; p = new Paragraph(leading, departamentos, calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; p = new Paragraph(leading, locales, calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; p = new Paragraph(leading, cocheras, calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; p = new Paragraph(leading, sum, calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; p = new Paragraph(leading, bauleras, calibri8N); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); } c = new PdfPCell(); c.Border = 0; p = new Paragraph(1, " ", calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); t.AddCell(c); t.AddCell(c); t.AddCell(c); t.AddCell(c); t.AddCell(c); t.AddCell(c); t.AddCell(c); leading = 7; c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0.1F; p = new Paragraph(leading, "Totales", calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0.1F; p = new Paragraph(leading, " ", calibri8B); p.Alignment = Element.ALIGN_LEFT; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0.1F; p = new Paragraph(leading, gen.ToString("n2"), calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0.1F; p = new Paragraph(leading, dep.ToString("n2"), calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0.1F; p = new Paragraph(leading, loc.ToString("n2"), calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0.1F; p = new Paragraph(leading, coch.ToString("n2"), calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0.1F; p = new Paragraph(leading, su.ToString("n2"), calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); c = new PdfPCell(); c.Border = 0; c.BorderWidthTop = 0.1F; p = new Paragraph(leading, baul.ToString("n2"), calibri8B); p.Alignment = Element.ALIGN_CENTER; c.AddElement(p); t.AddCell(c); doc.Add(t); doc.Close(); } return Ruta + @"Listados unidades\\" + edificiosUnidadesCoef.First().Edificio + ".pdf"; }
public static string emitirRecibo(Bitmap qr, List<CatalogoDeudores.DetalleDeuda> detallesACobrar, Double descuento = 0) { unidad u = new unidad(); u.id_unidad = detallesACobrar.First().Unidad; u.dir_edificio = detallesACobrar.First().Edificio; u = CatalogoUnidades.getUnidad(u); return ControladorInformes.generarRecibo(qr, detallesACobrar, u, u.titular, descuento); }
private int getByeCount(int competitorCount) { /*3 = 1 4 = 0 5 = 3 6 = 2 7 = 1 8 = 0 9 = 7 10 = 6 11 = 5 12 = 4 13 = 3 14 = 2 15 = 1 16 = 0 17 = 15 18 = 14*/ if (competitorCount > 2) { List<int> power2 = new List<int>(); power2.Add(2); power2.Add(4); power2.Add(8); power2.Add(16); power2.Add(32); power2.Add(64); power2.Add(128); return power2.First(m => m >= competitorCount) - competitorCount; } else { return 0; } }
private void FillTable(PdfPTable pdfTable, List<StoreReport> allReports) { var mainHeaderCell = GetCustomizedCell("Aggregated Sales Report", 1, TABLE_COLUMNS, 15); pdfTable.AddCell(mainHeaderCell); mainHeaderCell.Padding = 0f; var currentDate = allReports.First().Date; SetHeadersContent(pdfTable, currentDate); decimal currentSum = 0; decimal grandTotalSum = 0; var isDateChanged = false; foreach (var monthReport in allReports) { if (isDateChanged)//monthReport.Date != currentDate) { SetHeadersContent(pdfTable, monthReport.Date); isDateChanged = false; } foreach (var product in monthReport.Products) { AddProductInfo(product, pdfTable); } currentSum += monthReport.TotalSum; grandTotalSum += monthReport.TotalSum; if (!monthReport.Date.Equals(currentDate))// || monthReport.Equals(allReports.First())) { SetTotalSumRow(pdfTable, currentSum, monthReport); currentDate = monthReport.Date; currentSum = 0; isDateChanged = true; } } SetTotalSumRow(pdfTable, currentSum, allReports.Last()); SetGrandTotalSumRow(pdfTable, grandTotalSum); }