Add oform_pdf format

This commit is contained in:
Oleg Korshul
2023-11-27 23:38:06 +03:00
parent 282e1fe025
commit 94c4e22b8e
8 changed files with 226 additions and 3 deletions

View File

@ -0,0 +1,34 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
static const char* g_format_oform_pdf_meta_tag = "ONLYOFFICE FORM";

View File

@ -110,7 +110,7 @@ public:
void SetCMapFile(const std::wstring& sFile);
void ToXml(const std::wstring& sFile, bool bSaveStreams = false);
bool GetMetaData(const std::wstring& sFile, const std::wstring& sMetaName, BYTE** pMetaData, DWORD& nMetaLength);
static bool GetMetaData(const std::wstring& sFile, const std::wstring& sMetaName, BYTE** pMetaData, DWORD& nMetaLength);
virtual bool LoadFromFile (const std::wstring& file, const std::wstring& options = L"", const std::wstring& owner_password = L"", const std::wstring& user_password = L"");
virtual bool LoadFromMemory(BYTE* data, DWORD length, const std::wstring& options = L"", const std::wstring& owner_password = L"", const std::wstring& user_password = L"");
virtual NSFonts::IApplicationFonts* GetFonts();

View File

@ -94,7 +94,8 @@ HEADERS += \
\
../../src/lib/odf.h \
\
../../src/lib/pdf_image.h
../../src/lib/pdf_image.h \
../../src/lib/pdf_oform.h
#vbaformat
LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lVbaFormatLib

View File

