简体   繁体   中英

Ghostscript convert pdf to jpg, save file or temp file?

I've a website with many pdf files and i'm using ghostscript to convert PDF to JPG on the fly (while opening the pdf I convert the PDF to JPG and the visitor see the JPG version of the PDF). Now I save the jpg to a certain folder but this using very much of the webspace. So my question is, is it better to save the JPG to a temp file if thats even possible?

I hope you guys understand my question so i hope to get some good advice!

Thanks in advance!

This is the exact problem I had when implementing GhostScript. It is possible and we ended up doing this for our project.

Pros

  • The GhostScript split takes time, and saving the images to a temp location prevents the page load from taking too long
  • Saving the images to a temp folder localizes the files so you can deal with them more effectively when you need to remove them

Cons

  • It takes up space, so you should implement some code to remove the images from the temp folder.

You have some options to handle the temp folder and other variables to consider. We eventually went with deleting the temp folder on a nightly basis, as well as some special instances within the code. Here are some options.

User Leaves the Page

Probably the easiest to implement, but if the user decides to come right back to the page, you will be splitting and saving the files all over again. Not ideal if you are making images for a pdf with many pages

User Ends the Session

A little more difficult to code, but much more reasonble then deleting the files when the user leaves the page. If the user immediately restarts a session, you will encounter the same problem but still its better than the above choice.

Timed Delete

This could be anything from deleting the images within an hour or a week. This is good for general cleanup, but its hard to determine what a proper time limit should be as the user could come back at any time. Its also much more difficult to implement.

Project Specific

There might be an event in your code that happens that makes sense to delete the temp folder. For example, our project deals with properties. When a property is set to 'Sold' or 'Canceled', we delete the temp files for that property because we don't need them anymore.

Thats some of the issues we encountered and discussed for our project, I hope it helps you get a better idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM