gettalong / hexapdf

Versatile PDF creation and manipulation for Ruby
https://hexapdf.gettalong.org
Other
1.21k stars 69 forks source link

i try to encryption pdf file before open but got wrong number of arguments #301

Closed newSirawit closed 4 months ago

newSirawit commented 4 months ago

i try to encryption pdf file before open by using encrypt but got "`encrypt': wrong number of arguments (given 1, expected 0) (ArgumentError)". what is i missing pls help.

this is my code :

" def test_encryption doc = HexaPDF::Document.new

  page = doc.pages.add
  canvas = page.canvas
  canvas.font("Helvetica", size: 12)
  canvas.text("Hello, world!", at: [100, 500])

  encryption_options = {
    type: :standard_v2,
    owner_password: "1234",
    user_password: "1234",
    permissions: [:print, :modify_content]
  }
  doc.encrypt(encryption_options)

  doc.write("encrypted_document.pdf")

  puts "PDF file encrypted successfully!"
end
"

thank you so much
gettalong commented 4 months ago

You need to use doc.encrypt(**encryption_options) since the method doesn't expect a single hash as argument but a number of keyword arguments, see https://hexapdf.gettalong.org/documentation/api/HexaPDF/Document/index.html#method-i-encrypt.

Also, the type: :standard_v2 is a not supported keyword argument for the #encrypt method.