mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
pdf fix number of signature
This commit is contained in:
@ -53,6 +53,7 @@
|
||||
#include "lib/xpdf/SecurityHandler.h"
|
||||
#include "lib/xpdf/Lexer.h"
|
||||
#include "lib/xpdf/Parser.h"
|
||||
#include "lib/xpdf/AcroForm.h"
|
||||
#include "Src/RendererOutputDev.h"
|
||||
|
||||
#ifdef BUILDING_WASM_MODULE
|
||||
@ -529,6 +530,11 @@ return 0;
|
||||
sCatalog.clear();
|
||||
Ref catRef = catRefObj.getRef();
|
||||
|
||||
unsigned int nFormField = 0;
|
||||
AcroForm* form = m_pInternal->m_pPDFDocument->getCatalog()->getForm();
|
||||
if (form)
|
||||
nFormField = form->getNumFields();
|
||||
|
||||
int nCryptAlgorithm = -1;
|
||||
std::wstring sEncrypt = L"<Encrypt";
|
||||
if (xref->isEncrypted())
|
||||
@ -567,7 +573,7 @@ return 0;
|
||||
if (sEncrypt == L"<Encrypt></Encrypt>")
|
||||
sEncrypt.clear();
|
||||
|
||||
bool bRes = m_pInternal->m_pPdfWriter->EditPdf(xref->getLastXRefPos(), xref->getNumObjects(), sCatalog, std::make_pair(catRef.num, catRef.gen), sEncrypt, sPassword, nCryptAlgorithm);
|
||||
bool bRes = m_pInternal->m_pPdfWriter->EditPdf(xref->getLastXRefPos(), xref->getNumObjects(), sCatalog, std::make_pair(catRef.num, catRef.gen), sEncrypt, sPassword, nCryptAlgorithm, nFormField);
|
||||
if (bRes)
|
||||
m_pInternal->GetPageTree(xref, &pagesRefObj);
|
||||
pagesRefObj.free();
|
||||
|
||||
@ -2094,9 +2094,9 @@ HRESULT CPdfRenderer::DrawImageWith1bppMask(IGrObject* pImage, NSImages::CPixJbi
|
||||
m_pPage->GrRestore();
|
||||
return S_OK;
|
||||
}
|
||||
bool CPdfRenderer::EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, const std::pair<int, int>& pCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm)
|
||||
bool CPdfRenderer::EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, const std::pair<int, int>& pCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm, int nFormField)
|
||||
{
|
||||
return m_pDocument->EditPdf(nPosLastXRef, nSizeXRef, sCatalog, pCatalog, sEncrypt, sPassword, nCryptAlgorithm);
|
||||
return m_pDocument->EditPdf(nPosLastXRef, nSizeXRef, sCatalog, pCatalog, sEncrypt, sPassword, nCryptAlgorithm, nFormField);
|
||||
}
|
||||
bool CPdfRenderer::CreatePageTree(const std::wstring& sPageTree, const std::pair<int, int>& pPageTree)
|
||||
{
|
||||
|
||||
@ -231,7 +231,7 @@ public:
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Дополнительные функции для дозаписи Pdf
|
||||
//----------------------------------------------------------------------------------------
|
||||
bool EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, const std::pair<int, int>& pCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm);
|
||||
bool EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, const std::pair<int, int>& pCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm, int nFormField);
|
||||
bool CreatePageTree(const std::wstring& sPageTree, const std::pair<int, int>& pPageTree);
|
||||
std::pair<int, int> GetPageRef(int nPageIndex);
|
||||
bool EditPage(const std::wstring& sPage, const std::pair<int, int>& pPage);
|
||||
|
||||
@ -79,6 +79,7 @@ namespace PdfWriter
|
||||
m_pPageTree = NULL;
|
||||
m_pCurPage = NULL;
|
||||
m_nCurPageNum = -1;
|
||||
m_unFormFields = 0;
|
||||
m_pInfo = NULL;
|
||||
m_pTrailer = NULL;
|
||||
m_pResources = NULL;
|
||||
@ -183,6 +184,7 @@ namespace PdfWriter
|
||||
m_pPageTree = NULL;
|
||||
m_pCurPage = NULL;
|
||||
m_nCurPageNum = 0;
|
||||
m_unFormFields = 0;
|
||||
m_bEncrypt = false;
|
||||
m_pEncryptDict = NULL;
|
||||
m_pInfo = NULL;
|
||||
@ -1087,7 +1089,7 @@ namespace PdfWriter
|
||||
|
||||
return (!!m_pAcroForm);
|
||||
}
|
||||
bool CDocument::EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, const std::pair<int, int>& pCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm)
|
||||
bool CDocument::EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, const std::pair<int, int>& pCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm, int nFormField)
|
||||
{
|
||||
Close();
|
||||
|
||||
@ -1134,6 +1136,7 @@ namespace PdfWriter
|
||||
m_bEncrypt = true;
|
||||
}
|
||||
|
||||
m_unFormFields = nFormField;
|
||||
return true;
|
||||
}
|
||||
bool CDocument::CreatePageTree(const std::wstring& sPageTree, const std::pair<int, int>& pPageTree)
|
||||
@ -1338,7 +1341,7 @@ namespace PdfWriter
|
||||
pField->GetSignatureDict()->SetCert(m_vSignatures[i].pCertificate);
|
||||
pField->AddPageRect(m_vSignatures[i].pPage, m_vSignatures[i].oRect);
|
||||
pField->Add("F", 132);
|
||||
pField->SetFieldName("Sig" + std::to_string(i + 1));
|
||||
pField->SetFieldName("Sig" + std::to_string(i + m_unFormFields + 1));
|
||||
if (m_vSignatures[i].pImage)
|
||||
pField->SetAppearance(m_vSignatures[i].pImage);
|
||||
|
||||
|
||||
@ -152,7 +152,7 @@ namespace PdfWriter
|
||||
CSignatureField* CreateSignatureField();
|
||||
bool CheckFieldName(CFieldBase* pField, const std::string& sName);
|
||||
|
||||
bool EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, const std::pair<int, int>& pCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm);
|
||||
bool EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, const std::pair<int, int>& pCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm, int nFormField);
|
||||
bool CreatePageTree(const std::wstring& sPageTree, const std::pair<int, int>& pPageTree);
|
||||
std::pair<int, int> GetPageRef(int nPageIndex);
|
||||
CPage* EditPage(const std::wstring& sPage, const std::pair<int, int>& pPage);
|
||||
@ -220,6 +220,7 @@ namespace PdfWriter
|
||||
bool m_bEncrypt;
|
||||
CEncryptDict* m_pEncryptDict;
|
||||
std::vector<TSignatureInfo> m_vSignatures;
|
||||
unsigned int m_unFormFields;
|
||||
unsigned int m_unCompressMode;
|
||||
std::vector<CExtGrState*> m_vExtGrStates;
|
||||
std::vector<CExtGrState*> m_vStrokeAlpha;
|
||||
|
||||
@ -110,33 +110,42 @@ int main()
|
||||
*/
|
||||
if (bResult && pReader->EditPdf(&pdfWriter, sPassword))
|
||||
{
|
||||
if (pReader->EditPage(0))
|
||||
if (pCertificate)
|
||||
{
|
||||
TEST(&pdfWriter);
|
||||
pdfWriter.PageRotate(90);
|
||||
if (pCertificate)
|
||||
pdfWriter.Sign(10, 10, 50, 50, NSFile::GetProcessDirectory() + L"/test.jpg", pCertificate);
|
||||
// Подпись не позволяет вносить иные изменения кроме заполнения форм, подписания и комментирования документы
|
||||
if (pReader->EditPage(0))
|
||||
{
|
||||
pdfWriter.Sign(10, 70, 50, 50, NSFile::GetProcessDirectory() + L"/test.png", pCertificate);
|
||||
}
|
||||
}
|
||||
|
||||
pReader->DeletePage(1);
|
||||
|
||||
if (pReader->EditPage(1))
|
||||
else
|
||||
{
|
||||
TEST3(&pdfWriter);
|
||||
}
|
||||
if (pReader->EditPage(0))
|
||||
{
|
||||
TEST(&pdfWriter);
|
||||
pdfWriter.PageRotate(90);
|
||||
}
|
||||
|
||||
if (pReader->EditPage(2))
|
||||
{
|
||||
TEST2(&pdfWriter);
|
||||
}
|
||||
pReader->DeletePage(1);
|
||||
|
||||
if (pReader->AddPage(3))
|
||||
{
|
||||
// Новой странице необходимо выставить длину и ширину
|
||||
pdfWriter.put_Width(dWidth);
|
||||
pdfWriter.put_Height(dHeight);
|
||||
if (pReader->EditPage(1))
|
||||
{
|
||||
TEST3(&pdfWriter);
|
||||
}
|
||||
|
||||
TEST(&pdfWriter);
|
||||
if (pReader->EditPage(2))
|
||||
{
|
||||
TEST2(&pdfWriter);
|
||||
}
|
||||
|
||||
if (pReader->AddPage(3))
|
||||
{
|
||||
// Новой странице необходимо выставить длину и ширину
|
||||
pdfWriter.put_Width(dWidth);
|
||||
pdfWriter.put_Height(dHeight);
|
||||
|
||||
TEST(&pdfWriter);
|
||||
}
|
||||
}
|
||||
|
||||
NSFile::CFileBinary::Copy(sSrcFile, sDstFile);
|
||||
|
||||
Reference in New Issue
Block a user