public ReadOnlyCollection<double> CompareImageFromPdf(string path, string testImage) { List<double> match = new List<double>(); List<System.Drawing.Image> ImgList = new List<System.Drawing.Image>(); ImgList = GetImages(path); ImgList.ForEach(img => img.Save("Image_" + Guid.NewGuid() + ".bmp")); ImgList.ForEach(img => match.Add(ImageTest(testImage, img))); return match.AsReadOnly(); }
private static string BodyTabelaComissao(List<Pagamento> listaPagamento) { var tbody = new StringBuilder(); listaPagamento.ForEach(p => tbody.AppendFormat(" <tr><td>{0}</th><td>{1}</th><td>{2}</th><td>{3}</th></tr>" ,p.Contrato.Cliente.Nome ,p.ValorPago ,p.ValorPago - ((p.ValorPago * p.Contrato.Vendedor.Comissao) / 100) ,(p.ValorPago * p.Contrato.Vendedor.Comissao) / 100) ); return tbody.ToString(); }
public HttpResponseMessage Invoice(string date, string number, string total, string emails, string clientNumber, string matter, string description) { byte[] pdf = null; using (var ms = new MemoryStream()) { using (var doc = new Document()) { doc.SetMargins(60, 60, 40, 40); PdfWriter.GetInstance(doc, ms); doc.Open(); #region Header var table = new PdfPTable(4) { WidthPercentage = 100 }; var colSizes = new List<float> { 120f, 130f, 140f }; colSizes.Add(doc.PageSize.Width - colSizes.Sum()); table.SetWidths(colSizes.ToArray()); table.AddCell(new PdfPCell { Image = Image.GetInstance(HttpContext.Current.Request.MapPath("~\\App_Data\\Logo.jpg")), BorderColorRight = BaseColor.WHITE, Rowspan = 3 }); table.AddCell(new PdfPCell(CreatePhrase("950 E. State Hwy 114\nSuite 160\nSouthlake, TX 76092")) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Rowspan = 3 }); table.AddCell(CreateCell("Invoice Date", Element.ALIGN_RIGHT)); table.AddCell(CreateCell(date, Element.ALIGN_CENTER)); table.AddCell(CreateCell("Invoice Number", Element.ALIGN_RIGHT)); table.AddCell(CreateCell(number, Element.ALIGN_CENTER)); table.AddCell(CreateCell("Invoice Total", Element.ALIGN_RIGHT)); table.AddCell(CreateCell(total, Element.ALIGN_CENTER)); doc.Add(table); #endregion #region Emails doc.Add(CreatePhrase(" ")); table = new PdfPTable(1) { WidthPercentage = 100 }; table.AddCell(CreateCell($"Invoice for {emails}", Element.ALIGN_CENTER)); doc.Add(table); #endregion #region Matters doc.Add(CreatePhrase(" ")); table = new PdfPTable(4) { WidthPercentage = 100 }; colSizes = new List<float> { 120f, 130f, 80f }; colSizes.Insert(2, doc.PageSize.Width - colSizes.Sum()); table.SetWidths(colSizes.ToArray()); var columns = new List<string> { "Client", "Matter", "Description", "Amount" }; columns.ForEach(c => { var cell = new PdfPCell { Phrase = CreatePhrase(c, headerFont), HorizontalAlignment = Element.ALIGN_CENTER }; table.AddCell(cell); }); columns = new List<string> { clientNumber, matter, description, total }; columns.ForEach(c => { table.AddCell(CreateCell(c, Element.ALIGN_CENTER)); }); doc.Add(table); #endregion #region Footer doc.Add(CreatePhrase("\nIf you have any questions, please contact us at [email protected].\n")); doc.Add(CreatePhrase("\nThank you for using SyncIDS.com!")); #endregion } pdf = ms.ToArray(); } var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new ByteArrayContent(pdf); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); return response; }
//99% of credit goes to this person: http://stackoverflow.com/a/20491695 public static bool Merge(List<string> fullFilePaths, string saveAs) { try { using (FileStream stream = new FileStream(saveAs, FileMode.Create)) using (Document doc = new Document()) using (PdfCopy pdf = new PdfCopy(doc, stream)) { doc.Open(); PdfReader reader = null; PdfImportedPage page = null; fullFilePaths.ForEach(file => { using (reader = new PdfReader(file)) { for (int i = 0; i < reader.NumberOfPages; i++) { page = pdf.GetImportedPage(reader, i + 1); pdf.AddPage(page); } pdf.FreeReader(reader); } }); } } catch(Exception ex) { Console.WriteLine(ex.Message); return false; } return true; }
public static bool Merge(List<PDFFiles> InFiles, string OutFile) { try { for(int i=0; i<InFiles.Count; i++) { PdfReader reader = null; reader = new PdfReader(InFiles[i].filePath); if (!reader.IsOpenedWithFullPermissions) { string newUnlockedFile = unlockPDF(InFiles[i].filePath); //throw new System.IO.FileLoadException("Cannot merge because \"" + file.fileName + "\" is Locked for editing"); InFiles.Remove(InFiles[i]); InFiles.Insert(i, new PDFFiles(newUnlockedFile)); } } } catch (FileNotFoundException ex) { throw ex; } catch (System.IO.FileLoadException) { throw; } catch { return false; } try { using (FileStream stream = new FileStream(OutFile, FileMode.Create)) using (Document doc = new Document(PageSize.A4)) using (PdfCopy pdf = new PdfCopy(doc, stream)) { doc.Open(); PdfReader reader = null; PdfImportedPage page = null; //fixed typo InFiles.ForEach(file => { reader = new PdfReader(file.filePath); for (int i = 0; i < reader.NumberOfPages; i++) { page = pdf.GetImportedPage(reader, i + 1); //doc.SetPageSize(page.Width <= page.Height ? PageSize.A4 : PageSize.A4.Rotate()); pdf.AddPage(page); } pdf.FreeReader(reader); reader.Close(); }); } } catch { return false; } ScaleToA4(OutFile, OutFile); return true; }