On Wed, 2016-04-27, 17:47 +0000, Jaseem Ali K T wrote:
> Hi mabri,
>> What I want is to read destinations(bookmarks) from PDF documents.
> Though I would prefer later PDF versions to be my input (later than 1.2),
> I guess even later PDF version could be produced with backward compatibility
> in mind, so having Destinations with PdfName object.
>
> Having support for destinations with PdfName object would make the class even
> more complete.
Hi all,
I have fixed the issue with reading destinations in a way working with ones
produced with backward compatibility (to PDF 1.1) in mind (though don't call
the constructor with a PdfName if the document isn't backward-compatible if
you aren't prepared to handle the exception that would be thrown, to make that
handling easier I've used an error code which is only used for that there).
I've attached the change as a patch to this e-mail, build-tested it okay
(static & shared native GNU/Linux) and now kindly ask you to review it and
(if you are a committer) test, apply and commit it separately to the public
repository. For the sake of Jaseem Ali K T who requested it, please make the
submit/archive time in UTC count for deciding it to be before the freeze, or
the issue to be high enough in relevance to allow the fix during the freeze.
> Regards
> Jaseem
Best regards, mabri
Index: src/doc/PdfDestination.cpp
===================================================================
--- src/doc/PdfDestination.cpp (revision 1747)
+++ src/doc/PdfDestination.cpp (working copy)
@@ -37,7 +37,7 @@
#include "base/PdfDefinesPrivate.h"
#include "PdfAction.h"
-#include "PdfDocument.h"
+#include "PdfMemDocument.h"
#include "PdfNamesTree.h"
#include "PdfPage.h"
#include "PdfPagesTree.h"
@@ -156,9 +156,13 @@
void PdfDestination::Init( PdfObject* pObject, PdfDocument* pDocument )
{
+ bool bValueExpected = false;
+ PdfObject* pValue;
+
if ( pObject->GetDataType() == ePdfDataType_Array )
{
m_array = pObject->GetArray();
+ m_pObject = pObject;
}
else if( pObject->GetDataType() == ePdfDataType_String )
{
@@ -168,7 +172,44 @@
PODOFO_RAISE_ERROR( ePdfError_NoObject );
}
- PdfObject* pValue = pNames->GetValue( "Dests", pObject->GetString() );
+ pValue = pNames->GetValue( "Dests", pObject->GetString() );
+ bValueExpected = true;
+ }
+ else if( pObject->GetDataType() == ePdfDataType_Name )
+ {
+ PdfMemDocument* pMemDoc = dynamic_cast<PdfMemDocument*>(pDocument);
+ if ( !pMemDoc )
+ {
+ PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidHandle,
+ "For reading from a document, only use PdfMemDocument." );
+ }
+
+ PdfObject* pCatalog = pMemDoc->GetCatalog();
+ if ( !pCatalog )
+ {
+ PODOFO_RAISE_ERROR( ePdfError_NoObject );
+ }
+
+ PdfObject* pDests = pCatalog->GetIndirectKey( PdfName( "Dests" ) );
+ if( !pDests )
+ {
+ // The error code has been chosen for its distinguishability.
+ PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidKey,
+ "No PDF-1.1-compatible destination dictionary found." );
+ }
+ pValue = pDests->GetIndirectKey( pObject->GetName() );
+ bValueExpected = true;
+ }
+ else
+ {
+ PdfError::LogMessage( eLogSeverity_Error, "Unsupported object given to"
+ " PdfDestination::Init of type %s", pObject->GetDataTypeString() );
+ m_array = PdfArray(); // needed to prevent crash on method calls
+ // needed for GetObject() use w/o checking its return value for NULL
+ m_pObject = pDocument->GetObjects()->CreateObject( m_array );
+ }
+ if ( bValueExpected )
+ {
if( !pValue )
{
PODOFO_RAISE_ERROR( ePdfError_InvalidName );
@@ -178,9 +219,8 @@
m_array = pValue->GetArray();
else if( pValue->IsDictionary() )
m_array = pValue->GetDictionary().GetKey( "D" )->GetArray();
+ m_pObject = pValue;
}
-
- m_pObject = pObject;
}
void PdfDestination::AddToDictionary( PdfDictionary & dictionary ) const
------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users