filter/source/pdf/pdfexport.cxx   |    2 -
 vcl/inc/pdf/COSWriter.hxx         |    5 +++
 vcl/source/gdi/pdfwriter_impl.cxx |   52 ++++++++++++++++++--------------------
 3 files changed, 31 insertions(+), 28 deletions(-)

New commits:
commit 5719a09bcbffa7ad0e1bedb19f4046aadfc38ce4
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Dec 16 22:58:35 2024 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Dec 26 06:08:10 2024 +0100

    pdf: use "Default" enum value for PDF version when 0 is passed
    
    0 means to not use any specific version so always use the version
    that is set as default here.
    
    Change-Id: I1aa9aac9c67fdd8c8334f581f1b8b93a43e5c3ee
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178591
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178772
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx
index cca7703c50c8..8827971fcda5 100644
--- a/filter/source/pdf/pdfexport.cxx
+++ b/filter/source/pdf/pdfexport.cxx
@@ -752,7 +752,7 @@ bool PDFExport::Export( const OUString& rFile, const 
Sequence< PropertyValue >&
             {
             default:
             case 0:
-                aContext.Version = vcl::PDFWriter::PDFVersion::PDF_1_7;
+                aContext.Version = vcl::PDFWriter::PDFVersion::Default;
                 break;
             case 1:
                 aContext.Version = vcl::PDFWriter::PDFVersion::PDF_A_1;
commit a30330702d4dcafab3f8b0deae2485997e28a01d
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Dec 13 23:26:43 2024 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Dec 26 06:08:01 2024 +0100

    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 <vmik...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178771
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/vcl/inc/pdf/COSWriter.hxx b/vcl/inc/pdf/COSWriter.hxx
index 2142de1f846e..d63a2198a2e7 100644
--- a/vcl/inc/pdf/COSWriter.hxx
+++ b/vcl/inc/pdf/COSWriter.hxx
@@ -72,6 +72,11 @@ public:
     OStringBuffer& getLine() { return mrBuffer; }
 
     void startDict() { mrBuffer.append("<<"); }
+    void startDictWithKey(std::string_view key)
+    {
+        mrBuffer.append(key);
+        mrBuffer.append("<<");
+    }
     void endDict() { mrBuffer.append(">>
"); }
 
     void startStream() { mrBuffer.append("stream
"); }
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(">>
stream
");
-        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("
endstream
endobj

");
         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(">>
endobj

");
+        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("
" );
+        aLine.append("]");
+        aWriter.endDict();
+        aWriter.endDict();
     }
 
     if( m_aContext.PageLayout != PDFWriter::DefaultLayout )

Reply via email to