PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu May 02, 2024 4:26 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Jan 18, 2010 3:39 am 
Offline

Joined: Fri Jan 15, 2010 12:42 am
Posts: 4
Does anyone know how or is it atleast possible to attach or append a normal pdf file to a dynamically created migradoc document.

I looked at the

Code:
PdfDocument pdftoapp = PdfReader.Open(@"C:\PDF_Report.pdf");


but unable to join it with a Migradoc document.

Thanks


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 18, 2010 10:31 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
Check our samples.

One sample:
http://www.pdfsharp.net/wiki/Concatenat ... ample.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 21, 2010 1:34 am 
Offline

Joined: Fri Jan 15, 2010 12:42 am
Posts: 4
Thanks for the link, had a looked at your samples, I was unable to find how to import a pdf document into a Migradoc document directly.

I figured this method using the examples but there has to be an easier way, please advise.

step 1 Create a blank pdf sharp document
step 2 add the dynamically generated migradoc in to the blank pdf
step 3 import the normal pdf simply via PdfReader

Code:

        static double A4Width = XUnit.FromCentimeter(21).Point;
        static double A4Height = XUnit.FromCentimeter(29.7).Point;

        public PDFDocumentImportTest()
        {
            string filename = "MixMigraDocAndPdfSharp.pdf";
            filename = Guid.NewGuid().ToString("D").ToUpper() + ".pdf";
            PdfDocument mainPDF = new PdfDocument();

            MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(PdfDocumentObj);
            docRenderer.PrepareDocument();

            XRect A4Rect = new XRect(0, 0, A4Width, A4Height);

            int pageCount = docRenderer.FormattedDocument.PageCount;

            for (int idx = 0; idx < pageCount; idx++)
            {
                PdfPage mainPdfPage = mainPDF.AddPage();
                XGraphics gfx = XGraphics.FromPdfPage(mainPdfPage);
                // HACKĀ²
                gfx.MUH = PdfFontEncoding.Unicode;
                gfx.MFEH = PdfFontEmbedding.Default;

                // Use BeginContainer / EndContainer for simplicity only. You can naturaly use you own transformations.
                XGraphicsContainer container = gfx.BeginContainer(A4Rect, A4Rect, XGraphicsUnit.Point);

                // Render the page. Note that page numbers start with 1.
                docRenderer.RenderPage(gfx, idx + 1);

                // Note: The outline and the hyperlinks (table of content) does not work in the produced PDF document.

                // Pop the previous graphical state
                gfx.EndContainer(container);
            }
               
            PdfDocument pdfInFile = PdfReader.Open(@"C:\Temp\Already_Generated_PDF_Report.pdf", PdfDocumentOpenMode.Import);

            foreach (PdfPage p in pdfInFile.Pages)
            {
                mainPDF.AddPage(p);
            }

            mainPDF.Save(filename);
            Process.Start(filename);
        }


Is the above correct? is there an easier method? How would you reorder the page numbers?(a hint)

Thanks


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 21, 2010 10:50 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
indula wrote:
Is the above correct?

It looks correct.

indula wrote:
is there an easier method?

I have no idea.

indula wrote:
How would you reorder the page numbers?(a hint)

What's the problem? Both documents have pages starting with 1?
You can add the existing document first and append the new document (not starting at page 1 but at page (n + 1) assuming the existing document has n pages.
You can create a new page 0 with PDFsharp or MigraDoc that shows that "old document" starts at page 1 and "new document" starts at page (n + 1).

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 95 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