diff --git a/PdfFile/PdfEditor.cpp b/PdfFile/PdfEditor.cpp index e2769bb56b..ce3e67d411 100644 --- a/PdfFile/PdfEditor.cpp +++ b/PdfFile/PdfEditor.cpp @@ -43,6 +43,7 @@ #include "lib/xpdf/Parser.h" #include "lib/xpdf/Outline.h" #include "lib/xpdf/Link.h" +#include "lib/xpdf/Stream.h" #include "SrcWriter/Catalog.h" #include "SrcWriter/EncryptDictionary.h" @@ -3529,19 +3530,14 @@ bool CPdfEditor::IsBase14(const std::wstring& wsFontName, bool& bBold, bool& bIt void CPdfEditor::Redact(IAdvancedCommand* _pCommand) { PdfWriter::CDocument* pDoc = m_pWriter->GetDocument(); - int nOriginIndex = m_nEditPage; + PdfWriter::CPage* pWPage = NULL; if (m_nMode == Mode::WriteNew) - { - PdfWriter::CPageTree* pPageTree = pDoc->GetPageTree(); - PdfWriter::CObjectBase* pObj = pPageTree->GetObj(m_nEditPage); - PdfWriter::CFakePage* pFakePage = NULL; - if (pObj) - pFakePage = dynamic_cast(pObj); - if (pFakePage) - nOriginIndex = pFakePage->GetOriginIndex(); - } + pWPage = pDoc->GetPage(m_nEditPage); + if (!pWPage) + return; + PDFDoc* pPDFDocument = NULL; - int nPageIndex = m_pReader->GetPageIndex(nOriginIndex, &pPDFDocument); + int nPageIndex = m_pReader->GetPageIndex(m_nEditPage, &pPDFDocument); if (nPageIndex < 0 || !pPDFDocument) return; Page* pPage = pPDFDocument->getCatalog()->getPage(nPageIndex); @@ -3558,7 +3554,50 @@ void CPdfEditor::Redact(IAdvancedCommand* _pCommand) arrQuads[i * 4 + 3] = cropBox->y2 - dQ; } - Redact(arrQuads); +#ifndef BUILDING_WASM_MODULE + //globalParams->setDrawFormFields(gFalse); + //globalParams->setDrawAnnotations(gFalse); + + PdfWriter::RedactOutputDev oRedactOut(m_pWriter); + oRedactOut.NewPDF(pPDFDocument->getXRef()); + oRedactOut.SetRedact(arrQuads); + + PDFRectangle* box = pPage->getMediaBox(); + // TODO есть проблема с ресурсами - здесть только исходные ресурсы, без новых дописанных + Gfx* gfx = new Gfx(pPDFDocument, &oRedactOut, nPageIndex, pPage->getResourceDict(), 72.0, 72.0, box, NULL, 0); + + PdfWriter::CArrayObject* pContents = (PdfWriter::CArrayObject*)pWPage->Get("Contents"); + Object oContents; + oContents.initArray(NULL); + for (int i = 0; i < pContents->GetCount(); ++i) + { + PdfWriter::CObjectBase* pObj = pContents->Get(i); + PdfWriter::CDictObject* pDict = NULL; + if (pObj->GetType() == PdfWriter::object_type_DICT) + pDict = (PdfWriter::CDictObject*)pObj; + if (!pDict) + continue; + PdfWriter::CStream* pStream = pDict->GetStream(); + unsigned int nSize = pStream->Size(); + BYTE* pData = new BYTE[nSize]; + pStream->Read(pData, &nSize); + + Object obj, oContent; + obj.initNull(); + Stream* pContentStream = new MemStream((char*)pData, 0, nSize, &obj, gTrue); + oContent.initStream(pContentStream); + oContents.arrayAdd(&oContent); + } + gfx->display(&oContents); + oContents.free(); + + RELEASEOBJECT(gfx); + + //pPDFDocument->displayPage(&oRedactOut, nPageIndex, 72.0, 72.0, 0, gTrue, gFalse, gFalse); + + //globalParams->setDrawFormFields(gTrue); + //globalParams->setDrawAnnotations(gTrue); +#endif int nFlags = pCommand->GetFlag(); if (nFlags & (1 << 0)) @@ -3613,35 +3652,3 @@ void CPdfEditor::Redact(IAdvancedCommand* _pCommand) */ } } -void CPdfEditor::Redact(const std::vector& arrQuadPoints) -{ - PdfWriter::CDocument* pDoc = m_pWriter->GetDocument(); - int nOriginIndex = m_nEditPage; - if (m_nMode == Mode::WriteNew) - { - PdfWriter::CPageTree* pPageTree = pDoc->GetPageTree(); - PdfWriter::CObjectBase* pObj = pPageTree->GetObj(m_nEditPage); - PdfWriter::CFakePage* pFakePage = NULL; - if (pObj) - pFakePage = dynamic_cast(pObj); - if (pFakePage) - nOriginIndex = pFakePage->GetOriginIndex(); - } - PDFDoc* pPDFDocument = NULL; - int nPageIndex = m_pReader->GetPageIndex(nOriginIndex, &pPDFDocument); - if (nPageIndex < 0 || !pPDFDocument) - return; - -#ifndef BUILDING_WASM_MODULE - globalParams->setDrawFormFields(gFalse); - globalParams->setDrawAnnotations(gFalse); - - PdfWriter::RedactOutputDev oRedactOut(m_pWriter); - oRedactOut.NewPDF(pPDFDocument->getXRef()); - oRedactOut.SetRedact(arrQuadPoints); - pPDFDocument->displayPage(&oRedactOut, nPageIndex, 72.0, 72.0, 0, gTrue, gFalse, gFalse); - - globalParams->setDrawFormFields(gTrue); - globalParams->setDrawAnnotations(gTrue); -#endif -} diff --git a/PdfFile/PdfEditor.h b/PdfFile/PdfEditor.h index 231a82b630..eb1e1382c4 100644 --- a/PdfFile/PdfEditor.h +++ b/PdfFile/PdfEditor.h @@ -101,7 +101,6 @@ public: void EndMarkedContent(); bool IsBase14(const std::wstring& wsFontName, bool& bBold, bool& bItalic, std::wstring& wsFontPath); void Redact(IAdvancedCommand* pCommand); - void Redact(const std::vector& arrQuadPoints); bool SplitPages(const int* arrPageIndex, unsigned int unLength); void AfterSplitPages(); diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 289b85e423..1a1ca330f7 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -1367,7 +1367,3 @@ HRESULT CPdfFile::AdvancedCommand(IAdvancedCommand* command) } return S_FALSE; } -void CPdfFile::Redact(const std::vector& arrQuadPoints) -{ - m_pInternal->pEditor->Redact(arrQuadPoints); -} diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index 74bb4e545d..6aea19c287 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -306,9 +306,6 @@ public: virtual HRESULT IsSupportAdvancedCommand(const IAdvancedCommand::AdvancedCommandType& type); virtual HRESULT AdvancedCommand(IAdvancedCommand* command); - // TEST - void Redact(const std::vector& arrQuadPoints); - private: CPdfFile_Private* m_pInternal; };