fix don't makeWritable different files

This commit is contained in:
Kulikova Svetlana
2022-07-29 13:26:46 +03:00
parent 31158a5f5b
commit 2e820186b5
5 changed files with 30 additions and 10 deletions

View File

@ -680,18 +680,25 @@ return 0;
sInfo = XMLConverter::DictToXml(L"Info", &info); sInfo = XMLConverter::DictToXml(L"Info", &info);
info.free(); info.free();
std::wstring wsPath = m_pInternal->m_pPdfWriter->GetEditPdfPath();
bool bRes = m_pInternal->m_pPdfWriter->EditClose(sTrailer, sInfo); bool bRes = m_pInternal->m_pPdfWriter->EditClose(sTrailer, sInfo);
GString* owner_pswd = NSStrings::CreateString(sPassword);
GString* user_pswd = NSStrings::CreateString(sPassword);
bRes &= m_pInternal->m_pPDFDocument->makeWritable(false, owner_pswd, user_pswd);
delete owner_pswd;
delete user_pswd;
NSFile::CFileBinary oFile; std::string sPathUtf8New = U_TO_UTF8(wsPath);
if (oFile.OpenFile(m_pInternal->m_wsSrcPath)) std::string sPathUtf8Old = U_TO_UTF8(m_pInternal->m_wsSrcPath);
if (sPathUtf8Old == sPathUtf8New || NSSystemPath::NormalizePath(sPathUtf8Old) == NSSystemPath::NormalizePath(sPathUtf8New))
{ {
m_pInternal->m_nFileLength = oFile.GetFileSize(); GString* owner_pswd = NSStrings::CreateString(sPassword);
oFile.CloseFile(); GString* user_pswd = NSStrings::CreateString(sPassword);
bRes &= m_pInternal->m_pPDFDocument->makeWritable(false, owner_pswd, user_pswd);
delete owner_pswd;
delete user_pswd;
NSFile::CFileBinary oFile;
if (oFile.OpenFile(m_pInternal->m_wsSrcPath))
{
m_pInternal->m_nFileLength = oFile.GetFileSize();
oFile.CloseFile();
}
} }
return bRes; return bRes;

View File

@ -2222,6 +2222,14 @@ void CPdfRenderer::Sign(const double& dX, const double& dY, const double& dW, co
m_pDocument->Sign(TRect(MM_2_PT(dX), m_pPage->GetHeight() - MM_2_PT(dY), MM_2_PT(dX + dW), m_pPage->GetHeight() - MM_2_PT(dY + dH)), m_pDocument->Sign(TRect(MM_2_PT(dX), m_pPage->GetHeight() - MM_2_PT(dY), MM_2_PT(dX + dW), m_pPage->GetHeight() - MM_2_PT(dY + dH)),
pImage, pCertificate); pImage, pCertificate);
} }
std::wstring CPdfRenderer::GetEditPdfPath()
{
if (!m_bEdit)
{
return L"";
}
return m_pDocument->GetEditPdfPath();
}
NSFonts::IApplicationFonts* CPdfRenderer::GetApplicationFonts() NSFonts::IApplicationFonts* CPdfRenderer::GetApplicationFonts()
{ {

View File

@ -241,6 +241,7 @@ public:
bool EditClose(const std::wstring& sTrailer, const std::wstring& sInfo); bool EditClose(const std::wstring& sTrailer, const std::wstring& sInfo);
void PageRotate(int nRotate); void PageRotate(int nRotate);
void Sign(const double& dX, const double& dY, const double& dW, const double& dH, const std::wstring& wsPicturePath, ICertificate* pCertificate); void Sign(const double& dX, const double& dY, const double& dW, const double& dH, const std::wstring& wsPicturePath, ICertificate* pCertificate);
std::wstring GetEditPdfPath();
NSFonts::IApplicationFonts* GetApplicationFonts(); NSFonts::IApplicationFonts* GetApplicationFonts();

View File

@ -160,6 +160,7 @@ namespace PdfWriter
bool DeletePage(int nPageIndex); bool DeletePage(int nPageIndex);
bool AddToFile(const std::wstring& sTrailer, const std::wstring& sInfo); bool AddToFile(const std::wstring& sTrailer, const std::wstring& sInfo);
void Sign(const TRect& oRect, CImageDict* pImage, ICertificate* pCert); void Sign(const TRect& oRect, CImageDict* pImage, ICertificate* pCert);
std::wstring GetEditPdfPath() { return m_wsFilePath; }
private: private:
char* GetTTFontTag(); char* GetTTFontTag();

View File

@ -109,7 +109,10 @@ int main()
return 0; return 0;
} }
if (bResult && pReader->EditPdf(&pdfWriter, sSrcFile, sPassword)) bool bNewDstFile = false;
if (bNewDstFile)
NSFile::CFileBinary::Copy(sSrcFile, sDstFile);
if (bResult && pReader->EditPdf(&pdfWriter, bNewDstFile ? sDstFile : sSrcFile, sPassword))
{ {
if (true && pCertificate) if (true && pCertificate)
{ {