PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jul 14, 2024 8:01 pm

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: Tue Dec 30, 2008 2:18 pm 
Offline

Joined: Tue Dec 30, 2008 2:11 pm
Posts: 7
I have is I have created a big table which is rendered via a datatable. When I load the pdf it is created but only the first page is shown. In theory there should be around 30 pages. I thought the table would automatically create and go onto a seperate page or am i misinformed? Could someone look at my code and please tell me what to change so that all the table is shown. Many thanks Matt.

Code:
 PdfDocument outputPdf = new PdfDocument();
            PdfPage page0 = outputPdf.AddPage();
           

            Document doc = new Document();
           
            Section tableSection = doc.AddSection();

           
            Table myTable2 = tableSection.AddTable();
           
            myTable2.Borders.Visible = false;
            myTable2.Format.Borders.Visible = false;

            Column column1 = myTable2.AddColumn(Unit.FromCentimeter(2));
            Column column2 = myTable2.AddColumn(Unit.FromCentimeter(2));
            Column column3 = myTable2.AddColumn(Unit.FromCentimeter(8));
            Column column4 = myTable2.AddColumn(Unit.FromCentimeter(2));
            Column column5 = myTable2.AddColumn(Unit.FromCentimeter(2));
            Column column6 = myTable2.AddColumn(Unit.FromCentimeter(2));

           
            Row row1 = myTable2.AddRow();

            row1.Cells[0].AddParagraph("Forename");
            row1.Cells[1].AddParagraph("Surname");
            row1.Cells[2].AddParagraph("Email");
            row1.Cells[3].AddParagraph("Tel Num");
            row1.Cells[4].AddParagraph("Username");
            row1.Cells[5].AddParagraph("Password");


            for(int i =0; i<dt.Rows.Count; i++)
            {

            Row row2 = myTable2.AddRow();

            string item1 = dt.Rows[i][0].ToString();
            string item2 = dt.Rows[i][1].ToString();
            string item3 = dt.Rows[i][2].ToString();
            string item4 = dt.Rows[i][3].ToString();
            string item5 = dt.Rows[i][4].ToString();
            string item6 = dt.Rows[i][5].ToString();

            row2.Cells[0].AddParagraph(item1);
            row2.Cells[1].AddParagraph(item2);
            row2.Cells[2].AddParagraph(item3);
            row2.Cells[3].AddParagraph(item4);
            row2.Cells[4].AddParagraph(item5);
            row2.Cells[5].AddParagraph(item6);
           

                }


       


            DocumentRenderer docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc);
            docRenderer.PrepareDocument();
            XGraphics gfx = XGraphics.FromPdfPage(page0);
           
            docRenderer.RenderPage(gfx, 1, PageRenderOptions.All);
           
           
            outputPdf.Save("C:/Documents and Settings/Matthew Bryant/My Documents/Visual Studio 2008/WebSites/Matt Drop Down/mattsfile.pdf");


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jan 05, 2009 2:09 pm 
Offline

Joined: Wed Nov 12, 2008 9:44 pm
Posts: 2
Well, looking at your code it seems to be doing exactly what you tell it to: rendering only one page.

I'm a bit confused as to why you're using the XGraphics package here. I'm using PDFSharp to render a multi-page table with headers and footers. My rendering code looks something like this:

Code:
Document document = gvPDF.CreateDocument(GridView1);
MiagraDoc.Rendering.PdfDocumentRenderer pdfRenderer = new MiagraDoc.Rendering.PdfDocumentRenderer(true);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();           
pdfRenderer.Save("test.pdf");


There's nothing special about my document, it's just a section with a table and some rows and columns.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 08, 2009 10:41 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
stu72 wrote:
I'm a bit confused as to why you're using the XGraphics package here.

Yep, that's right.

After calling PrepareDocument you can determine how many pages there are in the document. Then you have to loop thru all pages.

If you don't want to modify the pages with PDFsharp calls, then simply follow stu72's approach.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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: Bing [Bot] and 41 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