Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Sep 26, 2019 10:12 pm

Hi!

I have one encrypted file called "EncryptedFile.pdf" (attached) wich your password is 550.

Using the C# line code:
EncryptedFilePdfDocument.Security.Encrypt(String.Empty)

I save your decrypted version called "DecryptedFile.pdf" (attached too). I can open it in Chrome, for example, without problem.

When I try build a large PdfDocument using DecryptedFile like this:

PdfDocument FinalPDF= new PdfDocument();

for (Int32 Counter = 0; Counter < DecryptedFilePdfDocument.Pages.Count; Counter++)
{
FinalPDF.InsertPage(DecryptedFilePdfDocument, Counter);
}

I receive the error code:

Invalid contents array.

[PdfDocumentException: Invalid contents array.]
Spire.Pdf.PdfPageLayerCollection.ᜀ(PdfPageWidget A_0) +1208
Spire.Pdf.PdfPageLayerCollection..ctor(PdfPageBase page) +116
Spire.Pdf.PdfPageBase.get_PageLayers() +85
Spire.Pdf.PdfPageBase.᜛() +84
Spire.Pdf.Widget.PdfPageCollection.ᜀ(PdfDocumentBase A_0, PdfPageBase A_1, List`1 A_2) +695
Spire.Pdf.PdfNewDocument.ClonePage(PdfDocumentBase ldDoc, PdfPageBase page, List`1 destinations) +40
Spire.Pdf.PdfDocumentBase.ImportPageRange(PdfDocumentBase ldDoc, Int32 startIndex, Int32 endIndex) +2068
Spire.Pdf.PdfDocumentBase.ImportPage(PdfDocumentBase ldDoc, Int32 pageIndex) +135
Spire.Pdf.PdfDocument.InsertPage(PdfDocument doc, Int32 pageIndex) +47
GEDArquivoDokks.GED.Arquivos.PastaArquivoDokks.GerarRelatorio(List`1 pListaDoCaminhoDoArquivoDokks) +452
GEDArquivoDokks.GEDDownloadArquivoDokks.DownloadPastaArquivoDokks(String pLoteDeIDsArquivoDokks) +653
GEDArquivoDokks.GEDDownloadArquivoDokks.Page_Load(Object sender, EventArgs e) +557
System.Web.UI.Control.OnLoad(EventArgs e) +103
System.Web.UI.Control.LoadRecursive() +68
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3811

This occur just when I use the drecypted file - with the others I don't have any problem.

(the Spire.Pdf.dll version is 5.4.9.2040)

Thanks for your attention.

RuiBarbosa
 
Posts: 19
Joined: Thu Apr 18, 2019 12:23 pm

Fri Sep 27, 2019 9:27 am

Hi,

Thanks for your inquiry.
I decrypted your encrypted file(EncryptedFile.pdf) then merge it to a document using Spire.PDF Pack(Hot Fix) Version:5.9.6 but didn't reproduce your issue. I also tested your files using Spire.Pdf_5.4.9, there is no issue as well. I suggest you try to use the latest version of Spire.Pdf which has more improvements than old versions. And below is my code for your reference.

Code: Select all
            //use the open password to load the encrypted PDF file
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(@"……\EncryptedFile.pdf", "550");

            //set the password as empty to decrypt PDF
            pdf.Security.Encrypt(string.Empty);

            //save the document to file
            pdf.SaveToFile("19033-Decrypt.pdf", FileFormat.PDF);

            //Merge the decrypted files
            String[] files = new String[]
            {
                //the file I decrypted from your encrypted file(EncryptedFile.pdf)
                @"……\19033-Decrypt.pdf",
                //the decrypted file you offered
                @"……\DecryptedFile.pdf",
            };

            PdfDocument[] docs = new PdfDocument[files.Length];
            for (int i = 0; i < files.Length; i++)
            {
                docs[i] = new PdfDocument(files[i]);
            }

            //import page
            for (Int32 i = 0; i < docs[1].Pages.Count; i++)
            {
                docs[0].InsertPage(docs[1], i);
            }

            //save to Pdf file
            docs[0].SaveToFile("MergeDocuments.pdf");


If the issue still exists after trying the latest version, to help us investigate your issue accurately, please offer us the following information.
1. All of your input merge files(if any).
2. The complete code you were using which could reproduce your issue directly.
3. The OS and Region information, e.g. win7 64bit, China/Chinese.
You could upload them here or send us([email protected]) via email.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Fri Sep 27, 2019 12:35 pm

Amber,

indeed, the code is really working well. The problem was in another part of the code. We are stamping this document and was a little detail that was causing the error.

I would like to thank you for your attention.

Best wishes,

Campêlo

RuiBarbosa
 
Posts: 19
Joined: Thu Apr 18, 2019 12:23 pm

Sun Sep 29, 2019 6:16 am

Hi,

Thanks for your reply.
Have you solved this issue by yourself? If not, to help us investigate your issue accurately, could you please offer us the following information?
1. The complete code you were using which could reproduce your issue directly.
2. If the input Pdf file you were using now is different from the one you provided before, please provide to us.
You could upload them here or send us([email protected]) via email.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.PDF