PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sat Jan 18, 2014 10:46 am 
Offline

Joined: Sat Jan 18, 2014 10:14 am
Posts: 1
I have been using Migradoc for a few weeks now but i'm stuck..

I have to build a small application for my job in which I have to generate a simple documentation pdf from a database. Everything is working fine except for the index page.

The setup of the program is as follows:
First of, I create a dataGridView with all the rows from the database I have to export. Then I loop through this dataGridView and for each row, I add a row to a table in the pdf.
Code:
foreach (DataGridViewRow dataRow in dataGridView.Rows)
            {
                newFolder = dataRow.Cells[4].Value.ToString();

                Row row = t.AddRow();

                row.Cells[0].AddParagraph(dataRow.Cells[0].Value.ToString());
                row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
                Paragraph para = row.Cells[1].AddParagraph();
                //adding image to this cell. long code, don't think it's necessary.
               
                row.Cells[2].AddParagraph(dataRow.Cells[2].Value.ToString());
                row.Cells[2].VerticalAlignment = VerticalAlignment.Center;
                row.Cells[3].AddParagraph(dataRow.Cells[3].Value.ToString());
                row.Cells[3].VerticalAlignment = VerticalAlignment.Center;


Now here comes the problem. The last cell of each row contains the name of the folder in which the data is stored. When the current folder of the row that is looped is different from the last row, then a bookmark needs to be added and a reference on the index page with a page number.
Code:
if (!newFolder.Equals(oldFolder) && newFolder != "")
                {
                    Paragraph p = row.Cells[4].AddParagraph(dataRow.Cells[4].Value.ToString());
                    p.AddBookmark(dataRow.Cells[4].Value.ToString() + "bm");
                    p.Format.OutlineLevel = OutlineLevel.Level2;

                    Hyperlink hLink = indexSection.AddParagraph().AddHyperlink(dataRow.Cells[4].Value.ToString() + "bm", HyperlinkType.Bookmark);
                    hLink.AddText(" - " + dataRow.Cells[4].Value.ToString() + "\t_______________________ ");
                    hLink.AddPageRefField(dataRow.Cells[4].Value.ToString() + "bm");

                }
                else
                {
                    row.Cells[4].AddParagraph(dataRow.Cells[4].Value.ToString());
                }

When the pdf is made, there are bookmarks. On the left side in Adobe Reader I can see all the bookmarks and they point to exactly the right page. These are probably added by the paragraph itself because I'm using
Code:
p.Format.OutlineLevel = OutlineLevel.Level2;
But when i look at the index page, I can see all the bookmarks, but the page numbers all direct to the beginning of the table and so do the hyperlinks.

I assume i'm doing something wrong, but I can't figure out what.

I'd really appreciate some help!


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

All times are UTC


Who is online

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