最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Libreoffice excel to pdf conversion problem - Stack Overflow

programmeradmin4浏览0评论

When I am trying to run this code on an excel document:

import subprocess

subprocess.run(['libreoffice', '--headless', '--convert-to', 'pdf',
                'test_docs/doc.xls', '--outdir', 'tmp_docs'])

My document splits by width on 2 pages with the second page as shown below: (.png)

Why would this happen and how to fix this?

When I am trying to run this code on an excel document:

import subprocess

subprocess.run(['libreoffice', '--headless', '--convert-to', 'pdf',
                'test_docs/doc.xls', '--outdir', 'tmp_docs'])

My document splits by width on 2 pages with the second page as shown below: (https://i.sstatic/LRaPbvwd.png)

Why would this happen and how to fix this?

Share Improve this question edited Mar 17 at 14:25 Timus 11.4k5 gold badges17 silver badges31 bronze badges asked Mar 17 at 13:06 IvanIvan 112 bronze badges 5
  • Is changing the excel document an option or you need to do it programmatically? – Gei Stoyanov Commented Mar 17 at 13:21
  • I have a large number of documents to be converted both in excel and doc format and they are being created not by me, therefore edited not by me. – Ivan Commented Mar 17 at 13:24
  • If you run this command from the command line instead of through Python, do you get the same result? – Mark Ransom Commented Mar 17 at 14:58
  • @MarkRansom yes, result is the same. – Ivan Commented Mar 17 at 15:21
  • In that case the problem doesn't belong on this site. You need to find support for the libreoffice application. – Mark Ransom Commented Mar 17 at 18:10
Add a comment  | 

1 Answer 1

Reset to default 1

I have found an answer:

Basically it looks like this is a common issue with excel conversion to pdf, so the solution is to add this line below. It converts a full excel sheet to single pdf page, but I am satisfied with this solution:

'pdf:calc_pdf_Export:{"SinglePageSheets":{"type":"boolean","value":"true"}}'
subprocess.run(['libreoffice', '--headless', '--convert-to', 'pdf:calc_pdf_Export:{"SinglePageSheets":{"type":"boolean","value":"true"}}',
                f'test_docs/{file}', '--outdir', 'tmp_docs'])
发布评论

评论列表(0)

  1. 暂无评论