PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed Apr 25, 2018 1:07 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Mar 09, 2018 2:47 pm 
Offline

Joined: Fri Mar 09, 2018 12:51 pm
Posts: 2
Hi, I'm new in MigraDoc and I'm trying to create a PDF and to add a footer.
Following this example I created my Document which includes a table. Now the idea was to add a footer, I found this example, but I'm not able to combine the two things.
My problem is that by creating my table the class Document is used, for the footer a PDFDocument is required instead.
Any help?
Thanks.


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 09, 2018 3:03 pm 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 358
Location: CCAA
Hi!

Document is MigraDoc, PdfDocument is PDFsharp.

The MigraDoc samples are here:
http://pdfsharp.net/wiki/MigraDocSamples.ashx

The Invoice sample uses a footer:
http://pdfsharp.net/wiki/Invoice-sample.ashx

So does this sample:
http://pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 12, 2018 7:52 am 
Offline

Joined: Fri Mar 09, 2018 12:51 pm
Posts: 2
I ended up with this code, it works:

Code:
public static void Buil(Sitzung sitzung)
{
   Document document = BuildDocument(sitzung);

   DefineStyles(document);

   PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always)
   {
      Document = document
   };
   renderer.RenderDocument();

   PdfDocument pdfDocument = renderer.PdfDocument;
   PdfPage page = pdfDocument.Pages[0];
   AddFooter(page, userName);

   DocumentRenderer docRenderer = new DocumentRenderer(document);
   docRenderer.PrepareDocument();

   MemoryStream stream = new MemoryStream();
   pdfDocument.Save(stream);
}



public static void AddFooter(PdfPage page, string userName)
{
   XGraphics gfx = XGraphics.FromPdfPage(page);
   XRect rect = new XRect(new XPoint(), gfx.PageSize);
   rect.Inflate(-15, -20);

   XFont font = new XFont(Frutiger, 7, XFontStyle.Italic);
   XStringFormat format = new XStringFormat
   {
      Alignment = XStringAlignment.Near,
      LineAlignment = XLineAlignment.Far
   };
   gfx.DrawString($"Ausdruck von {userName} um {DateTime.Now.ToString("dd.MM.yyyy HH:mm")}", font, XBrushes.Black, rect, format);
}


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group