Creating a non editable pdf blurs the text

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);

@PolarisAP

The issue you’re experiencing with the non-editable PDF becoming blurry and not in sync with the editable version may be related to how the images are rendered and added to the new PDF. When converting pages to images and setting their dimensions, quality loss can occur if not handled properly.

Here are a few suggestions to improve the quality of the generated non-editable PDF:

  1. Increase DPI Resolution: While a DPI of 300 is generally acceptable, experimenting with higher values (e.g., 600 DPI) may enhance clarity.

  2. Avoid Resizing Images: Instead of adjusting the page size to zoomed dimensions, maintain the original dimensions and scale the image to fit the page. This approach can help preserve text quality.

  3. Use Vector Graphics: If feasible, retain the text as vector graphics rather than converting it to images. This ensures that the text remains sharp at any zoom level.

Here’s a modified code snippet that keeps the original dimensions and scales the image:

// 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;

    // Create a new MemoryStream with the image data
    var imageStream = new MemoryStream(ms.ToArray());

    // Add new page to output PDF with original dimensions
    Aspose.Pdf.Page newPage = imagePdf.Pages.Add();
    newPage.SetPageSize(originalWidth, originalHeight); // Keep original size

    // Create image object and add to page
    var image = new Aspose.Pdf.Image();
    image.ImageStream = imageStream;

    // Set image dimensions to fill the original page
    image.FixWidth = originalWidth;
    image.FixHeight = originalHeight;

    // Add image to the page
    newPage.Paragraphs.Add(image);
}

By maintaining the original dimensions, you may mitigate the blurriness issue when zooming in.

If the problem persists, check the original PDF for any embedded fonts or graphics that might not be rendering correctly in the new PDF.