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

Free Support Forum - aspose.com

Read and convert Readonly PDF to editable?

Been using Aspose.PDF for a while and is happy with it. Sometimes my program needs to handle pdfs that are password protected. As of my understanding, a PDF can be completely locked, requiring a password for both reading and writing. But there is also a case where sometimes only editing requires password, not reading.

So when a PDF is readonly, is there a way to read it? And if so, could I create a new Document and add the pages there and create an “editable” document? I want to do something like this:

public void IsPdfValid(string sourceFilePath)
{
    PdfFileInfo pdfFileInfo = new PdfFileInfo();
    pdfFileInfo.BindPdf(sourceFilePath);

    if (pdfFileInfo.IsPdfFile)
    {
        if (!pdfFileInfo.IsEncrypted)
        {
            Document pdfDocumentOriginal = new Document(sourceFilePath); //This fails, needs password

            Document pdfDocumentNew = new Document();

            pdfDocumentNew.Pages.Add(pdfDocumentOriginal.Pages);
        }
    }
}

@nisse1233

You need to specify password for a PDF file which is protected in order to perform operations. After opening a PDF document, you can remove its password and make editable for future. In case the password is unknown, it will not be possible to edit or process the PDF. In case you need further assistance, please let us know.

Aha. I am just thinking because with my computer’s pdf viewer I can open and view files that only requires password for editing.

@nisse1233

PDF documents may have different privileges and security level set for them. Sometimes a PDF document is password protected only when meant to be edited. You can load such PDF documents using the API but would not be able to perform modifications as API will throw some exception at particular stage.

Nevertheless, would you kindly share such PDF document with us. We will investigate the scenario in details and try to implement handling of such files in the API as well.

I see. Can you you demonstrate how to load the document then? Because when I do it, it fails.

I cannot share such an pdf as my Adobe Trial has expired. If you have Adobe creative cloud, you can take any random pdf and add a password for editing and try loading that in aspose.

@nisse1233

You can create a PDF document using following code snippet which will not have an open-password but some privileges only:

Document doc = new Document();
doc.Pages.Add();
Facades.DocumentPrivilege documentPrivilege = Facades.DocumentPrivilege.AllowAll;
documentPrivilege.AllowAssembly = false;
documentPrivilege.AllowCopy = false;
documentPrivilege.AllowModifyContents = false;
doc.Encrypt("", "qwerty", documentPrivilege, CryptoAlgorithm.AESx128, false);
doc.Save(dataDir + "PasswordProtected.pdf");
doc = new Document(dataDir + "PasswordProtected.pdf");

PasswordProtected.pdf (2.6 KB)

Such document can be opened using the API as they do not require any password to get loaded.