summaryrefslogtreecommitdiff
path: root/vcl/source
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-12-13 23:26:43 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-12-26 06:08:01 +0100
commita30330702d4dcafab3f8b0deae2485997e28a01d (patch)
tree4d9cf68145d599d0759af20dfec889859eb60421 /vcl/source
parentf45401ce130f1377163e977f52b037b7b46b4910 (diff)
pdf: Fix embedded files when the PDF is encrypted
When we encrypt the PDF and want to attach the ODF document to the PDF, the PDF file would not have any attachments when opened. This is because the encryption for the attachments and embedded files was not done correctly. This patch fixes this issue. Change-Id: I5bd8175f6067b8b684defa3b60746176f4314c8c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178447 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178771 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/source')
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx52
1 files changed, 25 insertions, 27 deletions
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index faf795fa60c7..cee972efb2fe 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -5233,26 +5233,28 @@ bool PDFWriterImpl::emitEmbeddedFiles()
aLine.append(" /Params ");
appendObjectReference(nParamsObject, aLine);
aLine.append(">>\nstream\n");
- checkAndEnableStreamEncryption(rEmbeddedFile.m_nObject);
if (!writeBuffer(aLine)) return false;
- disableStreamEncryption();
aLine.setLength(0);
sal_Int64 nSize{};
if (!rEmbeddedFile.m_aDataContainer.isEmpty())
{
nSize = rEmbeddedFile.m_aDataContainer.getSize();
+ checkAndEnableStreamEncryption(rEmbeddedFile.m_nObject);
if (!writeBufferBytes(rEmbeddedFile.m_aDataContainer.getData(), rEmbeddedFile.m_aDataContainer.getSize()))
return false;
+ disableStreamEncryption();
}
else if (rEmbeddedFile.m_pStream)
{
+ checkAndEnableStreamEncryption(rEmbeddedFile.m_nObject);
sal_uInt64 nBegin = getCurrentFilePosition();
css::uno::Reference<css::io::XOutputStream> xStream(new PDFStreamIf(this));
rEmbeddedFile.m_pStream->write(xStream);
rEmbeddedFile.m_pStream.reset();
xStream.clear();
nSize = sal_Int64(getCurrentFilePosition() - nBegin);
+ disableStreamEncryption();
}
aLine.append("\nendstream\nendobj\n\n");
if (!writeBuffer(aLine)) return false;
@@ -5361,29 +5363,26 @@ bool PDFWriterImpl::emitCatalog()
{
if (!updateObject(rAttachedFile.mnObjectId))
return false;
- aLine.setLength( 0 );
+ aLine.setLength(0);
- appendObjectID(rAttachedFile.mnObjectId, aLine);
- aLine.append("<</Type /Filespec");
- aLine.append("/F<");
- COSWriter::appendUnicodeTextString(rAttachedFile.maFilename, aLine);
- aLine.append("> ");
+ aWriter.startObject(rAttachedFile.mnObjectId);
+ aWriter.startDict();
+ aWriter.write("/Type", "/Filespec");
+ aWriter.writeKeyAndUnicodeEncrypt("/F", rAttachedFile.maFilename, rAttachedFile.mnObjectId);
if (PDFWriter::PDFVersion::PDF_1_7 <= m_aContext.Version)
{
- aLine.append("/UF<");
- COSWriter::appendUnicodeTextString(rAttachedFile.maFilename, aLine);
- aLine.append("> ");
+ aWriter.writeKeyAndUnicodeEncrypt("/UF", rAttachedFile.maFilename, rAttachedFile.mnObjectId);
}
if (!rAttachedFile.maDescription.isEmpty())
{
- aLine.append("/Desc <");
- COSWriter::appendUnicodeTextString(rAttachedFile.maDescription, aLine);
- aLine.append("> ");
+ aWriter.writeKeyAndUnicodeEncrypt("/Desc", rAttachedFile.maDescription, rAttachedFile.mnObjectId);
}
- aLine.append("/EF <</F ");
- appendObjectReference(rAttachedFile.mnEmbeddedFileObjectId, aLine);
- aLine.append(">>");
- aLine.append(">>\nendobj\n\n");
+ aLine.append("/EF");
+ aWriter.startDict();
+ aWriter.writeKeyAndReference("/F", rAttachedFile.mnEmbeddedFileObjectId);
+ aWriter.endDict();
+ aWriter.endDict();
+ aWriter.endObject();
if (!writeBuffer(aLine)) return false;
}
@@ -5408,18 +5407,17 @@ bool PDFWriterImpl::emitCatalog()
if (!m_aDocumentAttachedFiles.empty())
{
- aLine.append("/Names ");
- aLine.append("<</EmbeddedFiles <</Names [");
+ aWriter.startDictWithKey("/Names");
+ aWriter.startDictWithKey("/EmbeddedFiles");
+ aLine.append("/Names [");
for (auto & rAttachedFile : m_aDocumentAttachedFiles)
{
- aLine.append('<');
- COSWriter::appendUnicodeTextString(rAttachedFile.maFilename, aLine);
- aLine.append('>');
- aLine.append(' ');
- appendObjectReference(rAttachedFile.mnObjectId, aLine);
+ aWriter.writeUnicodeEncrypt(rAttachedFile.maFilename, m_nCatalogObject);
+ aWriter.writeReference(rAttachedFile.mnObjectId);
}
- aLine.append("]>>>>");
- aLine.append("\n" );
+ aLine.append("]");
+ aWriter.endDict();
+ aWriter.endDict();
}
if( m_aContext.PageLayout != PDFWriter::DefaultLayout )