Copy link to clipboard
Copied
Hey Guys,
How can i extract the bookmarks from a PDF file.
I am creating a table of contents in a coldfusion 8 page and I need the bookmarks to link the chapters to the pdf pages.
Thanks a lot!!
Sid
Copy link to clipboard
Copied
You could use a bit of iText to extract the bookmark details (essentially an array of structures) or export them to xml.
<!--- syntax may differ for cf8 --->
<cfset input = "c:/path/to/yourFile.pdf">
<cfset reader = createObject("java", "com.lowagie.text.pdf.PdfReader").init(input)>
<cfset bookmarks = createObject("java", "com.lowagie.text.pdf.SimpleBookmark").getBookmark(reader)>
<cfif structKeyExists(variables, "bookmarks")>
<cfdump var="#bookmarks#">
</cfif>
Copy link to clipboard
Copied
Hey Thanks a lot for code!!!
I am getting an error saying:
Object instantiation exception.
An exception occurred while instantiating a Java object. The class must not
be an interface or an abstract class. Error: ''. The error occurred
in *C:\www\xxxxxxxxxxxxx\index.cfm:
line 5*
3 :
4 :
Thanks a lot!!!
Sid
Copy link to clipboard
Copied
I am getting an error saying:
Object instantiation exception.
CF8's version of iText is older. So there might be some syntax differences. Can you post the strack trace? That has the real error message.
Copy link to clipboard
Copied
Sure here u go!!
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:166)
at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:80)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2360)
at cfindex2ecfm230452687.runPage(C:\www\comm_dev\site-deployment-root\wwwroot\pubs\factsheets\impacto_padre\index.cfm:5)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:381)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:94)
at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:27)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
at coldfusion.CfmServlet.service(CfmServlet.java:200)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
at jrun.servlet.FilterChain.service(FilterChain.java:101)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
Caused by: java.io.IOException: impactopadres.pdf not found as file or resource.
at com.lowagie.text.pdf.RandomAccessFileOrArray.(Unknown Source)
... 38 more
Copy link to clipboard
Copied
Caused by: java.io.IOException: impactopadres.pdf not found
as file or resource.
The error is saying it cannot find your file OR CF does not have permission to read the file. Did you use an absolute path ? Is the path to your pdf correct? ie Does FileExists(pathToYourFile) return true?
Copy link to clipboard
Copied
Ooh I was using a non absolute path. I changes it to an absolute path and it
worked. But is there any other solution for a non absolute path.
Thanks a lot for all the help!!!
Copy link to clipboard
Copied
There are plenty of CF functions for converting file paths, such as ExpandPath(). Check the "System functions" in the documentation.
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec1a60c-7ffc.html#WSc3ff6d0ea77859461172e0811cbec22c24-69b7
Copy link to clipboard
Copied
Awesome!! Thanks a lot!!
Copy link to clipboard
Copied
This is the line 5:
<cfset reader = createObject("java",
"com.lowagie.text.pdf.PdfReader").init(input)>*