how to convert rtf to image format ( jpg/png..)

霸气de小男生 提交于 2019-12-11 12:36:40

问题


i need to convert rtf document that contains images (jpgs/pngs ) to image format jpgs or pngs programmaticly , do you have any ideas on how to do it ? on server side (web) Thanks


回答1:


You can use a virtual printing device, for example: http://www.joyprinter.com/




回答2:


If by programmatically, you mean scripts, you could script your RTF program to open files, then export to PDF, then export the PDF to an image. At least, this kind of operation is relatively easy on OS X. You could probably do it entirely in Automator, using TextEdit and Preview. Otherwise, on OS X you could also try accessing the core services that would do the same thing. No clue on Windows though. Hope that helps!




回答3:


You might want to write a bash script to be executed by a cronjob. So at a defined time, or after a defined period, you will have your rtf files converted into jpgs.

Though I don't know if this might satisfy your "programmatic" need .. here is how to do this conversion:

To convert rtf files contain "advanced" features like images, as in your case, you need unoconv, which requires libreoffice to be installed.

unoconv -f pdf "${input_file}"

Otherwise, just for reference because it's not your case, if the rtf files contain only simply text you can avoid the requirement to have libreoffice installed by using a cascade conversion like

// convert rtf to txt
unrtf --text "input_file.rtf" > "temp.txt"

// convert txt to pdf
enscript "temp.txt" -o - | ps2pdf - "temp.pdf"

// convert pdf to jpg
convert -quality 100 -append "temp.pdf" "output.jpg"

// remove temp files
trash "temp.txt" "temp.pdf" // or rm if you prefer


来源:https://stackoverflow.com/questions/1611459/how-to-convert-rtf-to-image-format-jpg-png

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!