首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pdftex在bash脚本中失败

pdftex在bash脚本中失败
EN

Stack Overflow用户
提问于 2021-02-04 19:36:44
回答 1查看 88关注 0票数 0

我有bash脚本,采取小册子格式的PDF,并将其转换为单独的页面。该脚本由运行在nginx下的php调用。

我使用的是pdfcrop,它调用pdfTex,这是故障点。

该脚本以root用户身份从命令行运行良好。但是,当由nginx运行(脚本通过php调用)时,当pdfcrop调用pdfTex时,它会失败。

下面是故障点的行:

代码语言:javascript
复制
pdfcrop --ini --verbose --bbox "0 0 1000 600" --margins "-490 10 10 10" ${tempDir}$1 ${tempDir}right.pdf

我记录了详细的输出,并获得了以下内容:

代码语言:javascript
复制
nginx
PDFCROP 1.40, 2020/06/06 - Copyright (c) 2002-2020 by Heiko Oberdiek, Oberdiek Package Support Group.
* PDF header: %PDF-1.5
* Running ghostscript for BoundingBox calculation ...
GPL Ghostscript 9.25 (2018-09-13)
Copyright (C) 2018 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
%%BoundingBox: 90 83 972 571
* Page 1: 0 0 1000 600
%%HiResBoundingBox: 90.674997 83.069997 971.999970 570.725983
Page 2
%%BoundingBox: 33 23 969 572
* Page 2: 0 0 1000 600
%%HiResBoundingBox: 33.731999 23.939999 968.147970 571.697983
* Running pdfTeX ...

第一行'nginx‘是因为我记录了whomami的结果,以确认哪个用户正在运行脚本。请注意,该脚本仅在pdfTex调用时停止。

同样,当从命令行以root用户身份运行时,该脚本可以正常工作。pdfTex似乎对nginx用户不可用。如果是这种情况,我该如何修复它呢?

提亚

编辑:考虑到问题可能是权限问题,pdfTex无法写入其临时文件,我将运行脚本的目录的所有者和组更改为nginx。结果是一样的。

编辑2:下面是对我的脚本的PHP调用:

代码语言:javascript
复制
chdir($scriptDir);
$result = shell_exec('./friedensBulletin.sh' . ' ' . $bulletinName . ' ' . $bulletinName);
chdir($cwd);

$scriptDir是我的脚本所在的位置。将$cwd设置为当前工作目录,然后在此处重置。

编辑3:整个bash脚本

代码语言:javascript
复制
#!/bin/bash

#################################################  
# takes a PDF, crops, exports as html           #
# req. pdfcrop for cropping                     #
# req. poppler (pdftohtml) for file conversion  #
# $1 input file                                 #
# $2 output file                                #
# author: roger@rogercreasy.com                 #
# 01.09.2021                                    #
#################################################

tempDir="tmp/"

# handle pages 1 and 3
pdfcrop --ini --bbox "0 0 1000 600" --margins "-490 10 10 10"   ${tempDir}$1 ${tempDir}right.pdf
pdfseparate ${tempDir}right.pdf ${tempDir}right%d.pdf

#handle pages 2 and 4
pdfcrop --ini --bbox "0 0 1000 600" --margins "10 10 -490 10"    ${tempDir}$1 ${tempDir}left.pdf
pdfseparate ${tempDir}left.pdf ${tempDir}left%d.pdf

#recombine in the correct order
pdfunite ${tempDir}right1.pdf ${tempDir}left2.pdf ${tempDir}right2.pdf   ${tempDir}left1.pdf ${tempDir}tmp.pdf

mv ${tempDir}tmp.pdf $2

# clean up uneeded files
rm ${tempDir}*.pdf
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-08 07:02:48

我最初的理论是pdfTex对nginx用户不可用,这是正确的。

在我的脚本中,我记录了which pdftex的结果。此命令返回未找到。解决方案是创建一个指向pdftex脚本的符号链接。我通过将以下代码添加到我的脚本中实现了这一点。

代码语言:javascript
复制
if ! [[ -L "pdftex" ]]; then
    ln -s /bin/pdftex pdftex
fi

这将检查链接是否存在,如果不存在,则创建它。当然,假设pdftex总是安装在相同的位置,这种方法允许我的脚本在移动到另一台服务器时工作。我通过在命令行上以root用户身份运行‘`which pdftex’找到了pdftex的位置。

感谢pdfcrop的作者Heiko Oberdiek帮助解决了这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66044811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档