> chunhsia_t...@mazak.co.jp wrote on 19 Juli 2017 at 10:04: > > Dear Sir / Madam, > > want to set pdf password. > > tried: - > > PdfEncrypt* pEncrypt = PdfEncrypt::CreatePdfEncrypt("user", "owner"); > PdfEncrypt* pEncrypt = PdfEncrypt::CreatePdfEncrypt("", ""); > PdfEncrypt* pEncrypt = PdfEncrypt::CreatePdfEncrypt("user", "owner", > 0, PdfEncrypt::ePdfEncryptAlgorithm_RC4V1, PdfEncrypt::ePdfKeyLength_40); > PdfEncrypt* pEncrypt = PdfEncrypt::CreatePdfEncrypt("user", "owner", > 3900, PdfEncrypt::ePdfEncryptAlgorithm_RC4V1, PdfEncrypt::ePdfKeyLength_40); >
Hi all, it shouldn't be necessary to create a PdfEncrypt object yourself if you are using PdfMemDocument. In that case, just use the SetEncrypted method of your PdfMemDocument (give it the same arguments as CreatePdfEncrypt). Otherwise, delete the object as soon as you've given it to the PdfStreamedDocument constructor (as the latter does copy it for its use) to avoid the object taking up memory while it's unused. Don't do this when using PdfMemDocument as this will own the PdfEncrypt object passed to its SetEncrypted() method (so it'll get deleted automatically when the document is deleted, before that it's still needed). I advise to not not write the permissions as a number, but use the symbolic constants and the bitwise-or operator | to combine them (though this latter is probably not directly related, but good advice for maintainability). > but all has run time error: > > Unhandled exception at 0x75D5845D in PDF.exe: Microsoft C++ exception: > std::bad_alloc at memory location 0x002FDE8C. > > Please advice. > > With regards, > Tang The exception std::bad_alloc is thrown when not enough memory is available, which can happen if you call CreatePdfEncrypt in a loop some high number of times without deleting the objects after giving them to the PdfStreamedDocument constructor. I hope this helps. Best regards, Matthew Brincke ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Podofo-users mailing list Podofo-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/podofo-users