On creating PDF non editable by using below code. The non editable PDF look is not in sync with the normal editable pdf. Content of Non editable pdf shrinks a little and
becomes blurry on zooming in.
Code which we are using to convert the PDF to non editable
// Load the PDF document
Document pdfDocument = new Document(DownloadPath + reportRequestQueueid + “.” + fileextension);
Aspose.Pdf.Document imagePdf = new Aspose.Pdf.Document();
//Aspose.Pdf.Pages pages = pdfDocument.Pages;
// ZOOM SETTINGS
double zoomFactor = 2.0; // 1.5x zoom (150% of original size)
double dpiResolution = 300; // High quality DPI
int jpegQuality = 95; // High quality JPEG
// Iterate through the pages using the Pages collection
foreach (Page page in pdfDocument.Pages)
{
//Original page dimentions
double originalWidth = page.GetPageRect(true).Width;
double originalHeight = page.GetPageRect(true).Height;
// Calculate zoomed dimensions
double zoomedWidth = originalWidth * zoomFactor;
double zoomedHeight = originalHeight * zoomFactor;
// Calculate pixel dimensions for image generation
var resolution = new Aspose.Pdf.Devices.Resolution((int)dpiResolution);
int pixelWidth = (int)(zoomedWidth * dpiResolution / 72);
int pixelHeight = (int)(zoomedHeight * dpiResolution / 72);
// Render page to image
using (var ms = new MemoryStream())
{
var jpegDevice = new Aspose.Pdf.Devices.JpegDevice(pixelWidth, pixelHeight, resolution, jpegQuality);
jpegDevice.Process(page, ms);
ms.Position = 0;
// Process the page to image stream
jpegDevice.Process(page, ms);
ms.Position = 0;
// Create a new MemoryStream with the image data
var imageStream = new MemoryStream(ms.ToArray());
// Add new page to output PDF with ZOOMED dimensions
Aspose.Pdf.Page newPage = imagePdf.Pages.Add();
// Set the page size to ZOOMED dimensions (this is key!)
newPage.SetPageSize(zoomedWidth, zoomedHeight);
// Create image object and add to page
var image = new Aspose.Pdf.Image();
image.ImageStream = imageStream;
// Set image dimensions to fill the ZOOMED page
image.FixWidth = zoomedWidth;
image.FixHeight = zoomedHeight;
// Add image to the page
newPage.Paragraphs.Add(image);
}
}
// Set document privileges to disable printing
DocumentPrivilege privilege = DocumentPrivilege.ForbidAll;
privilege.AllowPrint = false;
// Apply the privileges to the document
imagePdf.Encrypt(“”, “”, privilege, CryptoAlgorithm.AESx128, false);
imagePdf.Save(DownloadPath + reportRequestQueueid + “.” + fileextension);