How to remove download and print buttons in toolbar

Due to security requirements, how to remove download and print buttons from the PDF document toolbar when using Aspose.Word.dll convert a document to a PDF format?

how to remove download and print buttons in toolbar in pdf document:

ReplaceTextAll.pdf (135.5 KB)

@davidxiao2008 You can configure permissions using PdfEncryptionDetails.Permissions property. For example see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Hello, World!");

PdfEncryptionDetails encryptionDetails =
    new PdfEncryptionDetails(string.Empty, "ownerpass", PdfPermissions.DisallowAll);

PdfSaveOptions opt = new PdfSaveOptions();
opt.EncryptionDetails = encryptionDetails;

doc.Save(@"C:\Temp\out.pdf", opt);

Thanks for your reply
I tried the code but did not achieve the expected goal (Aspose. Words.dll v23.7.0)

  1. When file was saved locally, it can hide download permission, it works but i need output to browser :frowning:
  2. When to output the file stream to the client’s browser, and there are still download and print buttons on the browser. It seems that this is the built-in button of the browser. May I ask if it is possible to hide the buttons
[HttpGet]
public async Task<IActionResult> Doc2()
{
    try
    {
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.Write("Hello, World!");

        using (var ms = new MemoryStream())
        {
            var saveOptions = new Aspose.Words.Saving.PdfSaveOptions();

            Aspose.Words.Saving.PdfEncryptionDetails encryptionDetails = new Aspose.Words.Saving.PdfEncryptionDetails(string.Empty, "ownerpass");
            encryptionDetails.Permissions = PdfPermissions.DisallowAll;
            saveOptions.EncryptionDetails = encryptionDetails;

            // Save To Local
            doc.Save(@"C:\Temp\out.pdf", saveOptions);

            // Output to browser
            doc.Save(ms, saveOptions);

            string contentType = "application/pdf";
            ms.Position = 0;
            return File(ms.ToArray(), contentType);
        }
    }
    catch (Exception ex)
    {
        throw;
    }
}

Here is my code

@davidxiao2008 Encryption details are stored in the document itself, how they are interpreted by the consumer application is out of Aspose.Words scope. I am afraid, there is no way to control how browser open PDF document and what buttons are shown using Aspose.Words.

What we plan to do is to create an online preview website for files. Is there any other solution (Aspose. Word or other family) to meet this requirement (without displaying the print button or preview button), provided that it is saved as a PDF stream

@davidxiao2008 You can consider using HtmlFixed format for viewing document on web page. This is an HTML based format designed exactly for viewing purposes:

Document doc = new Document(@"C:\Temp\in.docx");
HtmlFixedSaveOptions opt = new HtmlFixedSaveOptions();
opt.ExportEmbeddedCss = true;
opt.ExportEmbeddedFonts = true;
opt.ExportEmbeddedImages = true;
opt.ExportEmbeddedSvg = true;
doc.Save(@"C:\Temp\out.html", opt);

Alternatively, you can convert the document to SVG.

ok, thank you very much

1 Like

hi alexey,
Saving files in PDF format for online file preview web sit can improve user experience, and we hope to use PDF format for presentation.
Can I remove these buttons when converting aspose. Word to PDF by adding css style or JavaScript ?

@davidxiao2008 I am afraid, this is out of Aspose.Words scope and there is no way to remove buttons from PDF preview in browser using Aspose.Words.

thank you.
I need to find an alternative solution(like pdf appearance but forbid download), please help give some advice.

@davidxiao2008 As an alternative to PDF, for viewing documents in browser, you can try using HTML Fixed or SVG formats.

html format looks not so good. I will try other alternative solution.
thanks

1 Like