We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Signature- pkcs1 - pdfFileSecurity

Hi,


I am using , pdf.kit v6.0, pdf v6.4.2.
I want to sign (with pkcs1 certificat) a document and I want that document not copyable, printable …
If I put signature before security , the document is not well signed but unprintable …
If I put security before signature, the document is well signed but printable…

Is there anything I am missing ?

Regards

Cédric

Hi Cedric,

Thank you for considering Aspose.Pdf for .NET.

I have tried to replicate your issue at my end but unable to reproduce the issue. Please share your template PDF file and sample code with us. This will help us to figure out the issue and reply back to you soon.

We apologize for your inconvenience.

Thanks & Regards,

Hi,

Here is two sample
First , Pdf then Secu, then editor then cert

Monficher.pdf = file without secu and certificat
MonFicher_Secu.pdf = file unprintable, uncopyable…
MonFichier_Editor.pdf = file with Editor (Here is the security is lost)
MonFichier_Cert.pdf = file with Editor and certificat (Here is the security is lost )

Second, Pdf then editor , then secu then cert


Sub impressionSecuCert(Cert As String, password As String)

'Validation de la licence Aspose
Dim maLicencePdf As New Aspose.Pdf.License
maLicencePdf.SetLicense(“aspose.total.lic”)
    <span style="color:blue;">Dim</span> maLicencePdfKit <span style="color:blue;">As</span> <span style="color:blue;">New</span> Aspose.Pdf.Kit.<span style="color:#2b91af;">License</span>
    maLicencePdfKit.SetLicense(<span style="color:#a31515;">"aspose.total.lic"</span>)
    <span style="color:green;">'On recupère la liste des chapitres selectionnés</span>
    <span style="color:blue;">Dim</span> fs = <span style="color:blue;">New</span> <span style="color:#2b91af;">FileStream</span>(<span style="color:#a31515;">"c:\monfichier.pdf"</span>, <span style="color:#2b91af;">FileMode</span>.OpenOrCreate)
    <span style="color:blue;">Dim</span> monPdf <span style="color:blue;">As</span> <span style="color:blue;">New</span> Aspose.Pdf.Generator.<span style="color:#2b91af;">Pdf</span>(fs)

    <span style="color:blue;">Dim</span> maSection = monPdf.Sections.Add
    <span style="color:green;">' Create a Text object</span>
    <span style="color:blue;">Dim</span> txt <span style="color:blue;">As</span> Aspose.Pdf.Generator.<span style="color:#2b91af;">Text</span> = <span style="color:blue;">New</span> Aspose.Pdf.Generator.<span style="color:#2b91af;">Text</span>(<span style="color:#a31515;">"Test de  fichier PDF"</span>)
    <span style="color:green;">' Add text to Header section of the Pdf file</span>
    maSection.Paragraphs.Add(txt)
    monPdf.Close()
    fs.Close()

    <span style="color:green;">'Securite</span>
    fs = <span style="color:blue;">New</span> <span style="color:#2b91af;">FileStream</span>(<span style="color:#a31515;">"c:\monfichier.pdf"</span>, <span style="color:#2b91af;">FileMode</span>.OpenOrCreate)
    <span style="color:blue;">Dim</span> outStream <span style="color:blue;">As</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">MemoryStream</span>
    <span style="color:blue;">Using</span> outStream
        <span style="color:blue;">Dim</span> pdfSecurity <span style="color:blue;">As</span> <span style="color:#2b91af;">PdfFileSecurity</span> = <span style="color:blue;">New</span> <span style="color:#2b91af;">PdfFileSecurity</span>(fs, outStream)
        <span style="color:blue;">Dim</span> monPrivilege <span style="color:blue;">As</span> <span style="color:#2b91af;">DocumentPrivilege</span> = <span style="color:#2b91af;">DocumentPrivilege</span>.AllowAll
        monPrivilege.AllowDegradedPrinting = <span style="color:blue;">False</span>
        monPrivilege.AllowPrint = <span style="color:blue;">False</span>
        monPrivilege.AllowCopy = <span style="color:blue;">False</span>
        monPrivilege.ChangeAllowLevel = 0
        monPrivilege.CopyAllowLevel = 0
        monPrivilege.PrintAllowLevel = 0
        pdfSecurity.SetPrivilege(monPrivilege)
        <span style="color:green;">'Pour verifier</span>
        <span style="color:blue;">Dim</span> fPdf = <span style="color:blue;">New</span> <span style="color:#2b91af;">FileStream</span>(<span style="color:#a31515;">"c:\monFichier_Secu.pdf"</span>, <span style="color:#2b91af;">FileMode</span>.Create)
        outStream.WriteTo(fPdf)
        fPdf.Close()
        fs.Close()
        fs = <span style="color:blue;">Nothing</span>

        <span style="color:green;">'Editor</span>
        <span style="color:blue;">Dim</span> outStream2 <span style="color:blue;">As</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">MemoryStream</span>
        <span style="color:blue;">Using</span> outStream2
            <span style="color:blue;">Dim</span> monEditor <span style="color:blue;">As</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">FormEditor</span>(outStream, outStream2)
            monEditor.AddField(<span style="color:#2b91af;">FieldType</span>.Signature, <span style="color:#a31515;">"CNR Signature"</span>, 1, 10, 10, 110, 110)
            monEditor.Save()

            fPdf = <span style="color:blue;">New</span> <span style="color:#2b91af;">FileStream</span>(<span style="color:#a31515;">"c:\monFichier_Editor.pdf"</span>, <span style="color:#2b91af;">FileMode</span>.Create)
            outStream2.WriteTo(fPdf)
            fPdf.Close()
        <span style="color:blue;">End</span> <span style="color:blue;">Using</span>

        <span style="color:blue;">Dim</span> sig <span style="color:blue;">As</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">Pkcs7Signature</span>(Cert, password)
        sig.Reason = <span style="color:blue;">String</span>.Format(<span style="color:#a31515;">"ImpressionRegistre {0}"</span>, <span style="color:blue;">Date</span>.Now.ToString(<span style="color:#a31515;">"ddMMyy HH:mm:ss"</span>))
        sig.Contact = <span style="color:#a31515;">"Cedric"</span>
        sig.Location = <span style="color:#a31515;">"Location"</span>
        sig.Date = <span style="color:blue;">Date</span>.Now

        <span style="color:blue;">Dim</span> pdfSign <span style="color:blue;">As</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">PdfFileSignature</span>(<span style="color:#a31515;">"c:\monFichier_Editor.pdf"</span>)
        pdfSign.Sign(<span style="color:#a31515;">"CNR Signature"</span>, sig)
        pdfSign.Save(<span style="color:#a31515;">"c:\monFichier_Signe.pdf"</span>)
    <span style="color:blue;">End</span> <span style="color:blue;">Using</span>
  <span style="color:blue;">End</span> <span style="color:blue;">Sub</span></pre><pre style="font-family: Consolas; font-size: 13px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="color:blue;"><br></span></pre><pre style="font-family: Consolas; font-size: 13px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><pre style="font-family: Consolas; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">    <span style="color:blue;">Sub</span> impressionSecuCert2(Cert <span style="color:blue;">As</span> <span style="color:blue;">String</span>, password <span style="color:blue;">As</span> <span style="color:blue;">String</span>)

    <span style="color:green;">'Validation de la licence Aspose</span>
    <span style="color:blue;">Dim</span> maLicencePdf <span style="color:blue;">As</span> <span style="color:blue;">New</span> Aspose.Pdf.<span style="color:#2b91af;">License</span>
    maLicencePdf.SetLicense(<span style="color:#a31515;">"aspose.total.lic"</span>)

    <span style="color:blue;">Dim</span> maLicencePdfKit <span style="color:blue;">As</span> <span style="color:blue;">New</span> Aspose.Pdf.Kit.<span style="color:#2b91af;">License</span>
    maLicencePdfKit.SetLicense(<span style="color:#a31515;">"aspose.total.lic"</span>)
    <span style="color:green;">'On recupère la liste des chapitres selectionnés</span>
    <span style="color:blue;">Dim</span> fs = <span style="color:blue;">New</span> <span style="color:#2b91af;">FileStream</span>(<span style="color:#a31515;">"c:\2_monfichier.pdf"</span>, <span style="color:#2b91af;">FileMode</span>.OpenOrCreate)
    <span style="color:blue;">Dim</span> monPdf <span style="color:blue;">As</span> <span style="color:blue;">New</span> Aspose.Pdf.Generator.<span style="color:#2b91af;">Pdf</span>(fs)

    <span style="color:blue;">Dim</span> maSection = monPdf.Sections.Add
    <span style="color:green;">' Create a Text object</span>
    <span style="color:blue;">Dim</span> txt <span style="color:blue;">As</span> Aspose.Pdf.Generator.<span style="color:#2b91af;">Text</span> = <span style="color:blue;">New</span> Aspose.Pdf.Generator.<span style="color:#2b91af;">Text</span>(<span style="color:#a31515;">"Test de  fichier PDF"</span>)
    <span style="color:green;">' Add text to Header section of the Pdf file</span>
    maSection.Paragraphs.Add(txt)
    monPdf.Close()
    fs.Close()


    <span style="color:green;">'Securite</span>
    fs = <span style="color:blue;">New</span> <span style="color:#2b91af;">FileStream</span>(<span style="color:#a31515;">"c:\2_monfichier.pdf"</span>, <span style="color:#2b91af;">FileMode</span>.OpenOrCreate)
    <span style="color:blue;">Dim</span> outStream <span style="color:blue;">As</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">MemoryStream</span>
    <span style="color:blue;">Using</span> outStream
        <span style="color:green;">'Editor</span>
        <span style="color:blue;">Dim</span> outStream2 <span style="color:blue;">As</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">MemoryStream</span>
        <span style="color:blue;">Using</span> outStream2
            <span style="color:blue;">Dim</span> monEditor <span style="color:blue;">As</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">FormEditor</span>(fs, outStream2)
            monEditor.AddField(<span style="color:#2b91af;">FieldType</span>.Signature, <span style="color:#a31515;">"CNR Signature"</span>, 1, 10, 10, 110, 110)
            monEditor.Save()

            <span style="color:blue;">Dim</span> fPdf = <span style="color:blue;">New</span> <span style="color:#2b91af;">FileStream</span>(<span style="color:#a31515;">"c:\2_monFichier_Editor.pdf"</span>, <span style="color:#2b91af;">FileMode</span>.Create)
            outStream2.WriteTo(fPdf)
            fPdf.Close()

            <span style="color:blue;">Dim</span> pdfSecurity <span style="color:blue;">As</span> <span style="color:#2b91af;">PdfFileSecurity</span> = <span style="color:blue;">New</span> <span style="color:#2b91af;">PdfFileSecurity</span>(outStream2, outStream)
            <span style="color:blue;">Dim</span> monPrivilege <span style="color:blue;">As</span> <span style="color:#2b91af;">DocumentPrivilege</span> = <span style="color:#2b91af;">DocumentPrivilege</span>.AllowAll
            monPrivilege.AllowDegradedPrinting = <span style="color:blue;">False</span>
            monPrivilege.AllowPrint = <span style="color:blue;">False</span>
            monPrivilege.AllowCopy = <span style="color:blue;">False</span>
            monPrivilege.ChangeAllowLevel = 0
            monPrivilege.CopyAllowLevel = 0
            monPrivilege.PrintAllowLevel = 0
            pdfSecurity.SetPrivilege(monPrivilege)
            <span style="color:green;">'Pour verifier</span>
            fPdf = <span style="color:blue;">New</span> <span style="color:#2b91af;">FileStream</span>(<span style="color:#a31515;">"c:\2_monFichier_Secu.pdf"</span>, <span style="color:#2b91af;">FileMode</span>.Create)
            outStream.WriteTo(fPdf)
            fPdf.Close()
            fs.Close()
            fs = <span style="color:blue;">Nothing</span>
        <span style="color:blue;">End</span> <span style="color:blue;">Using</span>


        <span style="color:blue;">Dim</span> sig <span style="color:blue;">As</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">Pkcs7Signature</span>(Cert, password)
        sig.Reason = <span style="color:blue;">String</span>.Format(<span style="color:#a31515;">"ImpressionRegistre {0}"</span>, <span style="color:blue;">Date</span>.Now.ToString(<span style="color:#a31515;">"ddMMyy HH:mm:ss"</span>))
        sig.Contact = <span style="color:#a31515;">"Cedric"</span>
        sig.Location = <span style="color:#a31515;">"Location"</span>
        sig.Date = <span style="color:blue;">Date</span>.Now

        <span style="color:blue;">Dim</span> pdfSign <span style="color:blue;">As</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">PdfFileSignature</span>(<span style="color:#a31515;">"c:\monFichier_Editor.pdf"</span>)
        pdfSign.Sign(<span style="color:#a31515;">"CNR Signature"</span>, sig)
        pdfSign.Save(<span style="color:#a31515;">"c:\2_monFichier_Signe.pdf"</span>)
    <span style="color:blue;">End</span> <span style="color:blue;">Using</span>




