Enable security removal in FPDF_Doc_Save
[pdfium.git] / fpdfsdk / src / fpdfsave.cpp
index 8272eb0..6637c78 100644 (file)
@@ -1,91 +1,96 @@
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../include/fsdk_define.h"\r
-#include "../include/fpdfsave.h"\r
-#include "../include/fpdfedit.h"\r
-#if _FX_OS_ == _FX_ANDROID_\r
-#include "time.h"\r
-#else\r
-#include <ctime>\r
-#endif\r
-\r
-class CFX_IFileWrite:public IFX_StreamWrite\r
-{\r
-       \r
-public:\r
-       CFX_IFileWrite();\r
-       FX_BOOL                         Init( FPDF_FILEWRITE * pFileWriteStruct );\r
-       virtual FX_BOOL         WriteBlock(const void* pData, size_t size);\r
-       virtual void            Release(){};\r
-       \r
-protected:\r
-       FPDF_FILEWRITE*         m_pFileWriteStruct;\r
-};\r
-\r
-CFX_IFileWrite::CFX_IFileWrite()\r
-{\r
-       m_pFileWriteStruct = NULL;\r
-}\r
-\r
-FX_BOOL CFX_IFileWrite::Init( FPDF_FILEWRITE * pFileWriteStruct )\r
-{\r
-       if (!pFileWriteStruct)\r
-               return FALSE;\r
-       else\r
-       {\r
-               m_pFileWriteStruct = pFileWriteStruct;\r
-       }\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL CFX_IFileWrite::WriteBlock(const void* pData, size_t size)\r
-{\r
-       if (m_pFileWriteStruct)\r
-       {\r
-               m_pFileWriteStruct->WriteBlock( m_pFileWriteStruct, pData, size );\r
-               return TRUE;\r
-       }\r
-       else \r
-               return FALSE;\r
-}\r
-\r
-FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,FPDF_DWORD flags, FPDF_BOOL bSetVersion,\r
-                                                int fileVerion)\r
-{\r
-       CPDF_Document* pDoc = (CPDF_Document*)document;\r
-       if (!pDoc) \r
-               return 0;\r
-       \r
-       if ( flags < 1 || flags > 2 )\r
-       {\r
-               flags = 0;\r
-       }\r
-       \r
-       CPDF_Creator FileMaker(pDoc);\r
-       if(bSetVersion)\r
-               FileMaker.SetFileVersion(fileVerion);\r
-       CFX_IFileWrite* pStreamWrite = NULL;\r
-       FX_BOOL bRet;\r
-       pStreamWrite = new CFX_IFileWrite;\r
-       pStreamWrite->Init( pFileWrite );\r
-       bRet = FileMaker.Create(pStreamWrite, flags);\r
-       delete pStreamWrite;\r
-       return bRet;\r
-}\r
-\r
-DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(   FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,\r
-                                                                                               FPDF_DWORD flags )\r
-{\r
-       return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE , 0);\r
-}\r
-\r
-\r
-DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(      FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,\r
-       FPDF_DWORD flags, int fileVersion)\r
-{\r
-       return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE , fileVersion);\r
-}\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../include/fsdk_define.h"
+#include "../include/fpdfsave.h"
+#include "../include/fpdfedit.h"
+#if _FX_OS_ == _FX_ANDROID_
+#include "time.h"
+#else
+#include <ctime>
+#endif
+
+class CFX_IFileWrite:public IFX_StreamWrite
+{
+       
+public:
+       CFX_IFileWrite();
+       FX_BOOL                         Init( FPDF_FILEWRITE * pFileWriteStruct );
+       virtual FX_BOOL         WriteBlock(const void* pData, size_t size);
+       virtual void            Release(){};
+       
+protected:
+       FPDF_FILEWRITE*         m_pFileWriteStruct;
+};
+
+CFX_IFileWrite::CFX_IFileWrite()
+{
+       m_pFileWriteStruct = NULL;
+}
+
+FX_BOOL CFX_IFileWrite::Init( FPDF_FILEWRITE * pFileWriteStruct )
+{
+       if (!pFileWriteStruct)
+               return FALSE;
+       else
+       {
+               m_pFileWriteStruct = pFileWriteStruct;
+       }
+       return TRUE;
+}
+
+FX_BOOL CFX_IFileWrite::WriteBlock(const void* pData, size_t size)
+{
+       if (m_pFileWriteStruct)
+       {
+               m_pFileWriteStruct->WriteBlock( m_pFileWriteStruct, pData, size );
+               return TRUE;
+       }
+       else 
+               return FALSE;
+}
+
+FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,FPDF_DWORD flags, FPDF_BOOL bSetVersion,
+                                                int fileVerion)
+{
+       CPDF_Document* pDoc = (CPDF_Document*)document;
+       if (!pDoc) 
+               return 0;
+       
+       if ( flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY )
+       {
+               flags = 0;
+       }
+       
+       CPDF_Creator FileMaker(pDoc);
+       if(bSetVersion)
+               FileMaker.SetFileVersion(fileVerion);
+       if(flags == FPDF_REMOVE_SECURITY)
+       {
+               flags =  0;
+               FileMaker.RemoveSecurity();
+       }
+       CFX_IFileWrite* pStreamWrite = NULL;
+       FX_BOOL bRet;
+       pStreamWrite = new CFX_IFileWrite;
+       pStreamWrite->Init( pFileWrite );
+       bRet = FileMaker.Create(pStreamWrite, flags);
+       delete pStreamWrite;
+       return bRet;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(   FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,
+                                                                                               FPDF_DWORD flags )
+{
+       return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE , 0);
+}
+
+
+DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(      FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,
+       FPDF_DWORD flags, int fileVersion)
+{
+       return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE , fileVersion);
+}