Hi,
I have a password protected docx file. I need to remove the write protection using aspose and save the docx without protection. When i use the below code the docx protection is removed but when opening it shows some error message as “Word found unreadable content…” (Please see the error screen shots)
I am using Aspose.Words version 13.3.0.0.
Attachments
Input File is “PwdDocx.docx”.Its password is “test”
Output File is “TestOutput.docx”
Error screenshots are “err1.png” and “err2.png”.
This is my sample code:
using(System.IO.Stream stream = new System.IO.MemoryStream(input))
{
// TEST
Aspose.Words.Document wDoc = new Aspose.Words.Document(stream, new Aspose.Words.LoadOptions()
{
Password = "test"
});
Aspose.Words.SaveFormat save = Aspose.Words.FileFormatUtil.LoadFormatToSaveFormat(wDoc.OriginalLoadFormat);
Aspose.Words.Saving.OoxmlSaveOptions sOptions = new Aspose.Words.Saving.OoxmlSaveOptions(save);
sOptions.Compliance = Aspose.Words.Saving.OoxmlCompliance.Iso29500_2008_Transitional;
System.IO.MemoryStream outStream;
// convert page by page
for (int i = 0; i <wDoc.PageCount; i++)
{
outStream = new MemoryStream();
options.PageIndex = i;
options.PageCount = 1;
// TEST
wDoc.Save(outStream, sOptions);
output = ConvertBinaryFileToArray(outStream);
ConvertedTiff.Add(output);
// Close/Dispose stream
outStream.Close();
}
}
// Convert stream to byte array
private byte[] ConvertBinaryFileToArray(MemoryStream inputStream)
{
BinaryWriter bwriter = new BinaryWriter(inputStream);
bwriter.Write(true);
byte[] array = inputStream.ToArray();
bwriter.Close();
inputStream.Close();
return array;
}
Hoping to get a solution as soon as possible.
Thanks
Jeshwel J