<span style="color:blue;">End</span> <span style="color:blue;">Sub</span></pre></pre></div>

Hi Prochass,

I apologize for the delay in the response.

I have tested the scenario and I am able to notice the same problem. For the sake of correction, I have logged this problem for investigation as PDFNEWNET-32513 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction.

We are realy sorry for your inconvenience.

Thanks & Regards,

Hi Prochass,

Thanks for your patience.

I am very pleased to inform you that our develpment team has investigated your issue and found several "suspicious" issues, please find below mentioned findings of our development team against your issue.

1. Code snippet is invalid, it represents, the mixture of calling Aspose.Pdf.Kit and new Aspose.Pdf functions (e.g. creating signature object, setting license). So development team has changed code snippet in order to use only new Aspose.Pdf (see corrected.txt in attachments).

2. Your documents are broken, Adobe Acrobat open these documents but prompt to resave on closing (it means that, it definately made some changes in order to open the documents). So our development team unable to run code snippet successfully because of the broken documents. For further investigations we should understand how user get such documents. It's not strange if Aspose.Pdf can't work with broken documents but if we want to "study" Aspose.Pdf to work with broken documents we must know their origin (otherwise we can easily say, its work with normal documents).

Please feel free to contact support in case you need any further assistance.

Thanks & Regards,

Hi,

Than you for your response.
We will modify your snippet tou use new aspose pdf and we will be back.
The pdf files are issued from aspose cells…
Regards

Hi Prochass,

Thank you for the feedback.

You can contact to Aspose.Cells forum, in case you were creating broken PDF documents using Aspose.Cells API. This will help you to identify the exact issue.

Please feel free to contact support in case you need any further assistance.

Thanks & Regards,