From c057c8eb2450d232b5e1779d662f70f0b306d115 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Fri, 6 Mar 2026 14:08:36 +0300 Subject: [PATCH] Create RedacctInfo --- PdfFile/OnlineOfficeBinToPdf.cpp | 6 ++++++ PdfFile/PdfEditor.cpp | 10 ++++++++++ PdfFile/PdfEditor.h | 2 ++ PdfFile/PdfFile.cpp | 8 +++++++- PdfFile/PdfFile.h | 1 + PdfFile/SrcWriter/Document.cpp | 5 +++++ PdfFile/SrcWriter/Document.h | 2 ++ 7 files changed, 33 insertions(+), 1 deletion(-) diff --git a/PdfFile/OnlineOfficeBinToPdf.cpp b/PdfFile/OnlineOfficeBinToPdf.cpp index e79e8a0a26..20eba7d1eb 100644 --- a/PdfFile/OnlineOfficeBinToPdf.cpp +++ b/PdfFile/OnlineOfficeBinToPdf.cpp @@ -153,6 +153,7 @@ namespace NSOnlineOfficeBinToPdf MovePage = 4, MergePages = 5, SetType = 6, + RedactInfo = 7, Undefined = 255 }; @@ -250,6 +251,11 @@ namespace NSOnlineOfficeBinToPdf pPdf->SetEditType(1); break; } + case AddCommandType::RedactInfo: + { + pPdf->RedactInfo(nPageNum); + break; + } default: return false; } diff --git a/PdfFile/PdfEditor.cpp b/PdfFile/PdfEditor.cpp index 844288193c..3f064f9f70 100644 --- a/PdfFile/PdfEditor.cpp +++ b/PdfFile/PdfEditor.cpp @@ -1053,6 +1053,7 @@ CPdfEditor::CPdfEditor(const std::wstring& _wsSrcFile, const wchar_t* _wsPasswor m_nEditPage = -1; m_nError = 0; m_nMode = Mode::Unknown; + m_nRedactInfo = 0; PDFDoc* pPDFDocument = m_pReader->GetPDFDocument(0); if (!pPDFDocument) @@ -1082,6 +1083,7 @@ void CPdfEditor::SetMode(Mode nMode) else if (m_nMode == Mode::WriteNew) { PdfWriter::CDocument* pDoc = m_pWriter->GetDocument(); + pDoc->CreateNew(); PdfWriter::CPageTree* pPageTree = pDoc->GetPageTree(); m_mObjManager.SetDoc(pDoc); int nPages = m_pReader->GetNumPages(); @@ -1091,6 +1093,13 @@ void CPdfEditor::SetMode(Mode nMode) NewFrom(); } } +void CPdfEditor::RedactInfo(int nFlag) +{ + if (m_nMode != Mode::Unknown) + return; + m_pWriter->GetDocument()->RedactInfo(nFlag); + m_nRedactInfo = nFlag; +} bool CPdfEditor::IncrementalUpdates() { if (m_nMode != Mode::Unknown) @@ -1100,6 +1109,7 @@ bool CPdfEditor::IncrementalUpdates() PDFDoc* pPDFDocument = m_pReader->GetPDFDocument(0); XRef* xref = pPDFDocument->getXRef(); PdfWriter::CDocument* pDoc = m_pWriter->GetDocument(); + pDoc->CreateNew(); std::string sPathUtf8New = U_TO_UTF8(m_wsDstFile); std::string sPathUtf8Old = U_TO_UTF8(m_wsSrcFile); diff --git a/PdfFile/PdfEditor.h b/PdfFile/PdfEditor.h index c0636802f2..b9f662f38e 100644 --- a/PdfFile/PdfEditor.h +++ b/PdfFile/PdfEditor.h @@ -82,6 +82,7 @@ public: CPdfEditor(const std::wstring& _wsSrcFile, const wchar_t* _wsPassword, const std::wstring& _wsDstFile, CPdfReader* _pReader, CPdfWriter* _pWriter, Mode nMode = Mode::Unknown); void SetMode(Mode nMode); + void RedactInfo(int nFlag); int GetError(); void Close(); @@ -140,6 +141,7 @@ private: // 0 - Дозапись. pReader и pWriter работают с одним файлом // 1 - Split. pReader и pWriter работают с разными файлами Mode m_nMode; + int m_nRedactInfo; int m_nEditPage; int m_nOriginIndex; }; diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 257eecd0ff..8bd516d79c 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -140,7 +140,7 @@ bool CPdfFile::EditPdf(const std::wstring& wsDstFile) m_pInternal->pReader->CleanUp(); RELEASEOBJECT(m_pInternal->pWriter); - m_pInternal->pWriter = new CPdfWriter(m_pInternal->pAppFonts, false, this, true, m_pInternal->wsTempFolder); + m_pInternal->pWriter = new CPdfWriter(m_pInternal->pAppFonts, false, this, false, m_pInternal->wsTempFolder); RELEASEOBJECT(m_pInternal->pEditor); m_pInternal->pEditor = new CPdfEditor(m_pInternal->wsSrcFile, m_pInternal->wsPassword, wsDstFile, m_pInternal->pReader, m_pInternal->pWriter); @@ -159,6 +159,12 @@ void CPdfFile::SetEditType(int nType) if (nType == 1) m_pInternal->pEditor->SetMode(CPdfEditor::Mode::WriteNew); } +void CPdfFile::RedactInfo(int nFlag) +{ + if (!m_pInternal->pEditor) + return; + m_pInternal->pEditor->RedactInfo(nFlag); +} bool CPdfFile::EditPage(int nPageIndex) { if (!m_pInternal->pEditor) diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index 384c2983b2..d4f4b23178 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -102,6 +102,7 @@ public: bool EditPdf(const std::wstring& wsDstFile = L""); void EditClose(); void SetEditType(int nType); + void RedactInfo(int nFlag); // Манипуляции со страницами возможны в режиме редактирования bool EditPage (int nPageIndex); bool DeletePage(int nPageIndex); diff --git a/PdfFile/SrcWriter/Document.cpp b/PdfFile/SrcWriter/Document.cpp index a240016f09..8b094bbae5 100644 --- a/PdfFile/SrcWriter/Document.cpp +++ b/PdfFile/SrcWriter/Document.cpp @@ -95,6 +95,7 @@ namespace PdfWriter m_pTransparencyGroup = NULL; m_pFreeTypeLibrary = NULL; m_bPDFAConformance = false; + m_nRedactInfo = 0; m_pAcroForm = NULL; m_pFieldsResources = NULL; } @@ -496,6 +497,10 @@ namespace PdfWriter { m_bPDFAConformance = isPDFA; } + void CDocument::SetRedactInfo(int nFlag) + { + m_nRedactInfo = nFlag; + } bool CDocument::IsPDFA() const { return m_bPDFAConformance; diff --git a/PdfFile/SrcWriter/Document.h b/PdfFile/SrcWriter/Document.h index 24e9fa9f84..79c35b4dab 100644 --- a/PdfFile/SrcWriter/Document.h +++ b/PdfFile/SrcWriter/Document.h @@ -123,6 +123,7 @@ namespace PdfWriter void SetKeywords(const std::string& sKeywords); void SetPDFAConformanceMode(bool isPDFA); + void SetRedactInfo(int nFlag); bool IsPDFA() const; CPage* AddPage(); @@ -344,6 +345,7 @@ namespace PdfWriter std::vector m_vFreeTypeFonts; FT_Library m_pFreeTypeLibrary; bool m_bPDFAConformance; + int m_nRedactInfo; std::wstring m_wsDocumentID; CDictObject* m_pAcroForm; CResourcesDict* m_pFieldsResources;