wand.exceptions.PolicyError: not authorized `/tmp/xxx.pdf' Ubuntu PDF转图片错误

问题:

这个错误是由于python的wand库调用ImageMagick的convert命令导致的错误

convert /tmp/123.pdf /tmp/123.png

也是同样的错误

解决方法:

/etc/ 下的ImageMagick目录 也有可能是ImageMagick-6目录

vim policy.xml

<policy domain="coder" rights="none" pattern="PDF" />

改为

<policy domain="coder" rights="read|write" pattern="PDF" />

即可, 记得重启服务器

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是使用ImageMagickPDF换为图片的C语言代码示例: ```c #include <stdio.h> #include <stdlib.h> #include <wand/MagickWand.h> int main(int argc, char **argv) { MagickWand *magick_wand; MagickBooleanType status; MagickPixelPacket pixel; PixelIterator *iterator; ExceptionInfo *exception; char *pdf_file = "example.pdf"; char *image_file = "example.jpg"; int width, height; MagickWandGenesis(); exception = AcquireExceptionInfo(); magick_wand = NewMagickWand(); status = MagickReadImage(magick_wand, pdf_file); if (status == MagickFalse) { CatchException(exception); fprintf(stderr, "Failed to read PDF file %s\n", pdf_file); return 1; } MagickResetIterator(magick_wand); iterator = NewPixelIterator(magick_wand); width = MagickGetImageWidth(magick_wand); height = MagickGetImageHeight(magick_wand); for (int y = 0; y < height; y++) { PixelWand **pixels = PixelGetNextIteratorRow(iterator, &width); for (int x = 0; x < width; x++) { PixelGetMagickColor(pixels[x], &pixel); // Do something with the pixel color } PixelSyncIterator(iterator); } status = MagickWriteImage(magick_wand, image_file); if (status == MagickFalse) { CatchException(exception); fprintf(stderr, "Failed to write image file %s\n", image_file); return 1; } magick_wand = DestroyMagickWand(magick_wand); exception = DestroyExceptionInfo(exception); MagickWandTerminus(); return 0; } ``` 上述代码使用ImageMagick的MagickWand API读取PDF文件并将其换为JPEG格式的图像。你可以根据需要更改输出图像的格式。请注意,你需要安装ImageMagick库和开发文件才能编译此代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值