使用Pandoc生成docx文件:图像丢失!由于多个请求? [英] Generating a docx file using Pandoc: images missing! Due to multiple requests?

查看:71
本文介绍了使用Pandoc生成docx文件:图像丢失!由于多个请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 4.2应用程序生成降价文档,其中包括位于同一服务器(位于 public 文件夹中)中的图像.

I'm generating a markdown document using my Rails 4.2 app which includes images that are on the same server (in the public folder).

我要使用pandoc(pandoc-ruby 1.0.0)将文档转换成各种格式,尤其是HTML(在浏览器中预览)和DOCX(下载).

Using pandoc (pandoc-ruby 1.0.0), I want to convert the document into various formats, especially HTML (to preview it in the browser) and DOCX (to download it).

浏览器中的预览效果很好.但是当转换为DOCX时,不包括图像.我想这是由于Pandoc生成文档时对参考图像的多次请求所致.

The preview in the browser works perfect. But when converting to DOCX, the images aren't included. I guess this is due to multiple requests to referenced images while pandoc is generating the document.

我已经尝试将 allow_concurrency 设置为 true ,但这并不能解决问题.而且,它同时发生在开发和生产环境中(在开发中,它需要很长时间,而在生产中则不需要-可能是由于超时限制方面的某些差异?).

I have already experimented with setting allow_concurrency to true, but this didn't solve the problem. Also, it happens on both the development and the production environment (while in development, it takes a long time, and in production it doesn't - maybe due to some differences in timeout limits?).

我已经找到一种解决问题的方法,方法是不使用URL引用图像,而是将其作为base64字符串嵌入文档中.但这肯定不是解决方案,因为它会使HTML文档大量膨胀.另外,在生产中,我已经从很小的嵌入式图像中得到了 RuntimeError(堆栈空间溢出:当前大小8388608字节).所以我必须找到一个真正的解决方案.

I have already found a way to solve my problem by not referencing the images using an URL, but by embedding it as base64 string into the document. But this for sure can't be the solution of choice, as it tends to bloat up the HTML document a lot. Also, on production, I already get RuntimeError (Stack space overflow: current size 8388608 bytes) from pretty small embedded images. So I have to find a real solution.

推荐答案

如果图像位于同一服务器上,请按文件路径而不是url引用图像.

Reference the images by file path instead of url if they are on the same server.

这篇关于使用Pandoc生成docx文件:图像丢失!由于多个请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