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

Code exemple for merge PDFS #101

Open
matheuscamarques opened this issue Jul 26, 2023 · 0 comments
Open

Code exemple for merge PDFS #101

matheuscamarques opened this issue Jul 26, 2023 · 0 comments

Comments

@matheuscamarques
Copy link

could you implement something like this here

defmodule PdfMerger.MergePdfs do
  def method(input_files, output_file) do
    if pdftk_installed?() do
      merge_pdfs(input_files, output_file)
    else
      IO.puts("Error: pdftk is not installed.")
    end
  end

  defp command_exists?(command) do
    System.cmd("which", [command]) == {"/usr/bin/#{command}\n", 0}
  end

  defp pdftk_installed? do
    command_exists?("pdftk")
  end

  defp merge_pdfs(input_files, output_file) do
    input_files_string = Enum.join(input_files, " ")
    output_file = Path.expand(output_file)

    {output, status} =
      System.cmd("pdftk", ["#{input_files_string}", "cat", "output", "#{output_file}"])
      IO.inspect("pdftk #{input_files_string} cat output #{output_file}")
    case status do
      0 ->
        IO.puts("PDFs merged successfully.")

      _ ->
        IO.puts("Error: PDF merging failed.")
    end
  end
end
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

No branches or pull requests

1 participant