Open emendelson opened 3 years ago
Doesn't it work with Rosetta?
I'm also interested in this, currently getting:
RuntimeException: The exit status code '126' says something went wrong:
stderr: "sh: /Users/ME/project/vendor/bin/wkhtmltopdf-amd64: cannot execute binary file
Can you install the .pkg
, run it directly and report any errors? I'm not sure where you got that file from.
@fritzfr what is the processor that you're running on? This thread concerns a request to run on ARM processors (under a Mac OS), while the -amd64 you mention is (AFAIK) for an Intel-compatible architecture.
I have a similar issue, does not work when I enable rosetta either.
@Snarik what is the error you get?
It's working for me. Installed via Homebrew on the terminal in Rosetta mode. 1 - Run the terminal in Rosetta mode. 2 - brew install wkhtmltopdf
I don't have access to a M1 and I think it'll hard to port Qt4 to it, unless the arm64 support works as-is. So Rosetta seems to be the only option for the foreseeable future.
I still haven't been able to use the wkhtmltopdf right, it looks like it's not accessing my localhost (my apache and php were installed natively, without rosetta, I think that's the problem). It generates the pdf, but without the project's css. If I can't solve it, I think I'll have to use a docker = (
It's working for me. Installed via Homebrew on the terminal in Rosetta mode. 1 - Run the terminal in Rosetta mode. 2 - brew install wkhtmltopdf
This was the solution for me. I had to completely remove Brew, start my terminal in rosetta mode, reinstall it, and then build my packages.
It's working for me. Installed via Homebrew on the terminal in Rosetta mode. 1 - Run the terminal in Rosetta mode. 2 - brew install wkhtmltopdf
This was the solution for me. I had to completely remove Brew, start my terminal in rosetta mode, reinstall it, and then build my packages.
I'll probably have to do that too, since I installed everything natively except wkhtml.
Yeah brew just does screwy things when you try to install it as ARM64. Better to just run your whole dev env as x86, the performance hit is minor I've found. Good luck.
I managed to solve my problem by changing the hosts to the project's hostname. That way I didn't have to reinstall everything in Rosetta mode.
Example: /etc/hosts 127.0.0.1 projectname.localhost
In this way, he loaded the entire css of the project in the pdf normally.
Updating the solution that worked for me: 1 - Run the terminal in Rosetta mode. 2 - brew install wkhtmltopdf 3 - Edit /etc/hosts changing localhost to the desired hostname Ex: 127.0.0.1 projectname.localhost
I hope I helped in some way.
Has anyone had any luck installing wkhtmltopdf in a Docker container on an M1 Mac? I just got a new dev machine for work, and one of the steps in our custom Dockerfile is the following:
# Install wkhtmltopdf
RUN wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.stretch_amd64.deb \
&& dpkg -i wkhtmltox_0.12.6-1.stretch_amd64.deb \
&& rm wkhtmltox_0.12.6-1.stretch_amd64.deb
This fails when I build the container due to the package architecture and system architecture mismatch.
#7 10.53 dpkg: error processing archive wkhtmltox_0.12.6-1.stretch_amd64.deb (--install):
#7 10.53 package architecture (amd64) does not match system (arm64)
#7 10.54 Errors were encountered while processing:
#7 10.54 wkhtmltox_0.12.6-1.stretch_amd64.deb
------
failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.stretch_amd64.deb && dpkg -i wkhtmltox_0.12.6-1.stretch_amd64.deb && rm wkhtmltox_0.12.6-1.stretch_amd64.deb]: exit code: 1
My next step was going to be attempting to run my terminal in Rosetta mode to see if it will build that way. (EDIT: It did not work; receiving the same error.)
EDIT:
Ahh, nevermind. Didn't realize there was an ARM version of that release. I swapped my Dockerfile to use wkhtmltox_0.12.6-1.stretch_arm64.deb instead and was able to get the install to complete.
I believe that this issue can now be closed with @jtelcontar solution above:
# Install wkhtmltopdf
RUN wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.stretch_arm64.deb \
&& dpkg -i wkhtmltox_0.12.6-1.stretch_arm64.deb \
&& rm wkhtmltox_0.12.6-1.stretch_arm64.deb
@cclauss that solves the docker based workflow, not a native mac package for M1 so I think this issue should still remain open.
I ran into a similar issue mentioned by jtelcontar. I have a Docker package that I usually run on an UBUNTU host and also an Intel Mac. In the DockerFile I have this:
COPY wkhtmltox_0.12.6-1.buster_amd64.deb /
RUN dpkg -i /wkhtmltox_0.12.6-1.buster_amd64.deb
and that works fine for the Intel Mac and UBUNTU server (a Dell R710 Xeon).
I'd have to look at the error on the M1 because that is a collaborator, but it is an architecture error message.
I tried changing to arm64, and that also gives an error with buster build from Downloads for the arm architecture. It might be that I need to make some additional adjustments in my build ?
Previously I also think I got wkhtmltopdf to work via Docker by using apt install wkhtmltopdf with a Debian Docker container and then also adding some additional packages, like xvfb and others. That was without using the .deb package and it had / has QT support. I like using the pre-built .deb packages, but using apt install is not a bad option either.
Dockerfile
ARG TARGETARCH # used in install_wkhtml2x.sh
COPY install_wkhtml2x.sh .
RUN ./install_wkhtml2x.sh
install_wkhtml2x.sh
#!/bin/bash -x
set -e
# https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.buster_amd64.deb
# https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_arm64.deb
# If running on an M1 Mac...
if [[ "${TARGETARCH}" == "arm64" ]]; then
WKHTMLTOX_URL="https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1"
WKHTMLTOX_DEB="wkhtmltox_0.12.6-1.buster_arm64.deb"
else
WKHTMLTOX_URL="https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5"
WKHTMLTOX_DEB="wkhtmltox_0.12.5-1.buster_amd64.deb"
fi
wget ${WKHTMLTOX_URL}/${WKHTMLTOX_DEB}
sudo dpkg -i ${WKHTMLTOX_DEB}
rm ${WKHTMLTOX_DEB}
Christian, I'll give that a try, thanks.
Might have to clean up my DockerFile. Below is part of what I had.
I think I am using just one of those PIP modules, and not sure if I need the font-packages if I am using the .deb package. I don't have the M1 Mac myself, but I might get one soon. Kind of waiting for the 27" version release.
RUN pip3 install pdfkit
RUN pip3 install wkhtmltopdf
...
...
RUN apt-get update
RUN apt-get --assume-yes install xz-utils
# Needed for the .deb pacakge, section below builds the wkhtmltopdf package
RUN apt-get --assume-yes install fontconfig
RUN apt-get --assume-yes install xfonts-75dpi
RUN apt-get --assume-yes install xfonts-100dpi
RUN apt-get --assume-yes install xfonts-scalable
RUN apt-get --assume-yes install xfonts-base
COPY wkhtmltox_0.12.6-1.buster_amd64.deb /
RUN dpkg -i wkhtmltox_0.12.6-1.buster_amd64.deb
...
Do apt-get
first and pip3
second.
Put all your apt-get install
together into a single RUN command to allow dependency resolution to work.
Put all your pip3 install
together into a single RUN command to allow dependency resolution to work.
I'll give that a try. Thanks. I take it I could add what you suggested to my docker-entrypoint.sh somehow ? What is shown below is what is currently there in the entrypoint.
DockerFile
FROM ....
RUN apt-get update && apt-get --assume-yes install -y \
wget \
xz-utils \
# ? Needed for the .deb pacakge, section below builds the wkhtmltopdf package
fontconfig \
xfonts-75dpi \
xfonts-100dpi \
xfonts-scalable \
xfonts-base \
dcmtk
RUN pip3 install pydicom pynetdicom pdfkit imgkit hl7 wkhtmltopdf mysql-connector-python requests
# Move to entrypoint or separate file
# COPY wkhtmltox_0.12.6-1.buster_amd64.deb /
# RUN dpkg -i wkhtmltox_0.12.6-1.buster_amd64.deb
ARG TARGETARCH # for later use in docker-entrypoint.sh
COPY docker-entrypoint.sh /
docker-entrypoint.sh
#!/usr/bin/env bash
set -o errexit
# https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.buster_amd64.deb
# https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_arm64.deb
# If running on an M1 Mac...
if [[ "${TARGETARCH}" == "arm64" ]]; then
WKHTMLTOX_URL="https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1"
WKHTMLTOX_DEB="wkhtmltox_0.12.6-1.buster_arm64.deb"
else
WKHTMLTOX_URL="https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5"
WKHTMLTOX_DEB="wkhtmltox_0.12.5-1.buster_amd64.deb"
fi
wget ${WKHTMLTOX_URL}/${WKHTMLTOX_DEB}
dpkg -i ${WKHTMLTOX_DEB}
rm ${WKHTMLTOX_DEB}
logfilecommand='--logfile=/etc/orthanc/logs/'
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
logfile=$logfilecommand$current_time.log
# generate the configuration file
cd /startup
python3 generateConfiguration.py
if [[ $TRACE_DICOM == true ]]; then
trace=--trace-dicom
fi
if [[ $VERBOSE_ENABLED == true ]]; then
verbosity=--verbose
fi
jobs=""
if [[ $NO_JOBS == true ]]; then
jobs=--no-jobs
fi
argv=(Orthanc $trace $verbosity $jobs $logfile "$@")
echo "Startup command: ${argv[*]}" >&2
exec "${argv[@]}"
Docker Build log
pacs-1_1 | 16200K .......... .......... .......... .......... .......... 97% 1.83M 0s
pacs-1_1 | 16250K .......... .......... .......... .......... .......... 98% 52.5M 0s
pacs-1_1 | 16300K .......... .......... .......... .......... .......... 98% 40.3M 0s
pacs-1_1 | 16350K .......... .......... .......... .......... .......... 98% 20.8M 0s
pacs-1_1 | 16400K .......... .......... .......... .......... .......... 99% 136M 0s
pacs-1_1 | 16450K .......... .......... .......... .......... .......... 99% 6.06M 0s
pacs-1_1 | 16500K .......... .......... .......... .......... .......... 99% 31.3M 0s
pacs-1_1 | 16550K .......... .......... .......... .......... .......... 99% 57.8M 0s
pacs-1_1 | 16600K .. 100% 4.49T=1.5s
any progress?
I think my statement earlier was pretty clear?
I think my statement earlier was pretty clear?
is QT 6 available to build this project? I see qt6 support mac os m1 in https://www.qt.io/blog/qt-on-apple-silicon
Please read https://wkhtmltopdf.org/status
It's working for me. Installed via Homebrew on the terminal in Rosetta mode.
I was able to install homebrew natively without using Rosetta mode. This link provides a good set of instructions which worked for me (m1 max).
https://www.funkyspacemonkey.com/how-to-install-homebrew-on-m1-macs-running-macos-monterey
I'm not much of a Mac person but I have a 2021 MacBook Pro with M1 silicon. I believe I have found a couple of ways to work around this. There may be a reason why my approaches are bad. If so please enlighten me.
First approach:
This is based on my having installed wkhtmltopdf using brew: brew install --cask wkhtmltopdf
rails console
> WickedPdf.config.merge!({exe_path: '/usr/local/bin/wkhtmltopdf'})
> pdf = WickedPdf.new.pdf_from_string('Hello World')
=> %PDF-1.4\n1 0 obj\n<<\n ...
This approach needs to be coded into the application. It likely needs a coding decision similar to the alternative approach below.
Alternative approach:
Monkey patch the gem file ./gems/wkhtmltopdf-binary-0.12.5.1/bin/wkhtmltopdf changing line 27 from
RbConfig::CONFIG['host_cpu'] == 'x86_64' ? 'macos_cocoa' : 'macos_carbon'
to
(%w(x86_64 arm64).include? RbConfig::CONFIG['host_cpu']) ? 'macos_cocoa' : 'macos_carbon'
I presume the correct approach is to raise a PR against the wkhtmltopdf-binary gem which includes a correctly compiled binary and a modification to the code that selects the correct binary. I don't know about building a binary, nor whether using the one provided by brew would be in contravention of any licensing rules. I've also noticed there are quite a few PRs to add binaries that are yet to be merged.
So I offer this workaround. Please let me know if either of them will lead to pdf generation problems. Obviously I realise the monkey patch will be wiped out by the next gem update.
If anyone is still struggling with installing wkhtmltopdf
on Mac M1 I have just managed to install it using brew.
I have 2021 MacbookPro M1 and my Terminal runs natively (not through Rosetta) and I just ran
brew install wkhtmltopdf
and that worked for me with no issues
If anyone is still struggling with installing
wkhtmltopdf
on Mac M1 I have just managed to install it using brew. I have 2021 MacbookPro M1 and my Terminal runs natively (not through Rosetta) and I just ranbrew install wkhtmltopdf
and that worked for me with no issues
Can confirm this works with PHP on a MacBook from 2022 running an apple silicon chip.
Running a 2023 Macbook Pro M2 Pro without Roseta support
$ uname -a
Darwin xxx 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:39:46 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6020 arm64
$ brew install wkhtmltopdf
...
$ /usr/local/bin/wkhtmltopdf
zsh: bad CPU type in executable: /usr/local/bin/wkhtmltopdf
Installing wkhtmltopdf in a Docker container on M1 Mac. The code in the Dockerfile:
RUN apt-get update \
&& apt-get install -y xfonts-75dpi wget \
&& apt-get install -y xfonts-base wget \
&& wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_arm64.deb \
&& apt install -y ./wkhtmltox_0.12.6.1-2.jammy_arm64.deb \
&& rm ./wkhtmltox_0.12.6.1-2.jammy_arm64.deb
If anyone is still struggling with installing
wkhtmltopdf
on Mac M1 I have just managed to install it using brew. I have 2021 MacbookPro M1 and my Terminal runs natively (not through Rosetta) and I just ranbrew install wkhtmltopdf
and that worked for me with no issues
How did you manage this?
~$ uname -a
Darwin 22.3.0; root:xnu-8792.81.3~2/RELEASE_ARM64_T8103 arm64
$ brew reinstall wkhtmltopdf
==> Downloading https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-2/wkhtmltox-0.12.6-2.macos-cocoa.pkg
wkhtmltopdf was successfully installed!
-bash: /usr/local/bin/wkhtmltoimage: Bad CPU type in executable
-bash: /usr/local/bin/wkhtmltopdf: Bad CPU type in executable
If anyone is still struggling with installing
wkhtmltopdf
on Mac M1 I have just managed to install it using brew. I have 2021 MacbookPro M1 and my Terminal runs natively (not through Rosetta) and I just ranbrew install wkhtmltopdf
and that worked for me with no issuesHow did you manage this?
~$ uname -a Darwin 22.3.0; root:xnu-8792.81.3~2/RELEASE_ARM64_T8103 arm64 $ brew reinstall wkhtmltopdf ==> Downloading https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-2/wkhtmltox-0.12.6-2.macos-cocoa.pkg wkhtmltopdf was successfully installed! -bash: /usr/local/bin/wkhtmltoimage: Bad CPU type in executable -bash: /usr/local/bin/wkhtmltopdf: Bad CPU type in executable
This is working fine for me, however I am hoping to generate the libwkhtmltox.dylib file. Is there any documentation on how these are generated and how I might build on for Mac ARM?
@TimZander you need to run it via Rosetta.
I use wkhtmltopdf in various projects that run on macOS. As far as I know, there are no binaries for Apple Silicon (M1), and I haven't figured out how to build on an M1 Mac.
Is there any hope of getting an ARM build for the Mac?
Thanks to any help and advice.