Is there a way I could prevent the user from copying the content of a PDF file on iOS devices?
To detail a bit the background of this query, I have an app that is downloading a PDF and displaying it in the browser. The file is provided by a .NET Core web api and the client that it's serving the file is developed in Angular.
At the API level I am using iTextSharp to encrypt and set permissions for it (just printing permission). This works without any issues on desktop, but not on iOS devices.
If anyone could help me, I would be grateful.
UPDATE
.NET Core encryption method
public byte[] EncryptPdf(byte[] bytes, string encryptionKey)
{
using (var ms = new MemoryStream())
{
using (var reader = new PdfReader(bytes))
using (var stamper = new PdfStamper(reader, ms))
{
stamper.SetEncryption(null, Encoding.ASCII.GetBytes(encryptionKey),
PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128);
stamper.Close();
}
return ms.ToArray();
}
}
Angular snippet for handling the blob
downloadFile(data: any) {
var windowUrl = window.URL || (window as any).webkitURL;
if (navigator.msSaveOrOpenBlob) {
navigator.msSaveOrOpenBlob(data.body, this.getFileName(data));
return;
} else if (navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i)) {
const url = windowUrl.createObjectURL(data.body);
window.location.href = url;
return;
}
saveAs(data.body, this.getFileName(data));
}