stavro / arc

:paperclip: Flexible file upload and attachment library for Elixir
1.16k stars 210 forks source link

Converting PDF to PNG - resulting images stuck in temporary file (multi-page pdf) #284

Closed aprilxyc closed 5 years ago

aprilxyc commented 5 years ago

Hi all,

I have the following function that is converting PDF files to PNG images

  def transform(:original, _) do
      {:convert, fn(input, output) ->
        "#{input} png:#{output}" end, :png}
    end

This works successfully but the resulting PNG images only show up in my temporary folder (i.e. the one specified by the output variable) and not in the directory specified. I want to have these converted files show up in the path I have specified.

I have a function storage_dir that does specify the path but I believe this is only relevant to the PDFs uploaded and not the PDFs converted:

   def storage_dir(version, {file, scope}) do
         "/some-path./"
  end

The closest answer I've found is Issue #77 but I'm not sure whether it is applicable or how to set my path. Any help would be appreciated on advising how to specify where these converted images should go or how to specify the output directory.

Erlang/OTP 22 Elixir 1.0.0 arc_ecto 0.11.2

OvermindDL1 commented 5 years ago

For note, I use {:convert, fn(input, output) -> ["-density", "144", input, "png:" <> output] end, :png} without issue, appears in the correct place and all, only difference is the -density 144 arguments so I doubt that's it, so perhaps something server-specific?

I have a function storage_dir that does specify the path but I believe this is only relevant to the PDFs uploaded and not the PDFs converted:

Mine is:

  def storage_dir(version, {file, scope}) do
    Application.get_env(:arc, :storage_dir) <> request_dir(version, {file, scope})
  end

But I'm pretty sure it applies to the end-converted file though?

aprilxyc commented 5 years ago

For note, I use {:convert, fn(input, output) -> ["-density", "144", input, "png:" <> output] end, :png} without issue, appears in the correct place and all, only difference is the -density 144 arguments so I doubt that's it, so perhaps something server-specific?

I have a function storage_dir that does specify the path but I believe this is only relevant to the PDFs uploaded and not the PDFs converted:

Mine is:

  def storage_dir(version, {file, scope}) do
    Application.get_env(:arc, :storage_dir) <> request_dir(version, {file, scope})
  end

But I'm pretty sure it applies to the end-converted file though?

Hi sorry forgot to mention this only happens with multi-paged PDFs. Does yours work with multi-paged PDFs? Thank you!

OvermindDL1 commented 5 years ago

Ah I only handle single-page PDF's specifically for the reason of I have no clue how to have Arc handle multiple, so I split it before I ever give it to Arc. This would be a nice addition to Arc though.

aprilxyc commented 5 years ago

Ah I only handle single-page PDF's specifically for the reason of I have no clue how to have Arc handle multiple, so I split it before I ever give it to Arc. This would be a nice addition to Arc though.

No worries. Thank you for your help regardless. I think it may exist with Arc using +adjoin, however there is not much documentation on this and I haven't quite figured out the syntax for it yet. I ended up just using -append to join the PDFs together.