public void CreatePdf(IEnumerable <int> articleRevueIds, Stream memoryStream) { var articlesRevues = _uow.ArticlesRevue.Get(b => articleRevueIds.Contains(b.Id), o => o.OrderBy(ar => ar.PeriodePublication).ThenBy(ar => ar.NumeroRevue.HasValue ? ar.NumeroRevue.Value : 0).ThenBy(ar => ar.PremierePage), b => b.Revue.RevueMere); var pdfManager = _pdfManager.Create(memoryStream); PdfTableOfContent toc = new PdfTableOfContent("Sommaire"); var totalPage = 0; foreach (var articleRevue in articlesRevues) { toc.AddContent(String.Format("{0} ({1})", articleRevue.Titre, articleRevue.ShortTag), totalPage + 1); var documentToMerge = articleRevue.GetDocuments(); foreach (var doc in documentToMerge) { totalPage += pdfManager.AddPdf(doc.NomCompletFichier, doc.Tag, _fileMissingMessage, articleRevue.PagesReferences.ListePages.ToList(), true); } } toc.DecalePage(pdfManager.ComputeTableOfContent(toc)); pdfManager.AddTableOfContent(toc); pdfManager.Close(); }
public void CreatePdf(IEnumerable <int> acteIds, Stream memoryStream) { var actes = _uow.Actes.Get(b => acteIds.Contains(b.Id), null, b => b.ParoisseRegistre).OrderByExtList <Acte, int>(acteIds.ToList(), b => b.Id); var pdfManager = _pdfManager.Create(memoryStream); PdfTableOfContent toc = new PdfTableOfContent("Sommaire"); var totalPage = 0; foreach (var acte in actes) { toc.AddContent(String.Format("{0} ({1})", acte.ShortTag, acte.RegistreParoissial), totalPage + 1); var documentToMerge = acte.GetDocuments(); foreach (var doc in documentToMerge) { totalPage += pdfManager.AddPdf(doc.NomCompletFichier, doc.Tag, _fileMissingMessage, acte.PagesReferences.ListePages.ToList()); } } toc.DecalePage(pdfManager.ComputeTableOfContent(toc)); pdfManager.AddTableOfContent(toc); pdfManager.Close(); }
private int CreateTableOfContent(PdfTableOfContent toc, PdfWriter writer, Document doc, bool reorderPage) { var numberOfPageBeforeInsertTOC = writer.PageNumber; doc.SetPageSize(PageSize.A4); doc.SetMargins(36, 36, 36, 36); doc.NewPage(); Paragraph p; PdfAction action = new PdfAction(PdfAction.FIRSTPAGE); PdfAnnotation link; if (!String.IsNullOrEmpty(toc.TitreDocument)) { p = new Paragraph(toc.TitreDocument, fontTitrePrincipal); p.Alignment = Element.ALIGN_CENTER; doc.Add(p); // Un espace ? peut mieux faire peut etre... doc.Add(new Paragraph(" ")); } foreach (var content in toc.Contents) { // action = PdfAction.GotoLocalPage("p" + content.RealPage, new PdfDestination(PdfDestination.XYZ, 0f, PageSize.A4.Top, 0f), writer); action = PdfAction.GotoLocalPage("p" + content.RealPage, false); p = new Paragraph(content.Titre, fontText); p.Add(new Chunk(new DottedLineSeparator())); p.Add(new Chunk(content.PageNumber.ToString(), fontText)); float topY = writer.GetVerticalPosition(false); doc.Add(p); float bottomYY = writer.GetVerticalPosition(false); if (bottomYY > topY) // on a changé de page { topY = _docContent.Top; } link = new PdfAnnotation(writer, doc.Left, bottomYY, doc.Right, topY, action); writer.AddAnnotation(link); } var numberOfPage = writer.PageNumber; if (reorderPage) { doc.NewPage(); var reorderArray = Enumerable.Range(numberOfPageBeforeInsertTOC + 1, numberOfPage - numberOfPageBeforeInsertTOC) .Concat(Enumerable.Range(1, numberOfPageBeforeInsertTOC)).ToArray(); writer.ReorderPages(reorderArray); } return(numberOfPage); }
public int ComputeTableOfContent(PdfTableOfContent toc) { AssertGoodInitialization(); var numberOfPage = 0; using (MemoryStream stream = new MemoryStream()) { var doc = new Document(pageSize); var writer = PdfWriter.GetInstance(doc, stream); doc.Open(); numberOfPage = CreateTableOfContent(toc, writer, doc, false); } return(numberOfPage); }
public void CreatePdf(IEnumerable <int> pretreIds, Stream memoryStream) { var pretres = _uow.Pretres.Get(b => pretreIds.Contains(b.Id), null, b => b.Documents, b => b.Photos, b => b.ArticlesRevue.Select(ar => ar.Revue), b => b.FonctionsLieu.Select(fl => fl.Fonction), b => b.FonctionsLieu.Select(fl => fl.Lieu.TypeLieu)).OrderByExtList <Pretre, int>(pretreIds.ToList(), b => b.Id); var pdfManager = _pdfManager.Create(memoryStream); PdfTableOfContent toc = new PdfTableOfContent("Sommaire"); var totalPage = 0; foreach (var pretre in pretres) { toc.AddContent(pretre.NomComplet, totalPage + 1); totalPage += WritePretreToPdf(pdfManager, pretre); } toc.DecalePage(pdfManager.ComputeTableOfContent(toc)); pdfManager.AddTableOfContent(toc); pdfManager.Close(); }
public int AddTableOfContent(PdfTableOfContent toc) { AssertGoodInitialization(); return(CreateTableOfContent(toc, _writerContent, _docContent, true)); }