mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Add method for save added annotations
This commit is contained in:
@ -31,50 +31,48 @@
|
|||||||
*/
|
*/
|
||||||
#include "OnlineOfficeBinToPdf.h"
|
#include "OnlineOfficeBinToPdf.h"
|
||||||
|
|
||||||
#include "../../DesktopEditor/common/File.h"
|
|
||||||
#include "../../DesktopEditor/common/Directory.h"
|
#include "../../DesktopEditor/common/Directory.h"
|
||||||
#include "../../DesktopEditor/common/Base64.h"
|
|
||||||
#include "../../DesktopEditor/graphics/MetafileToRenderer.h"
|
#include "../../DesktopEditor/graphics/MetafileToRenderer.h"
|
||||||
|
|
||||||
namespace NSOnlineOfficeBinToPdf
|
namespace NSOnlineOfficeBinToPdf
|
||||||
{
|
{
|
||||||
class CMetafileToRenderterPDF : public IMetafileToRenderter
|
class CMetafileToRenderterPDF : public IMetafileToRenderter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CMetafileToRenderterPDF(IRenderer* pRenderer) : IMetafileToRenderter(pRenderer)
|
CMetafileToRenderterPDF(IRenderer* pRenderer) : IMetafileToRenderter(pRenderer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void SetLinearGradiant(const double& x0, const double& y0, const double& x1, const double& y1)
|
virtual void SetLinearGradiant(const double& x0, const double& y0, const double& x1, const double& y1)
|
||||||
{
|
{
|
||||||
((CPdfFile*)m_pRenderer)->SetLinearGradient(x0, y0, x1, y1);
|
((CPdfFile*)m_pRenderer)->SetLinearGradient(x0, y0, x1, y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void SetRadialGradiant(const double& dX0, const double& dY0, const double& dR0, const double& dX1, const double& dY1, const double& dR1)
|
virtual void SetRadialGradiant(const double& dX0, const double& dY0, const double& dR0, const double& dX1, const double& dY1, const double& dR1)
|
||||||
{
|
{
|
||||||
((CPdfFile*)m_pRenderer)->SetRadialGradient(dX0, dY0, dR0, dX1, dY1, dR1);
|
((CPdfFile*)m_pRenderer)->SetRadialGradient(dX0, dY0, dR0, dX1, dY1, dR1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool ConvertBufferToPdf(CPdfFile* pPdf, BYTE* pBuffer, LONG lBufferLen, CConvertFromBinParams* pParams)
|
static bool ConvertBufferToPdf(CPdfFile* pPdf, BYTE* pBuffer, LONG lBufferLen, CConvertFromBinParams* pParams)
|
||||||
{
|
{
|
||||||
CMetafileToRenderterPDF oCorrector(pPdf);
|
CMetafileToRenderterPDF oCorrector(pPdf);
|
||||||
oCorrector.SetTempDirectory(pPdf->GetTempDirectory());
|
oCorrector.SetTempDirectory(pPdf->GetTempDirectory());
|
||||||
if (pParams)
|
if (pParams)
|
||||||
{
|
{
|
||||||
oCorrector.SetMediaDirectory(pParams->m_sMediaDirectory);
|
oCorrector.SetMediaDirectory(pParams->m_sMediaDirectory);
|
||||||
oCorrector.SetInternalMediaDirectory(pParams->m_sInternalMediaDirectory);
|
oCorrector.SetInternalMediaDirectory(pParams->m_sInternalMediaDirectory);
|
||||||
oCorrector.SetThemesDirectory(pParams->m_sThemesDirectory);
|
oCorrector.SetThemesDirectory(pParams->m_sThemesDirectory);
|
||||||
|
|
||||||
if (pParams->m_bIsUsePicker)
|
if (pParams->m_bIsUsePicker)
|
||||||
oCorrector.InitPicker(pPdf->GetFonts());
|
oCorrector.InitPicker(pPdf->GetFonts());
|
||||||
}
|
}
|
||||||
NSOnlineOfficeBinToPdf::ConvertBufferToRenderer(pBuffer, lBufferLen, &oCorrector);
|
NSOnlineOfficeBinToPdf::ConvertBufferToRenderer(pBuffer, lBufferLen, &oCorrector);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool ConvertBinToPdf(CPdfFile* pPdf, const std::wstring& wsSrcFile, const std::wstring& wsDstFile, bool bBinary, CConvertFromBinParams* pParams)
|
bool ConvertBinToPdf(CPdfFile* pPdf, const std::wstring& wsSrcFile, const std::wstring& wsDstFile, bool bBinary, CConvertFromBinParams* pParams)
|
||||||
{
|
{
|
||||||
NSFile::CFileBinary oFile;
|
NSFile::CFileBinary oFile;
|
||||||
if (!oFile.OpenFile(wsSrcFile))
|
if (!oFile.OpenFile(wsSrcFile))
|
||||||
@ -105,8 +103,8 @@ namespace NSOnlineOfficeBinToPdf
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int nBufferLen = NSBase64::Base64DecodeGetRequiredLength(dwFileSize);
|
int nBufferLen = NSBase64::Base64DecodeGetRequiredLength(dwFileSize);
|
||||||
BYTE* pBuffer = new BYTE[nBufferLen];
|
BYTE* pBuffer = new BYTE[nBufferLen];
|
||||||
if (!pBuffer)
|
if (!pBuffer)
|
||||||
{
|
{
|
||||||
RELEASEARRAYOBJECTS(pFileContent);
|
RELEASEARRAYOBJECTS(pFileContent);
|
||||||
@ -145,4 +143,64 @@ namespace NSOnlineOfficeBinToPdf
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class AddCommandType
|
||||||
|
{
|
||||||
|
Annotation = 0,
|
||||||
|
AddPage = 1,
|
||||||
|
RemovePage = 2,
|
||||||
|
Undefined = 255
|
||||||
|
};
|
||||||
|
|
||||||
|
bool AddBinToPdf(CPdfFile* pPdf, BYTE* pBuffer, unsigned int nLen, CConvertFromBinParams* pParams)
|
||||||
|
{
|
||||||
|
CMetafileToRenderterPDF oCorrector(pPdf);
|
||||||
|
oCorrector.SetTempDirectory(pPdf->GetTempDirectory());
|
||||||
|
if (pParams)
|
||||||
|
{
|
||||||
|
oCorrector.SetMediaDirectory(pParams->m_sMediaDirectory);
|
||||||
|
oCorrector.SetInternalMediaDirectory(pParams->m_sInternalMediaDirectory);
|
||||||
|
oCorrector.SetThemesDirectory(pParams->m_sThemesDirectory);
|
||||||
|
|
||||||
|
if (pParams->m_bIsUsePicker)
|
||||||
|
oCorrector.InitPicker(pPdf->GetFonts());
|
||||||
|
}
|
||||||
|
|
||||||
|
NSOnlineOfficeBinToPdf::CBufferReader oReader(pBuffer, (int)nLen);
|
||||||
|
|
||||||
|
while (oReader.Check())
|
||||||
|
{
|
||||||
|
int nLen = oReader.ReadInt();
|
||||||
|
AddCommandType CommandType = (AddCommandType)oReader.ReadByte();
|
||||||
|
int nPageNum = oReader.ReadInt();
|
||||||
|
|
||||||
|
if (nPageNum < 0)
|
||||||
|
{
|
||||||
|
// ошибка в бинарнике
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: помечаем страницу в writer (nPageNum)
|
||||||
|
|
||||||
|
switch (CommandType)
|
||||||
|
{
|
||||||
|
case AddCommandType::Annotation:
|
||||||
|
{
|
||||||
|
NSOnlineOfficeBinToPdf::ConvertBufferToRenderer(oReader.GetCurrentBuffer(), (LONG)(nLen - 9) , &oCorrector);
|
||||||
|
oReader.Skip(nLen - 9);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case AddCommandType::AddPage:
|
||||||
|
case AddCommandType::RemovePage:
|
||||||
|
{
|
||||||
|
// TODO: version 7.6+
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,8 +37,8 @@
|
|||||||
|
|
||||||
namespace NSOnlineOfficeBinToPdf
|
namespace NSOnlineOfficeBinToPdf
|
||||||
{
|
{
|
||||||
bool ConvertBinToPdf(CPdfFile* pPdf, const std::wstring& wsSrcFile, const std::wstring& wsDstFile, bool bBinary, CConvertFromBinParams* pParams);
|
bool ConvertBinToPdf(CPdfFile* pPdf, const std::wstring& wsSrcFile, const std::wstring& wsDstFile, bool bBinary, CConvertFromBinParams* pParams);
|
||||||
|
bool AddBinToPdf(CPdfFile* pPdf, BYTE* pBuffer, unsigned int nLen, CConvertFromBinParams* pParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _PDF_WRITER_ONLINEOFFICEBINTOPDF_H
|
#endif // _PDF_WRITER_ONLINEOFFICEBINTOPDF_H
|
||||||
|
|
||||||
|
|||||||
@ -1584,3 +1584,11 @@ HRESULT CPdfFile::AdvancedCommand(IAdvancedCommand* command)
|
|||||||
}
|
}
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CPdfFile::AddCommandsToFile(BYTE* pBuffer, unsigned int& nLen, CConvertFromBinParams* pParams)
|
||||||
|
{
|
||||||
|
if (!m_pInternal->pReader || !m_pInternal->pWriter)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return NSOnlineOfficeBinToPdf::AddBinToPdf(this, pBuffer, nLen, pParams);
|
||||||
|
}
|
||||||
|
|||||||
@ -288,6 +288,8 @@ public:
|
|||||||
virtual HRESULT IsSupportAdvancedCommand(const IAdvancedCommand::AdvancedCommandType& type);
|
virtual HRESULT IsSupportAdvancedCommand(const IAdvancedCommand::AdvancedCommandType& type);
|
||||||
virtual HRESULT AdvancedCommand(IAdvancedCommand* command);
|
virtual HRESULT AdvancedCommand(IAdvancedCommand* command);
|
||||||
|
|
||||||
|
bool AddCommandsToFile(BYTE* pBuffer, unsigned int& nLen, CConvertFromBinParams* pParams);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CPdfFile_Private* m_pInternal;
|
CPdfFile_Private* m_pInternal;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user