using IronPdf;ChromePdfRenderer renderer = new ChromePdfRenderer();PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Secret Information:</h1> Hello World");// Password to edit the pdfpdf.SecuritySettings.OwnerPassword = "123password";// Password to open the pdfpdf.SecuritySettings.UserPassword = "password123";pdf.SaveAs("protected.pdf");
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Secret Information:</h1> Hello World");
// Password to edit the pdf
pdf.SecuritySettings.OwnerPassword = "123password";
// Password to open the pdf
pdf.SecuritySettings.UserPassword = "password123";
pdf.SaveAs("protected.pdf");
ImportsIronPdfPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Secret Information:</h1> Hello World")' Password to edit the pdfpdf.SecuritySettings.OwnerPassword = "123password"' Password to open the pdfpdf.SecuritySettings.UserPassword = "password123"pdf.SaveAs("protected.pdf")
Imports IronPdf
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Secret Information:</h1> Hello World")
' Password to edit the pdf
pdf.SecuritySettings.OwnerPassword = "123password"
' Password to open the pdf
pdf.SecuritySettings.UserPassword = "password123"
pdf.SaveAs("protected.pdf")
try{ var pdf = PdfDocument.FromFile("protected.pdf", userPassword); // Process the PDF}catch (IronPdf.Exceptions.IronPdfPasswordException ex){ // Handle incorrect passwordConsole.WriteLine("Invalid password provided");}
try
{
var pdf = PdfDocument.FromFile("protected.pdf", userPassword);
// Process the PDF
}
catch (IronPdf.Exceptions.IronPdfPasswordException ex)
{
// Handle incorrect password
Console.WriteLine("Invalid password provided");
}
ImportsIronPdf.ExceptionsTry Dim pdf = PdfDocument.FromFile("protected.pdf", userPassword) ' Process the PDFCatch ex AsIronPdfPasswordException ' Handle incorrect passwordConsole.WriteLine("Invalid password provided")EndTry
Imports IronPdf.Exceptions
Try
Dim pdf = PdfDocument.FromFile("protected.pdf", userPassword)
' Process the PDF
Catch ex As IronPdfPasswordException
' Handle incorrect password
Console.WriteLine("Invalid password provided")
End Try
using IronPdf;var pdf = PdfDocument.FromFile("protected.pdf", "password123");//... perform PDF-taskspdf.SaveAs("protected_2.pdf"); // Saved as another file
using IronPdf;
var pdf = PdfDocument.FromFile("protected.pdf", "password123");
//... perform PDF-tasks
pdf.SaveAs("protected_2.pdf"); // Saved as another file
ImportsIronPdfPrivate pdf = PdfDocument.FromFile("protected.pdf", "password123")'... perform PDF-taskspdf.SaveAs("protected_2.pdf") ' Saved as another file
Imports IronPdf
Private pdf = PdfDocument.FromFile("protected.pdf", "password123")
'... perform PDF-tasks
pdf.SaveAs("protected_2.pdf") ' Saved as another file
using IronPdf;// Open an Encrypted File, alternatively create a new PDF from HTMLvar pdf = PdfDocument.FromFile("protected.pdf", "password123");// Edit file security settings// The following code makes a PDF read only and will disallow copy & paste and printingpdf.SecuritySettings.RemovePasswordsAndEncryption();pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");pdf.SecuritySettings.AllowUserAnnotations = false;pdf.SecuritySettings.AllowUserCopyPasteContent = false;pdf.SecuritySettings.AllowUserFormData = false;pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;// Save the secure PDFpdf.SaveAs("secured.pdf");
using IronPdf;
// Open an Encrypted File, alternatively create a new PDF from HTML
var pdf = PdfDocument.FromFile("protected.pdf", "password123");
// Edit file security settings
// The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
// Save the secure PDF
pdf.SaveAs("secured.pdf");
ImportsIronPdf' Open an Encrypted File, alternatively create a new PDF from HTMLPrivate pdf = PdfDocument.FromFile("protected.pdf", "password123")' Edit file security settings' The following code makes a PDF read only and will disallow copy & paste and printingpdf.SecuritySettings.RemovePasswordsAndEncryption()pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key")pdf.SecuritySettings.AllowUserAnnotations = Falsepdf.SecuritySettings.AllowUserCopyPasteContent = Falsepdf.SecuritySettings.AllowUserFormData = Falsepdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights' Save the secure PDFpdf.SaveAs("secured.pdf")
Imports IronPdf
' Open an Encrypted File, alternatively create a new PDF from HTML
Private pdf = PdfDocument.FromFile("protected.pdf", "password123")
' Edit file security settings
' The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption()
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key")
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserFormData = False
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights
' Save the secure PDF
pdf.SaveAs("secured.pdf")
Can I add security settings when converting HTML to PDF?
Yes, IronPDF allows you to apply security settings immediately after converting HTML to PDF. After creating a PDF from HTML content, you can access the SecuritySettings properties to set passwords and permissions before saving the final document, ensuring your converted files are protected from the start.