Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable image magick ghostscript features #289

Merged
merged 1 commit into from
Apr 13, 2021
Merged

Conversation

samperman
Copy link
Contributor

See https://www.kb.cert.org/vuls/id/332928/
Enable features on focal since ghostscript is new enough

Fixes #286

See https://www.kb.cert.org/vuls/id/332928/
Enable features on focal since ghostscript is new enough

Fixes #286
@samperman samperman requested a review from jforest April 12, 2021 17:33
@samperman samperman merged commit 3a85e9d into master Apr 13, 2021
@samperman samperman deleted the imagemagick-pdf branch April 13, 2021 14:19
@dcaud
Copy link

dcaud commented Oct 26, 2023

Today, I relaunched an old app (with the exact same code as another app that is currently function) and am now getting this same error that caused this issue initially:

"R: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/421"

I wonder if this is related to upgrading Ubuntu to Jammy last month: #356

Either way, this is a drastic problem for multiple of my apps at the moment. Any ideas for a quick fix?

@dcaud
Copy link

dcaud commented Oct 26, 2023

Below is an example app that reproduces the error. Downloading a jpeg works, but not writing and downloading a PDF. Both work locally on my Mac.

library(shiny)
library(magick)

ui <- fluidPage(
  titlePanel("Error when downloading as PDF"),
  
  sidebarLayout(
    sidebarPanel(
      radioButtons("fileType", "Choose File Type:",
                   choices = c("PDF", "JPEG"),
                   selected = "PDF"),
      downloadButton("downloadFile", "Download")
    ),
    
    mainPanel(
      imageOutput("displayImage")
    )
  )
)

server <- function(input, output, session) {
  
  img <- image_read("wizard:")
  
  output$displayImage <- renderImage({
    tmp <- tempfile(fileext = ".png")
    image_write(img, path = tmp, format = "png")
    list(src = tmp)
  }, deleteFile = TRUE)
  
  output$downloadFile <- downloadHandler(
    filename = function() {
      if (input$fileType == "PDF") {
        paste0("converted_", Sys.Date(), ".pdf")
      } else {
        paste0("converted_", Sys.Date(), ".jpeg")
      }
    },
    content = function(file) {
      if (input$fileType == "PDF") {
        # The write function w/ PDF seems to be at odds with a policy that can be revised.
        image_write(img, path = file, format = "pdf")
      } else {
        image_write(img, path = file, format = "jpeg")
      }
    }
  )
}

shinyApp(ui = ui, server = server)

@dcaud
Copy link

dcaud commented Oct 26, 2023

I believe this was probably solved before by removing the entire policy.xml: #323

@dcaud
Copy link

dcaud commented Oct 27, 2023

It looks like the install script and test from the focal version didn't make it into the current jammy version.

This fix might require updating the install script.

Something like switching this code from:

if [ ${OS_CODENAME} == "focal" ]; then

to

if [ "${OS_CODENAME}" == "focal" ] || [ "${OS_CODENAME}" == "jammy" ]; then

But a test to see if the policy.xml file is still in the same referenced path would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change to ImageMagick's policy.xml to write PDFs using library(magick)
3 participants