@ -311,6 +311,10 @@ namespace NExtractTools
nRes = dir2zipMscrypt(sFromWithChanges, sTo, params, convertParams);
}
}
else if (AVS_OFFICESTUDIO_FILE_DOCUMENT_OFORM_PDF == nFormatTo)
{
nRes = docx_dir2pdfoform(sFromWithChanges, sTo, params, convertParams);
}
else if (AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC == nFormatTo)
{
nRes = docx_dir2doc(sFromWithChanges, sTo, params, convertParams);
@ -435,6 +439,10 @@ namespace NExtractTools
NSDoctRenderer::DoctRendererFormat::FormatFile eFromType = NSDoctRenderer::DoctRendererFormat::FormatFile::DOCT;
nRes = doct_bin2pdf(eFromType, sFrom, sTo, params, convertParams);
}
else if (AVS_OFFICESTUDIO_FILE_DOCUMENT_OFORM_PDF == nFormatTo)
{
nRes = doct_bin2pdfoform(sFrom, sTo, params, convertParams);
}
else if (0 != (AVS_OFFICESTUDIO_FILE_IMAGE & nFormatTo))
{
NSDoctRenderer::DoctRendererFormat::FormatFile eFromType = NSDoctRenderer::DoctRendererFormat::FormatFile::DOCT;
@ -508,7 +516,9 @@ namespace NExtractTools
std::wstring sDocxDir = combinePath(convertParams.m_sTempDir, L"docx_unpacked");
NSDirectory::CreateDirectory(sDocxDir);
if (AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX == nFormatFrom || AVS_OFFICESTUDIO_FILE_DOCUMENT_OFORM == nFormatFrom || AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCXF == nFormatFrom)
if (AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX == nFormatFrom ||
AVS_OFFICESTUDIO_FILE_DOCUMENT_OFORM == nFormatFrom ||
AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCXF == nFormatFrom)
{
sDocxFile = sFrom;
convertParams.m_sTempParamOOXMLFile = sDocxFile;

View File

@ -260,6 +260,15 @@ namespace NExtractTools
// DECLARE_CONVERT_FUNC(doct_bin2pdf);
// DECLARE_CONVERT_FUNC(doct_bin2image);
DECLARE_CONVERT_FUNC(pdfoform2docx_dir);
DECLARE_CONVERT_FUNC(docx_dir2pdfoform);
DECLARE_CONVERT_FUNC(pdfoform2doct_bin);
DECLARE_CONVERT_FUNC(doct_bin2pdfoform);
DECLARE_CONVERT_FUNC(pdfoform2docx);
DECLARE_CONVERT_FUNC(docx2pdfoform);
DECLARE_CONVERT_FUNC(pdfoform2doct);
DECLARE_CONVERT_FUNC(doct2pdfoform);
//-------------------------------------------------------------------------------------------------------------------------------------------------
_UINT32 convertmailmerge(const InputParamsMailMerge& oMailMergeSend, const std::wstring& sFrom, const std::wstring& sTo, InputParams& params, ConvertParams& convertParams);

View File

@ -475,6 +475,9 @@ namespace NExtractTools
std::wstring m_sInternalMediaDirectory;
std::string m_sPrintPages;
std::wstring m_sPdfOformMetaName;
std::wstring m_sPdfOformMetaData;
};
class InputParams

View File

@ -226,6 +226,19 @@ namespace NExtractTools
if (false == password.empty())
pdfWriter.SetPassword(password);
if (!convertParams.m_sPdfOformMetaName.empty() && !convertParams.m_sPdfOformMetaData.empty())
{
BYTE* pFileMetaData = NULL;
DWORD nFileMetaSize = 0;
if (NSFile::CFileBinary::ReadAllBytes(convertParams.m_sPdfOformMetaData, &pFileMetaData, nFileMetaSize))
{
pdfWriter.AddMetaData(convertParams.m_sPdfOformMetaName, pFileMetaData, nFileMetaSize);
}
RELEASEARRAYOBJECTS(pFileMetaData);
}
int nReg = (convertParams.m_bIsPaid == false) ? 0 : 1;
nRes = (S_OK == pdfWriter.OnlineWordToPdfFromBinary(sPdfBinFile, sTo, &oBufferParams)) ? nRes : AVS_FILEUTILS_ERROR_CONVERT;
RELEASEOBJECT(pApplicationFonts);

View File

@ -0,0 +1,153 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include "../../../Common/OfficeFileFormatDefines.h"
#include "./pdf_image.h"
namespace NExtractTools
{
_UINT32 pdfoform2docx_dir(const std::wstring& sFrom, const std::wstring& sTo, InputParams& params, ConvertParams& convertParams)
{
std::wstring sTempDocx = combinePath(convertParams.m_sTempDir, L"meta.docx");
_UINT32 nRes = pdfoform2docx(sFrom, sTempDocx, params, convertParams);
if (SUCCEEDED_X2T(nRes))
{
COfficeUtils oOfficeUtils(NULL);
if (S_OK == oOfficeUtils.ExtractToDirectory(sTempDocx, sTo, NULL, 0))
return 0;
return AVS_FILEUTILS_ERROR_CONVERT;
}
return nRes;
}
_UINT32 docx_dir2pdfoform(const std::wstring& sFrom, const std::wstring& sTo, InputParams& params, ConvertParams& convertParams)
{
std::wstring sDocxMeta = combinePath(convertParams.m_sTempDir, L"meta.docx");
_UINT32 nRes = dir2zipMscrypt(sFrom, sDocxMeta, params, convertParams);
if (!SUCCEEDED_X2T(nRes))
return nRes;
std::wstring sDoctDir = combinePath(convertParams.m_sTempDir, L"doct_pdf_unpacked");
std::wstring sDoctMeta = combinePath(sDoctDir, L"Editor.bin");
NSDirectory::CreateDirectory(sDoctDir);
nRes = docx_dir2doct_bin(sFrom, sDoctMeta, params, convertParams);
if (!SUCCEEDED_X2T(nRes))
return nRes;
convertParams.m_sPdfOformMetaName = NSFile::CUtf8Converter::GetUnicodeFromCharPtr(g_format_oform_pdf_meta_tag, strlen(g_format_oform_pdf_meta_tag));
convertParams.m_sPdfOformMetaData = sDocxMeta;
nRes = doct_bin2pdf(NSDoctRenderer::DoctRendererFormat::DOCT, sDoctMeta, sTo, params, convertParams);
convertParams.m_sPdfOformMetaName = L"";
convertParams.m_sPdfOformMetaData = L"";
return nRes;
}
_UINT32 pdfoform2doct_bin(const std::wstring& sFrom, const std::wstring& sTo, InputParams& params, ConvertParams& convertParams)
{
std::wstring sDocxDir = combinePath(convertParams.m_sTempDir, L"docx_unpacked");
NSDirectory::CreateDirectory(sDocxDir);
_UINT32 nRes = pdfoform2docx_dir(sFrom, sDocxDir, params, convertParams);
if (SUCCEEDED_X2T(nRes))
{
return docx_dir2doct_bin(sDocxDir, sTo, params, convertParams);
}
return nRes;
}
_UINT32 doct_bin2pdfoform(const std::wstring& sFrom, const std::wstring& sTo, InputParams& params, ConvertParams& convertParams)
{
std::wstring sDocxMeta = combinePath(convertParams.m_sTempDir, L"meta.docx");
_UINT32 nRes = doct_bin2docx(sFrom, sDocxMeta, params, convertParams);
if (!SUCCEEDED_X2T(nRes))
return nRes;
convertParams.m_sPdfOformMetaName = NSFile::CUtf8Converter::GetUnicodeFromCharPtr(g_format_oform_pdf_meta_tag, strlen(g_format_oform_pdf_meta_tag));
convertParams.m_sPdfOformMetaData = sDocxMeta;
nRes = doct_bin2pdf(NSDoctRenderer::DoctRendererFormat::DOCT, sFrom, sTo, params, convertParams);
convertParams.m_sPdfOformMetaName = L"";
convertParams.m_sPdfOformMetaData = L"";
return nRes;
}
_UINT32 pdfoform2docx(const std::wstring& sFrom, const std::wstring& sTo, InputParams& params, ConvertParams& convertParams)
{
BYTE* pData = NULL;
DWORD dwDataSize = 0;
std::wstring sMetaName = NSFile::CUtf8Converter::GetUnicodeFromCharPtr(g_format_oform_pdf_meta_tag, strlen(g_format_oform_pdf_meta_tag));
CPdfFile::GetMetaData(sFrom, sMetaName, &pData, dwDataSize);
if (NULL == pData)
return AVS_FILEUTILS_ERROR_CONVERT;
NSFile::CFileBinary oFile;
if (oFile.CreateFile(sTo))
{
bool bIsOk = oFile.WriteFile(pData, dwDataSize);
oFile.CloseFile();
return bIsOk ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
}
return AVS_FILEUTILS_ERROR_CONVERT;
}
_UINT32 docx2pdfoform(const std::wstring& sFrom, const std::wstring& sTo, InputParams& params, ConvertParams& convertParams)
{
return NSCommon::ooxml2format(sFrom, sTo, params, convertParams, L"docx", docx_dir2pdfoform);
}
_UINT32 pdfoform2doct(const std::wstring& sFrom, const std::wstring& sTo, InputParams& params, ConvertParams& convertParams)
{
return NSCommon::format2oot(sFrom, sTo, params, convertParams, L"doct", pdfoform2doct_bin);
}
_UINT32 doct2pdfoform(const std::wstring& sFrom, const std::wstring& sTo, InputParams& params, ConvertParams& convertParams)
{
return NSCommon::oot2format(sFrom, sTo, params, convertParams, L"doct", doct_bin2pdfoform);
}
}