|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
BookmarksI have an app that creates a PDF document using iTextSharp. After the document has been created I need to add bookmarks to it. I don't want to add any extra pages I just want bookmarks that will take to user to a certain page when they click on it. I have found lots of examples online but I haven't been able to get it working. I'm aware I'm supposed to use the PdfOutline object but I've been trying different examples for days and can't get it working. Just to get me started could someone tell me how to add a bookmark structure to an existing PDF document without adding any extra pages. eg the following structure for a 5 page document:
|---Page 1 | | | --- Page 2 | | | --- Page 3 | |---Page 4 | | --- Page 5 Thanks in advance |
|
|
Re: BookmarksThis is VB.net code that I use to insert bookmarks that refer to specific pages.
Just creating the outline objects creates the bookmarks. First you get a reference to the bookmark root, then you add hierarchical outline objects based on action objects. Let's say you have a pdfwriter object, m_wrtReport, and a contentbyte reference, m_objContentByte. Dim objOutlineRoot As iTextSharp.text.pdf.PdfOutline Dim objOutline As iTextSharp.text.pdf.PdfOutline Dim objSubOutline As iTextSharp.text.pdf.PdfOutline Dim objAction As iTextSharp.text.pdf.PdfAction ' get bookmarks root objOutlineRoot = m_objContentByte.RootOutline ' add page 1 bookmark objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(1, New iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH), m_wrtReport) objOutline = New iTextSharp.text.pdf.PdfOutline(objOutlineRoot, objAction, "Page 1") ' now add suboutlines for page 2 and 3 objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(2, New iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH), m_wrtReport) objSubOutline = New iTextSharp.text.pdf.PdfOutline(objOutline, objAction, "Page 2") objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(3, New iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH), m_wrtReport) objSubOutline = New iTextSharp.text.pdf.PdfOutline(objOutline, objAction, "Page 3") ' add page 4 bookmark objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(4, New iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH), m_wrtReport) objOutline = New iTextSharp.text.pdf.PdfOutline(objOutlineRoot, objAction, "Page 4") ' now add suboutlines for page 5 objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(5, New iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH), m_wrtReport) objSubOutline = New iTextSharp.text.pdf.PdfOutline(objOutline, objAction, "Page 5") Will Rickards On Wed, Apr 22, 2009 at 9:55 AM, johntheface <lace.john@...> wrote: > > I have an app that creates a PDF document using iTextSharp. After the > document has been created I need to add bookmarks to it. I don't want to add > any extra pages I just want bookmarks that will take to user to a certain > page when they click on it. I have found lots of examples online but I > haven't been able to get it working. I'm aware I'm supposed to use the > PdfOutline object but I've been trying different examples for days and can't > get it working. Just to get me started could someone tell me how to add a > bookmark structure to an existing PDF document without adding any extra > pages. eg the following structure for a 5 page document: > > |---Page 1 > | | > | --- Page 2 > | | > | --- Page 3 > | > |---Page 4 > | | > --- Page 5 > > Thanks in advance > -- > View this message in context: http://www.nabble.com/Bookmarks-tp23175463p23175463.html > Sent from the itextsharp-questions mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------------ > Stay on top of everything new and different, both inside and > around Java (TM) technology - register by April 22, and save > $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. > 300 plus technical and hands-on sessions. Register today. > Use priority code J9JMT32. http://p.sf.net/sfu/p > _______________________________________________ > itextsharp-questions mailing list > itextsharp-questions@... > https://lists.sourceforge.net/lists/listinfo/itextsharp-questions > ------------------------------------------------------------------------------ Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p _______________________________________________ itextsharp-questions mailing list itextsharp-questions@... https://lists.sourceforge.net/lists/listinfo/itextsharp-questions |
|
|
Re: BookmarksHi William ,
Hope you will reply PdfAction action = PdfAction.GotoLocalPage(intAdPageNo[0], new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter); PdfOutline ProviderRoot = new PdfOutline(VisitIndex, action, "By Provider", false); I need to change the action of the PdfOutline to some other page, depending on condition How i can do it? Pls reply
|
|
|
Re: BookmarksNot sure what you mean.
You just change the page number, the first argument to GotoLocalPage. In my actual implementation, I'm keeping track of what I'm inserting into the document. So if I start a new page to start a new section, that is when I do m_docReport.NewPage(), I get the page number with m_wrtReport.CurrentPageNumber. Then I add the bookmark. Will Rickards On Tue, Jun 2, 2009 at 8:36 AM, swati jain <swatifordotnet@...> wrote: > > Hi William , > > Hope you will reply > > PdfAction action = PdfAction.GotoLocalPage(intAdPageNo[0], new > PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter); > PdfOutline ProviderRoot = new PdfOutline(VisitIndex, action, "By Provider", > false); > > I need to change the action of the PdfOutline to some other page, depending > on condition > > How i can do it? > > Pls reply > > > > > William Rickards wrote: >> >> This is VB.net code that I use to insert bookmarks that refer to specific >> pages. >> Just creating the outline objects creates the bookmarks. >> First you get a reference to the bookmark root, then you add >> hierarchical outline objects based on action objects. >> >> Let's say you have a pdfwriter object, m_wrtReport, and a contentbyte >> reference, m_objContentByte. >> >> Dim objOutlineRoot As iTextSharp.text.pdf.PdfOutline >> Dim objOutline As iTextSharp.text.pdf.PdfOutline >> Dim objSubOutline As iTextSharp.text.pdf.PdfOutline >> Dim objAction As iTextSharp.text.pdf.PdfAction >> >> ' get bookmarks root >> objOutlineRoot = m_objContentByte.RootOutline >> >> ' add page 1 bookmark >> objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(1, >> New >> iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH), >> m_wrtReport) >> objOutline = New >> iTextSharp.text.pdf.PdfOutline(objOutlineRoot, objAction, "Page 1") >> >> ' now add suboutlines for page 2 and 3 >> objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(2, >> New >> iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH), >> m_wrtReport) >> objSubOutline = New >> iTextSharp.text.pdf.PdfOutline(objOutline, objAction, "Page 2") >> >> objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(3, >> New >> iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH), >> m_wrtReport) >> objSubOutline = New >> iTextSharp.text.pdf.PdfOutline(objOutline, objAction, "Page 3") >> >> ' add page 4 bookmark >> objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(4, >> New >> iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH), >> m_wrtReport) >> objOutline = New >> iTextSharp.text.pdf.PdfOutline(objOutlineRoot, objAction, "Page 4") >> >> ' now add suboutlines for page 5 >> objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(5, >> New >> iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH), >> m_wrtReport) >> objSubOutline = New >> iTextSharp.text.pdf.PdfOutline(objOutline, objAction, "Page 5") >> >> >> Will Rickards >> >> >> >> On Wed, Apr 22, 2009 at 9:55 AM, johntheface <lace.john@...> >> wrote: >>> >>> I have an app that creates a PDF document using iTextSharp. After the >>> document has been created I need to add bookmarks to it. I don't want to >>> add >>> any extra pages I just want bookmarks that will take to user to a certain >>> page when they click on it. I have found lots of examples online but I >>> haven't been able to get it working. I'm aware I'm supposed to use the >>> PdfOutline object but I've been trying different examples for days and >>> can't >>> get it working. Just to get me started could someone tell me how to add a >>> bookmark structure to an existing PDF document without adding any extra >>> pages. eg the following structure for a 5 page document: >>> >>> |---Page 1 >>> | | >>> | --- Page 2 >>> | | >>> | --- Page 3 >>> | >>> |---Page 4 >>> | | >>> --- Page 5 >>> >>> Thanks in advance >>> -- >>> View this message in context: >>> http://www.nabble.com/Bookmarks-tp23175463p23175463.html >>> Sent from the itextsharp-questions mailing list archive at Nabble.com. >>> >>> >>> ------------------------------------------------------------------------------ >>> Stay on top of everything new and different, both inside and >>> around Java (TM) technology - register by April 22, and save >>> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >>> 300 plus technical and hands-on sessions. Register today. >>> Use priority code J9JMT32. http://p.sf.net/sfu/p >>> _______________________________________________ >>> itextsharp-questions mailing list >>> itextsharp-questions@... >>> https://lists.sourceforge.net/lists/listinfo/itextsharp-questions >>> >> >> ------------------------------------------------------------------------------ >> Stay on top of everything new and different, both inside and >> around Java (TM) technology - register by April 22, and save >> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >> 300 plus technical and hands-on sessions. Register today. >> Use priority code J9JMT32. http://p.sf.net/sfu/p >> _______________________________________________ >> itextsharp-questions mailing list >> itextsharp-questions@... >> https://lists.sourceforge.net/lists/listinfo/itextsharp-questions >> >> > > -- > View this message in context: http://www.nabble.com/Bookmarks-tp23175463p23831704.html > Sent from the itextsharp-questions mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------------ > OpenSolaris 2009.06 is a cutting edge operating system for enterprises > looking to deploy the next generation of Solaris that includes the latest > innovations from Sun and the OpenSource community. Download a copy and > enjoy capabilities such as Networking, Storage and Virtualization. > Go to: http://p.sf.net/sfu/opensolaris-get > _______________________________________________ > itextsharp-questions mailing list > itextsharp-questions@... > https://lists.sourceforge.net/lists/listinfo/itextsharp-questions > ------------------------------------------------------------------------------ OpenSolaris 2009.06 is a cutting edge operating system for enterprises looking to deploy the next generation of Solaris that includes the latest innovations from Sun and the OpenSource community. Download a copy and enjoy capabilities such as Networking, Storage and Virtualization. Go to: http://p.sf.net/sfu/opensolaris-get _______________________________________________ itextsharp-questions mailing list itextsharp-questions@... https://lists.sourceforge.net/lists/listinfo/itextsharp-questions |
| Free embeddable forum powered by Nabble | Forum Help |