Unable to print PDF after concatenation

I am concatenating two or more memory streams using the PDFEditor into a single memory stream. I am then saving the concatenated memory stream to a file. However, when I attempt to print it, the print option is grayed out. The code I am using is as follows:

Dim pagestream(numpages - 1) As IO.MemoryStream
Dim newndfile(numpages - 1) As Aspose.Pdf.Kit.Form

For i As Integer = 0 To numpages - 1 'Represents the pages
pagestream(i) = New IO.MemoryStream
newndfile(i) = New Aspose.Pdf.Kit.Form(installdir & “\Forms\BB\ncd_form9.pdf”, pagestream(i))
'Fill out the form fields
'Code omitted
newndfile(i).FlattenAllFields()
newndfile(i).Save()
Next
’The following was suggested as a solution to a concatenation problem in another thread however, it did not help
For i As Integer = 0 To numpages - 1
pagestream(i).Position = 0
Next
’Concatenate the page
Dim pdfeditor As New Aspose.Pdf.Kit.PdfFileEditor
Dim outputstream As IO.MemoryStream = New IO.MemoryStream
pdfeditor.Concatenate(pagestream, outputstream)

The outputstream is then passed as a Byte() to another class to be saved as a file. I can open the file in Adobe Professional 6.0 however, the print button is grayed out. I have a sample pdf file which can be provided it that would help to identify the problem.

Hi,

Thank you for considering Aspose.

Please attach the sample pdf document and let us check it. Thanks.

As requested the file is attached.

Regards, Ralph

I found this document is enctypted and all permissions are set to be "not allowed". That's the reason you can't print it. Please check if the original document has those settings and if you have set security using Aspose.Pdf.Kit.

I have confirmed that the file is indeed encrypted with all permission turned off however please note that the original form has no security on it and is unencrypted. I have attached that file to this post.

When I test the encryption status of the individual streams prior to concatenation ‘BeEncrypted’ is set to ‘False’ however immediately after concatenation the ‘BeEncrypted’ property of the concatenated stream is set to ‘True’. Please note, the code I posted early works fine and has no encryption or security restrictions if the memorystream array (which is concatenated) has only one element. When it has two or more elements the concatenated output stream is encrypted.

Do you mean the result pdf is encrypted although you have not set the encryption setting? If so please provide complete example code and let us check it.

As requested below is the code for the method I am using to generate a pdf with one or more pages (depending on how many directors there are in the object ibccaobj.DirectorOfficerDetails.Director). As I indicated before if there are three or less directors and hence only one page is required the resulting PDF file is fine however if there is more than three directors resulting in pagestream() having more than one element the resulting PDF file is encrypted with all permission set to Not Allow. Note that in either case the Concatenate function is called to generate the outputstream.

Public Shared Function GenerateNoticeDirectorsPDF(ByVal sessionid As String, ByVal company As Company, ByVal ibccaobj As IBCCA) As FileAndData
Dim retval As FileAndData = Nothing
Try
If DCBO.General.ValidateSessionID(sessionid) Then
'Determine the number of pages required
Dim numpages As Integer = System.Math.Ceiling(ibccaobj.DirectorOfficerDetails.Directors.Count / 3)
'Need to determine install directory
Dim installdir As String = DCBO.General.GetInstallDirectory()
Dim pagestream(numpages - 1) As IO.MemoryStream
Dim newndfile(numpages - 1) As Aspose.Pdf.Kit.Form

Log.Write(LogMode.Verbose, LogEntryLevel.Notification, LogEntryType.Notification, “Creating Notice of Directors PDF…”)
For i As Integer = 0 To numpages - 1 'Represents the pages
pagestream(i) = New IO.MemoryStream
newndfile(i) = New Aspose.Pdf.Kit.Form(installdir & “\Forms\BB\ncd_form9.pdf”, pagestream(i))
newndfile(i).FillField(“CompanyName”, company.Name)
newndfile(i).FillField(“CompanyNumber”, company.Number)
For j As Integer = 0 To 3 - 1 'Represents the slots for directors on each page
If i * 3 + j <= ibccaobj.DirectorOfficerDetails.Directors.Count - 1 Then
newndfile(i).FillField(“DirectorName” & (j + 1).ToString, ibccaobj.DirectorOfficerDetails.Directors(i * 3 + j).ContactInfo.FullName)
newndfile(i).FillField(“DirectorAddress” & (j + 1).ToString, ibccaobj.DirectorOfficerDetails.Directors(i * 3 + j).ContactInfo.Address.ToString)
newndfile(i).FillField(“DirectorOccupation” & (j + 1).ToString, ibccaobj.DirectorOfficerDetails.Directors(i * 3 + j).Occupation)
Else
Exit For
End If
Next
newndfile(i).FillField(“PrintDate”, DateTime.Today.ToShortDateString)
newndfile(i).FlattenAllFields()
newndfile(i).Save()
Next
'Need to concatenate the files
Dim pdfeditor As New Aspose.Pdf.Kit.PdfFileEditor
Dim outputstream As IO.MemoryStream = New IO.MemoryStream
pdfeditor.Concatenate(pagestream, outputstream)

Dim newfileid As Int64 = AddClientIncorporationPDFFile(company.CompanyId, “Notice of Directors”, outputstream.ToArray)

Log.Write(LogMode.Verbose, LogEntryLevel.Notification, LogEntryType.Notification, "Successfully save Notice of Directors pdf to database. File ID: " & newfileid.ToString)

retval = New FileAndData
retval.File = DCBO.General.GetClientFile(sessionid, newfileid)
retval.Data = outputstream.ToArray
outputstream.Close()
'newndfile.FillField(“DirectorName1”, ibccaobj.DirectorOfficerDetails.Directors
DCBO.General.UpdateLastDbAccess(sessionid)
End If
Catch ex As Exception
ExceptionHandler.General.HandleException(ex)
Finally
GenerateNoticeDirectorsPDF = retval
End Try
End Function

Hope this helps.

Regards, Ralph

We are testing it and working on this. We will inform you if it is fixed.
Best regards.

Can you inform me if you CANNOT fix it as well as I would need to find an alternative method of achieving my objective?

Regards, Ralph

hi, Ralph,
I have tested the relative functions , and found that the function are ok. I opened the result pdf in Adobe Reader 7.0 and the “print” right is reserved.

The test code is like the following

Public Shared Sub TestFlattenRights()
Dim form As Form = New Aspose.Pdf.Kit.Form(KenTestPath + “66860/ncd_form9.pdf”,KenTestPath + “66860/out.pdf”)
form.FillField(“CompanyName”,“CompanyName”)
form.FillField(“CompanyNumber”,“CompanyNumber”)
form.FillField(“PrintDate”,“PrintDate”)
form.FlattenAllFields()
form.Save()
PdfFileEditor pdfeditor = New PdfFileEditor()
pdfeditor.Concatenate(KenTestPath + “66860/out.pdf”,KenTestPath + “66860/out2.pdf”,KenTestPath + “66860/outOut.pdf”)
End Sub


Ken

My apologies I realised I was using PDF.Kit 2.1.2.0. I downloaded 2.3.2.0 and now the concatenation works as expected.

Thanks, Ralph