So, yes the method void AddDateParams(PdfDictionary ¶ms, const PdfDate &creation_date, const PdfDate &mod_date) const;
needs to be const, because it is used by method that are const too. That ensure that methods called by a const method not change class members. Here is the patch file with your recommended changed. Index: src/base/PdfInputStream.cpp =================================================================== --- src/base/PdfInputStream.cpp (revision 1697) +++ src/base/PdfInputStream.cpp (working copy) @@ -35,6 +35,7 @@ #include "PdfInputDevice.h" #include "PdfDefinesPrivate.h" +#include "PdfDate.h" #include <stdio.h> #include <string.h> @@ -98,6 +99,24 @@ return lLen; } +PdfDate PdfFileInputStream::GetModifiedDate() +{ + + struct stat file_stat; + int fp = fileno(m_hFile); + fstat(fp, &file_stat); + return PdfDate(file_stat.st_mtime); +} + + +PdfDate PdfFileInputStream::GetCreationDate() +{ + struct stat file_stat; + int fp = fileno(m_hFile); + fstat(fp, &file_stat); + return PdfDate(file_stat.st_ctime); +} + FILE* PdfFileInputStream::GetHandle() { Index: src/base/PdfInputStream.h =================================================================== --- src/base/PdfInputStream.h (revision 1697) +++ src/base/PdfInputStream.h (working copy) @@ -35,6 +35,7 @@ #define _PDF_INPUT_STREAM_H_ #include "PdfDefines.h" +#include "PdfDate.h" namespace PoDoFo { @@ -103,6 +104,16 @@ */ pdf_long GetFileLength(); + /** Get the modified date of the file. + * \return the file modified date + */ + PdfDate GetModifiedDate(); + + /** Get the creation date of the file. + * \return the file creation date + */ + PdfDate GetCreationDate(); + /** Get the internal FILE handle. * \return the internal FILE handle */ Index: src/doc/PdfFileSpec.cpp =================================================================== --- src/doc/PdfFileSpec.cpp (revision 1697) +++ src/doc/PdfFileSpec.cpp (working copy) @@ -39,6 +39,7 @@ #include "base/PdfInputStream.h" #include "base/PdfObject.h" #include "base/PdfStream.h" +#include "base/PdfDate.h" #include <sstream> @@ -182,7 +183,7 @@ // Add additional information about the embedded file to the stream PdfDictionary params; params.AddKey( "Size", static_cast<pdf_int64>(stream.GetFileLength()) ); - // TODO: CreationDate and ModDate + AddDateParams(params, stream.GetCreationDate(), stream.GetModifiedDate()); pStream->GetDictionary().AddKey("Params", params ); } @@ -291,7 +292,7 @@ // Add additional information about the embedded file to the stream PdfDictionary params; params.AddKey( "Size", static_cast<pdf_int64>(stream.GetFileLength()) ); - // TODO: CreationDate and ModDate + AddDateParams(params, stream.GetCreationDate(), stream.GetModifiedDate()); pStream->GetDictionary().AddKey("Params", params ); } @@ -320,7 +321,7 @@ return lastFrom; } -void PdfFileSpec::EmbeddFileFromMem( PdfObject* pStream, const unsigned char* data, ptrdiff_t size ) const +void PdfFileSpec::EmbeddFileFromMem( PdfObject* pStream, const unsigned char* data, ptrdiff_t size, const PdfDate* creation_date, const PdfDate* mod_date ) const { PdfMemoryInputStream memstream(reinterpret_cast<const char*>(data),size); pStream->GetStream()->Set( &memstream ); @@ -328,6 +329,17 @@ // Add additional information about the embedded file to the stream PdfDictionary params; params.AddKey( "Size", static_cast<pdf_int64>(size) ); + PdfDate creation_date_internal; + PdfDate mod_date_internal; + if (creation_date != NULL) + { + creation_date_internal = *creation_date; + } + if (mod_date != NULL) + { + mod_date_internal = *mod_date; + } + AddDateParams( params, creation_date_internal, mod_date_internal ); pStream->GetDictionary().AddKey("Params", params ); } @@ -346,5 +358,15 @@ PODOFO_RAISE_ERROR( ePdfError_InvalidDataType ); } +void PdfFileSpec::AddDateParams(PdfDictionary ¶ms, const PdfDate &creation_date, const PdfDate &mod_date) const +{ + PdfString mod_date_string; + mod_date.ToString(mod_date_string); + params.AddKey("ModDate", mod_date_string); + PdfString creation_date_string; + creation_date.ToString(creation_date_string); + params.AddKey("CreationDate", creation_date_string); +} + }; Index: src/doc/PdfFileSpec.h =================================================================== --- src/doc/PdfFileSpec.h (revision 1697) +++ src/doc/PdfFileSpec.h (working copy) @@ -38,6 +38,8 @@ #include "podofo/base/PdfString.h" +#include "base/PdfDate.h" + #include "PdfElement.h" namespace PoDoFo { @@ -125,8 +127,15 @@ /* Petr P. Petrov 17 September 2009*/ /** Embeds the file from memory */ - void EmbeddFileFromMem( PdfObject* pStream, const unsigned char* data, ptrdiff_t size ) const; + void EmbeddFileFromMem( PdfObject* pStream, const unsigned char* data, ptrdiff_t size, const PdfDate* creation_date = NULL, const PdfDate* mod_date = NULL ) const; + /** Add creation date and modified date params to the given dictonary. + * \param params add the dates to this dictionary + * \param creation_date the creation date that will be added + * \param mod_date the modified date that will be added + */ + void AddDateParams( PdfDictionary ¶ms, const PdfDate &creation_date, const PdfDate &mod_date ) const; + }; }; Julian Rehborn Junior Software Engineer ________________________________________ GBS PAVONE Groupware GmbH Im Dörener Feld 3 33100 Paderborn Germany Phone: +49 52 51 31 02-0 Fax: +49 52 51 31 02-99 www.pavone.de ________________________________________ -- GBS PAVONE Groupware GmbH Disclaimer automatically added by GBS Email Management Solutions Sitz der Gesellschaft: GBS PAVONE Groupware GmbH Hospitalstr. 6 99817 Eisenach Germany Webseite: http://www.pavone.de, E-Mail: i...@pavone.de Registereintragung: Amtsgericht Jena HRB 508241 Umsatzsteuer-Identifikations-Nummer gemäß Paragraph 27a UstG: DE 185612304 Geschäftsführer: Jörg Ott From: podofo-users-requ...@lists.sourceforge.net To: podofo-users@lists.sourceforge.net Date: 01.12.2015 07:53 Subject: Re: Set CreationDate and ModDate during file embedding Hi, yes, that's it. Just do not hard code what dates will be used, add optional parameters for them both and only if the caller didn't set them then use the current time. The caller can know the exact dates, but still would prefer to attach the data as a blob. The code will be reused on other places, if found later. > If not, what else represents your description? Thinking of it, one can sometimes attach files without using PdfFileSpec (playing with dictionaries manually). It would be useful to have the method from b) defined as 'static' and 'public' for such cases, thus it's reusable even out of the PdfFileSpec. The actual prototype can be changed too, like passing PdfDate as pointers, and if they are NULL, then fill them as the current time. (Hmm, my initial proposal for the method prototype might be defined as a 'const' method, because it doesn't change anything in the class itself. As it'll be 'static' now, it doesn't matter much.) Thanks and bye, zyx P.S.: Message list digests are breaking threading (if not used properly, or when the client doesn't support to reply to individual messages). Consider changing your settings, the message digest is an ancient way of saving bandwidth and something like that, which is (usually) not a problem these days. -- http://www.litePDF.cz i...@litepdf.cz
embedd_file_cdate_mdate_v2.patch
Description: Binary data
------------------------------------------------------------------------------ Go from Idea to Many App Stores Faster with Intel(R) XDK Give your users amazing mobile app experiences with Intel(R) XDK. Use one codebase in this all-in-one HTML5 development environment. Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs. http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________ Podofo-users mailing list Podofo-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/podofo-users