PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 11:15 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Sat Dec 05, 2015 8:07 pm 
Offline

Joined: Sat Dec 05, 2015 7:57 pm
Posts: 3
Hi,

I would like to add or modify the header and the footer of an existing pdf document.

I'm only able to add a header and a footer to a new pdf document using migradoc.

Is it a way to add a header to an existing pdf document?

Thanks

Welby


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 05, 2015 10:55 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
Hi, Welby,

you can add header and footer using PDFsharp.

You can use MigraDoc to create a document with just header and footer and then use PDFsharp to merge the new document with the old document.

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


Top
 Profile  
Reply with quote  
PostPosted: Sun Dec 06, 2015 9:39 am 
Offline

Joined: Sat Dec 05, 2015 7:57 pm
Posts: 3
Hi Thomas

Do you have an example using pdfsharp?
With pdfsharp I m only able to open an existing pdf but not add an header.
Thanks
Welby


Top
 Profile  
Reply with quote  
PostPosted: Sun Dec 06, 2015 4:40 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
welby wrote:
Do you have an example using pdfsharp?
One example that draws text:
http://pdfsharp.net/wiki/HelloWorld-sample.ashx

One example that uses MigraDoc and PDFsharp:
http://pdfsharp.net/wiki/MixMigraDocAnd ... ample.ashx

There are more samples on the site.

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


Top
 Profile  
Reply with quote  
PostPosted: Sun Dec 06, 2015 6:44 pm 
Offline

Joined: Sat Dec 05, 2015 7:57 pm
Posts: 3
Hi Thomas,

The following code adds a header and a footer to a new pdf document.

I would like to do the same but for an existing pdf document.

Is it possible or not?

Can anyone help me on this?

Thanks

Code:
        Try
            Dim myDoc As Document = New Document
            Dim mySect As Section = myDoc.AddSection()

            mySect.AddParagraph("test hello world")

            Dim paragrph As Paragraph = mySect.Headers.Primary.AddParagraph()
            paragrph.AddText("Label: labelA1" & vbCrLf & "Issue: Issue1")
            paragrph.Format.Alignment = ParagraphAlignment.Right

            Dim paragrphFooter As Paragraph = mySect.Footers.Primary.AddParagraph()
            paragrphFooter.AddText("Footer reference")
            paragrphFooter.Format.Alignment = ParagraphAlignment.Right

            Dim myRenderer As PdfDocumentRenderer = New PdfDocumentRenderer(True, PdfFontEmbedding.Always)
            myRenderer.Document = myDoc
            myRenderer.RenderDocument()

            Const filename As String = "c://Demo1.pdf"

            myRenderer.PdfDocument.Save(filename)

            Process.Start(filename)

        Catch ex As Exception
            Debug.Print(ex.Message)
        End Try


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 07, 2015 8:56 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
welby wrote:
Is it possible or not?
It is possible with some effort on your side.

First option: create a new PDF document with MigraDoc containing headers and footers and lay the new pages over the existing pages using PDFsharp.

Second option: Follow the MixingMigraDocAndPDFsharp sample and draw header and footer directly onto the existing pages using "docRenderer.RenderPage(gfx, idx + 1); ".

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 13, 2016 7:22 am 
Offline

Joined: Wed Jul 13, 2016 7:17 am
Posts: 2
Hi Thomas,

Please help me a option 1, i have a urgent task for this situation.
I really important with me.

Thanks
Tuan Nguyen.


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 163 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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group