Repository navigation
feat: add Oxi (oxidocs) converter for docx to pdf and png #708
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
Open
Ryujiyasu
wants to merge
8
commits into
C4illin:main
Choose a base branch
from
Ryujiyasu:add-oxidocs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+273
−103
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
665db27
feat: add Oxi (oxidocs) converter for docx to pdf and png
Ryujiyasu 7232689
fix: verify the oxidocs download and convert with --strict
Ryujiyasu 0e0f694
chore: let Renovate update oxidocs, verified against the release's .s…
Ryujiyasu e8ca063
feat: oxidocs converts pptx (pdf, png) and xlsx (pdf); simpler Renova…
Ryujiyasu 7b435f1
feat: oxidocs 0.9.0-static.6, xlsx to png
Ryujiyasu d38385d
Merge upstream main into add-oxidocs (bun 1.4.5 base image)
Ryujiyasu 94fd201
Merge remote-tracking branch 'upstream/main' into add-oxidocs
Ryujiyasu 3a413ba
build: lay out oxidocs' bundled fonts at build time, so they are ther…
Ryujiyasu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,102 +1,120 @@ | ||
| FROM oven/bun:1.4.5-slim AS base | ||
| WORKDIR /app | ||
| COPY package.json bun.lock /app/ | ||
| RUN bun install --frozen-lockfile | ||
| COPY . . | ||
|
|
||
| RUN bun run build:bin | ||
|
|
||
| FROM debian:testing-slim AS release | ||
| LABEL org.opencontainers.image.source="https://github.com/C4illin/ConvertX" | ||
| WORKDIR /app | ||
|
|
||
| # install additional dependencies | ||
| ENV PIPX_HOME=/opt/pipx | ||
| ENV PIPX_BIN_DIR=/usr/local/bin | ||
|
|
||
| RUN apt-get update && apt-get install -y \ | ||
| assimp-utils \ | ||
| ca-certificates \ | ||
| calibre \ | ||
| curl \ | ||
| dasel \ | ||
| dcraw \ | ||
| djvulibre-bin \ | ||
| dvisvgm \ | ||
| ffmpeg \ | ||
| ghostscript \ | ||
| gosu \ | ||
| graphicsmagick \ | ||
| imagemagick-7.q16 \ | ||
| inkscape \ | ||
| latexmk \ | ||
| libheif-examples \ | ||
| libjxl-tools \ | ||
| libreoffice-calc-nogui \ | ||
| libreoffice-draw-nogui \ | ||
| libreoffice-writer-nogui \ | ||
| libva2 \ | ||
| libvips-tools \ | ||
| libemail-address-perl \ | ||
| libemail-outlook-message-perl \ | ||
| lmodern \ | ||
| mupdf-tools \ | ||
| pandoc \ | ||
| poppler-utils \ | ||
| potrace \ | ||
| python3-numpy \ | ||
| python3-tinycss2 \ | ||
| resvg \ | ||
| texlive \ | ||
| texlive-fonts-recommended \ | ||
| texlive-latex-extra \ | ||
| texlive-latex-recommended \ | ||
| texlive-xetex \ | ||
| python3 \ | ||
| python3-pip \ | ||
| pipx \ | ||
| --no-install-recommends \ | ||
| && pipx install "markitdown[all]" \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Remove when patch is released | ||
| RUN pipx runpip markitdown install --upgrade --no-cache-dir "Brotli>=1.2.1" "brotlicffi>=1.2.1.0" | ||
|
|
||
| RUN groupadd -g 1000 convertx && \ | ||
| useradd -u 1000 -g convertx -d /home/convertx -m -s /bin/bash convertx | ||
|
|
||
| # Install VTracer binary | ||
| RUN ARCH=$(uname -m) && \ | ||
| if [ "$ARCH" = "aarch64" ]; then \ | ||
| VTRACER_ASSET="vtracer-aarch64-unknown-linux-musl.tar.gz"; \ | ||
| else \ | ||
| VTRACER_ASSET="vtracer-x86_64-unknown-linux-musl.tar.gz"; \ | ||
| fi && \ | ||
| curl -L -o /tmp/vtracer.tar.gz "https://github.com/visioncortex/vtracer/releases/download/0.6.4/${VTRACER_ASSET}" && \ | ||
| tar -xzf /tmp/vtracer.tar.gz -C /tmp/ && \ | ||
| mv /tmp/vtracer /usr/local/bin/vtracer && \ | ||
| chmod +x /usr/local/bin/vtracer && \ | ||
| rm /tmp/vtracer.tar.gz | ||
|
|
||
| COPY --from=base /app/public/ /app/public/ | ||
| COPY --from=base /app/dist/convertx /app/convertx | ||
|
|
||
| # COPY . . | ||
| RUN mkdir data | ||
|
|
||
| COPY entrypoint.sh /entrypoint.sh | ||
| RUN chmod +x /entrypoint.sh | ||
|
|
||
| EXPOSE 3000/tcp | ||
| # used for calibre | ||
| ENV QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox" | ||
| ENV NODE_ENV=production | ||
| ENTRYPOINT [ "/entrypoint.sh" ] | ||
| CMD [ "/app/convertx" ] | ||
|
|
||
| # test stage that includes Bun for running tests if needed | ||
| FROM release AS test | ||
| COPY --from=base /usr/local/bin/bun /usr/local/bin/bun | ||
|
|
||
| # default target remains release | ||
| FROM release | ||
| FROM oven/bun:1.4.5-slim AS base | ||
| WORKDIR /app | ||
| COPY package.json bun.lock /app/ | ||
| RUN bun install --frozen-lockfile | ||
| COPY . . | ||
|
|
||
| RUN bun run build:bin | ||
|
|
||
| FROM debian:testing-slim AS release | ||
| LABEL org.opencontainers.image.source="https://github.com/C4illin/ConvertX" | ||
| WORKDIR /app | ||
|
|
||
| # install additional dependencies | ||
| ENV PIPX_HOME=/opt/pipx | ||
| ENV PIPX_BIN_DIR=/usr/local/bin | ||
|
|
||
| RUN apt-get update && apt-get install -y \ | ||
| assimp-utils \ | ||
| ca-certificates \ | ||
| calibre \ | ||
| curl \ | ||
| dasel \ | ||
| dcraw \ | ||
| djvulibre-bin \ | ||
| dvisvgm \ | ||
| ffmpeg \ | ||
| ghostscript \ | ||
| gosu \ | ||
| graphicsmagick \ | ||
| imagemagick-7.q16 \ | ||
| inkscape \ | ||
| latexmk \ | ||
| libheif-examples \ | ||
| libjxl-tools \ | ||
| libreoffice-calc-nogui \ | ||
| libreoffice-draw-nogui \ | ||
| libreoffice-writer-nogui \ | ||
| libva2 \ | ||
| libvips-tools \ | ||
| libemail-address-perl \ | ||
| libemail-outlook-message-perl \ | ||
| lmodern \ | ||
| mupdf-tools \ | ||
| pandoc \ | ||
| poppler-utils \ | ||
| potrace \ | ||
| python3-numpy \ | ||
| python3-tinycss2 \ | ||
| resvg \ | ||
| texlive \ | ||
| texlive-fonts-recommended \ | ||
| texlive-latex-extra \ | ||
| texlive-latex-recommended \ | ||
| texlive-xetex \ | ||
| python3 \ | ||
| python3-pip \ | ||
| pipx \ | ||
| --no-install-recommends \ | ||
| && pipx install "markitdown[all]" \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Remove when patch is released | ||
| RUN pipx runpip markitdown install --upgrade --no-cache-dir "Brotli>=1.2.1" "brotlicffi>=1.2.1.0" | ||
|
|
||
| RUN groupadd -g 1000 convertx && \ | ||
| useradd -u 1000 -g convertx -d /home/convertx -m -s /bin/bash convertx | ||
|
|
||
| # Install VTracer binary | ||
| RUN ARCH=$(uname -m) && \ | ||
| if [ "$ARCH" = "aarch64" ]; then \ | ||
| VTRACER_ASSET="vtracer-aarch64-unknown-linux-musl.tar.gz"; \ | ||
| else \ | ||
| VTRACER_ASSET="vtracer-x86_64-unknown-linux-musl.tar.gz"; \ | ||
| fi && \ | ||
| curl -L -o /tmp/vtracer.tar.gz "https://github.com/visioncortex/vtracer/releases/download/0.6.4/${VTRACER_ASSET}" && \ | ||
| tar -xzf /tmp/vtracer.tar.gz -C /tmp/ && \ | ||
| mv /tmp/vtracer /usr/local/bin/vtracer && \ | ||
| chmod +x /usr/local/bin/vtracer && \ | ||
| rm /tmp/vtracer.tar.gz | ||
|
|
||
| # Install oxidocs binary (docx, pptx and xlsx to pdf/png). It writes the fonts it | ||
| # carries next to itself on first use, so that is done here, as root: with PUID | ||
| # set, /usr/local/bin is not writable when it runs. | ||
| # renovate: datasource=github-releases depName=Ryujiyasu/oxi versioning=regex:^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:-static\.(?<build>\d+))?$ extractVersion=^oxidocs-v(?<version>.+)$ | ||
| ARG OXIDOCS_VERSION=0.9.0-static.6 | ||
| RUN ARCH=$(uname -m) && \ | ||
| if [ "$ARCH" = "aarch64" ]; then \ | ||
| OXIDOCS_ASSET="oxidocs-aarch64-unknown-linux-musl"; \ | ||
| else \ | ||
| OXIDOCS_ASSET="oxidocs-x86_64-unknown-linux-musl"; \ | ||
| fi && \ | ||
| curl -fL -o /tmp/oxidocs.tar.gz "https://github.com/Ryujiyasu/oxi/releases/download/oxidocs-v${OXIDOCS_VERSION}/${OXIDOCS_ASSET}.tar.gz" && \ | ||
| tar -xzf /tmp/oxidocs.tar.gz -C /tmp/ && \ | ||
| mv "/tmp/${OXIDOCS_ASSET}/oxidocs" /usr/local/bin/oxidocs && \ | ||
| chmod +x /usr/local/bin/oxidocs && \ | ||
| oxidocs fonts-index > /dev/null && \ | ||
| rm -r /tmp/oxidocs.tar.gz "/tmp/${OXIDOCS_ASSET}" | ||
|
|
||
| COPY --from=base /app/public/ /app/public/ | ||
| COPY --from=base /app/dist/convertx /app/convertx | ||
|
|
||
| # COPY . . | ||
| RUN mkdir data | ||
|
|
||
| COPY entrypoint.sh /entrypoint.sh | ||
| RUN chmod +x /entrypoint.sh | ||
|
|
||
| EXPOSE 3000/tcp | ||
| # used for calibre | ||
| ENV QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox" | ||
| ENV NODE_ENV=production | ||
| ENTRYPOINT [ "/entrypoint.sh" ] | ||
| CMD [ "/app/convertx" ] | ||
|
|
||
| # test stage that includes Bun for running tests if needed | ||
| FROM release AS test | ||
| COPY --from=base /usr/local/bin/bun /usr/local/bin/bun | ||
|
|
||
| # default target remains release | ||
| FROM release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| "heif-info", | ||
| "potrace", | ||
| "soffice", | ||
| "oxidocs", | ||
| "perl", | ||
| "markitdown" | ||
| ], | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { execFile as execFileOriginal } from "node:child_process"; | ||
|
|
||
| import { ExecFileFn } from "./types"; | ||
|
|
||
| export const properties = { | ||
| from: { | ||
| text: ["docx", "docm", "dotx"], | ||
| presentation: ["pptx", "pptm", "potx"], | ||
| calc: ["xlsx", "xlsm", "xltx", "xltm"], | ||
| }, | ||
| to: { | ||
| text: ["pdf", "png"], | ||
| presentation: ["pdf", "png"], | ||
| calc: ["pdf", "png"], | ||
| }, | ||
| }; | ||
|
|
||
| const presentations = new Set(properties.from.presentation); | ||
| const workbooks = new Set(properties.from.calc); | ||
|
|
||
| export function convert( | ||
| filePath: string, | ||
| fileType: string, | ||
| convertTo: string, | ||
| targetPath: string, | ||
| options?: unknown, | ||
| execFile: ExecFileFn = execFileOriginal, // to make it mockable | ||
| ): Promise<string> { | ||
| // png draws the first page (the first slide, the first printed page of a | ||
| // workbook); pdf converts the whole | ||
| // document, every slide, or the print areas of every visible sheet. | ||
| // --strict: when the document holds content Oxi does not draw, it writes | ||
| // nothing and fails (naming the content) rather than hand back a file with | ||
| // parts missing; LibreOffice can then be chosen instead. | ||
| // --quiet: nothing is printed on success, only warnings and errors | ||
| const kind = presentations.has(fileType) ? "pptx" : workbooks.has(fileType) ? "xlsx" : "docx"; | ||
| const command = `${kind}-to-${convertTo === "png" ? "png" : "pdf"}`; | ||
|
|
||
| return new Promise((resolve, reject) => { | ||
| execFile( | ||
| "oxidocs", | ||
| [command, "--strict", "--quiet", filePath, targetPath], | ||
| (error, stdout, stderr) => { | ||
| if (error) { | ||
| reject(`error: ${error}`); | ||
| } | ||
|
|
||
| if (stdout) { | ||
| console.log(`stdout: ${stdout}`); | ||
| } | ||
|
|
||
| if (stderr) { | ||
| console.error(`stderr: ${stderr}`); | ||
| } | ||
|
|
||
| resolve("Done"); | ||
| }, | ||
| ); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The new category targets let the
/convertendpoint accept xlsx→png through oxidocs, then run unsupportedxlsx-to-png. Validate the target against the uploaded file's input category before starting conversion.Prompt for AI agents