void EncryptTest::testLoadEncrypedFilePdfMemDocument() { std::string sFilename = TestUtils::getTempFilename(); try { CreatedEncrypedPdf( sFilename.c_str() ); // Try loading with PdfParser PdfMemDocument document; try { document.Load( sFilename.c_str() ); // Must throw an exception CPPUNIT_FAIL("Encrypted file not recognized!"); } catch( const PdfError & e ) { if( e.GetError() != ePdfError_InvalidPassword ) { CPPUNIT_FAIL("Invalid encryption exception thrown!"); } } document.SetPassword( "user" ); } catch( PdfError & e ) { e.PrintErrorMsg(); printf("Removing temp file: %s\n", sFilename.c_str()); TestUtils::deleteFile(sFilename.c_str()); throw e; } printf("Removing temp file: %s\n", sFilename.c_str()); TestUtils::deleteFile(sFilename.c_str()); }
int count_pages( const char* pszFilename, const bool & bShortFormat ) { PdfMemDocument document; document.Load( pszFilename ); int nPages = document.GetPageCount(); if( bShortFormat ) printf("%i\n", nPages ); else printf("%s:\t%i\n", pszFilename, nPages ); return nPages; }