On Wed, 2015-12-09 at 11:35 +0100, julian.rehb...@de.gbs.com wrote:
> I have not Linux machine to compile it. 
> It looks like some includes are missing. 
> "struct stat" and "fstat" should be available in glibc too. 

        Hi,
I made some more generic changes to your patch. Could you try with it,
please? It worked fine for me, but I'd like to be sure it will work for
you too.
        Thanks in advance,
        zyx

-- 
http://www.litePDF.cz                                 i...@litepdf.cz

Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 1699)
+++ CMakeLists.txt	(working copy)
@@ -82,6 +82,7 @@ CHECK_INCLUDE_FILE("ctype.h" PODOFO_HAVE
 # ancient compilers that don't and will never support the standard.
 
 CHECK_INCLUDE_FILE("sys/types.h" PODOFO_HAVE_SYS_TYPES_H) 
+CHECK_INCLUDE_FILE("sys/stat.h" PODOFO_HAVE_SYS_STAT_H) 
 CHECK_INCLUDE_FILE("stdint.h" PODOFO_HAVE_STDINT_H) 
 # See: http://msdn.microsoft.com/en-us/library/aa384264(VS.85).aspx
 CHECK_INCLUDE_FILE("BaseTsd.h" PODOFO_HAVE_BASETSD_H) 
Index: podofo_config.h.in
===================================================================
--- podofo_config.h.in	(revision 1699)
+++ podofo_config.h.in	(working copy)
@@ -26,6 +26,7 @@
 #cmakedefine PODOFO_HAVE_STDINT_H 1
 #cmakedefine PODOFO_HAVE_BASETSD_H 1 
 #cmakedefine PODOFO_HAVE_SYS_TYPES_H 1
+#cmakedefine PODOFO_HAVE_SYS_STAT_H 1
 /* Integer types - type names */
 #cmakedefine PDF_INT8_TYPENAME   @PDF_INT8_TYPENAME@
 #cmakedefine PDF_INT16_TYPENAME  @PDF_INT16_TYPENAME@
Index: src/base/PdfCompilerCompat.h
===================================================================
--- src/base/PdfCompilerCompat.h	(revision 1699)
+++ src/base/PdfCompilerCompat.h	(working copy)
@@ -57,6 +57,10 @@
 #include <sys/types.h>
 #endif
 
+#if PODOFO_HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
 #if PODOFO_HAVE_MEM_H
 #include <mem.h>
 #endif
Index: src/base/PdfInputStream.cpp
===================================================================
--- src/base/PdfInputStream.cpp	(revision 1699)
+++ 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,30 @@ pdf_long PdfFileInputStream::GetFileLeng
     return lLen;
 }
 
+PdfDate PdfFileInputStream::GetModifiedDate()
+{
+#ifdef PODOFO_HAVE_SYS_STAT_H
+    struct stat file_stat;
+    int fp = fileno(m_hFile);
+    fstat(fp, &file_stat);
+    return PdfDate(file_stat.st_mtime);
+#else
+    return PdfDate();
+#endif
+}
+
+PdfDate PdfFileInputStream::GetCreationDate()
+{
+#ifdef PODOFO_HAVE_SYS_STAT_H
+    struct stat file_stat;
+    int fp = fileno(m_hFile);
+    fstat(fp, &file_stat);
+    return PdfDate(file_stat.st_ctime);
+#else
+    return PdfDate();
+#endif
+}
+
 FILE*
 PdfFileInputStream::GetHandle()
 {
Index: src/base/PdfInputStream.h
===================================================================
--- src/base/PdfInputStream.h	(revision 1699)
+++ 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 @@ class PODOFO_API PdfFileInputStream : pu
      */
     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 1699)
+++ 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 @@ void PdfFileSpec::EmbeddFile( PdfObject*
     // 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 @@ void PdfFileSpec::EmbeddFile( PdfObject*
     // 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 @@ const char *PdfFileSpec::MaybeStripPath(
     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 @@ void PdfFileSpec::EmbeddFileFromMem( Pdf
     // 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,14 @@ const PdfString & PdfFileSpec::GetFilena
     PODOFO_RAISE_ERROR( ePdfError_InvalidDataType );
 }
 
+void PdfFileSpec::AddDateParams(PdfDictionary &params, 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 1699)
+++ src/doc/PdfFileSpec.h	(working copy)
@@ -36,6 +36,7 @@
 
 #include "podofo/base/PdfDefines.h"
 
+#include "podofo/base/PdfDate.h"
 #include "podofo/base/PdfString.h"
 
 #include "PdfElement.h"
@@ -125,7 +126,14 @@ class PODOFO_DOC_API PdfFileSpec : publi
     /* 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 &params, const PdfDate &creation_date, const PdfDate &mod_date ) const;
 
 };
 
------------------------------------------------------------------------------
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to