convert pdf to image - imagemagick - ghostscript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ciary
    Recognized Expert New Member
    • Apr 2009
    • 247

    convert pdf to image - imagemagick - ghostscript

    hi all,

    it's my second question of today but since i'm stuck with this problem, i'm going to ask it anyway. i'm trying to convert an uploaded pdf file to a jpg, gif or png file. i want to use it as a background image. the problem isn't uploading the file, it's converting the file from pdf to an image.

    first, i tried to use imagick. so i installed ghostscript and imagemagick. but then the problems began. i searched 4 days to find a way to get imagick working in php. i tried nearly every solution on google without a positive result. i'm using xampp on windows XP.

    does anyone know, in detail how you should install imagick or does anyone know another way to convert pdf files in to images using php.

    one other thing. the solution needs to contain a function to rotate the image as well. this might complicate things.

    still, i hope someone can help me.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    So you want something like an image of the pdf? Not quite sure how you'd do that, apart from create an app that reads the data and then builds it as an image. That'd be a hard thing to do, I guess.

    Good luck.

    - mark.

    Comment

    • Ciary
      Recognized Expert New Member
      • Apr 2009
      • 247

      #3
      i found on the php.net website a way to do it with imagick but i have a problem implementing and installing it.

      for the interrested: this is the way to convert pdf to image if you get it installed

      [EDIT] so, if anyone knows another way. or if anyone knows exacly how to install imagick, i'm here to hear your solutions

      Comment

      • Ciary
        Recognized Expert New Member
        • Apr 2009
        • 247

        #4
        come on!!

        is there really no one who knows how to install imagemagick and imagick properly? i really need this.

        il give you a billion thanks and a kiss of you want to :-)

        please!! it's urgent :-(

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Installation of imagick.

          I've never used it so I can't be of much help.

          - mark.

          Comment

          • secmazec
            New Member
            • Mar 2009
            • 34

            #6
            I could also use this code for thumbnails on my Website. Big thanks to whoever can and will code it in shortest possible form. :-)

            Comment

            • Ciary
              Recognized Expert New Member
              • Apr 2009
              • 247

              #7
              tried that already and it didn't work. but thanks anyway Markus.

              secmazec, coding it is the easy part. it's only 8 lines to convert a pdf to an image. installing imagick on windows is a lot harder.

              Code:
              <?php
              $im = new imagick( 'test.pdf[ 0]' ); 
              
              $im->setImageColorspace(255);
              $im->setCompression(Imagick::COMPRESSION_JPEG);
              $im->setCompressionQuality(100);
              $im->setImageFormat('jpeg');
              
              $im->writeImage('thumb.jpg');
              $im->clear();
              $im->destroy();
              ?>
              you will need to install ghostscript too because imagick itself can't handle pdf-files. So, if you get it installed, please let me know.

              Comment

              • secmazec
                New Member
                • Mar 2009
                • 34

                #8
                Thanks Ciary, now I understand.

                Comment

                • Ciary
                  Recognized Expert New Member
                  • Apr 2009
                  • 247

                  #9
                  my first question on this forum and after a few weeks, i've finally solved it.

                  the first thing you need to do when you want to convert a PDF to an image at runtime in php is ... (fill in all abusive content you can think of but the admin doesn't permit me to write) ... with imagick.

                  after that you install imagemagick and ghostscript
                  then you write the code: remember that in imagick you needed 5 lines of code. when using ghostscript and imagemagick (things you also needed with imagick) you need this:

                  Code:
                  exec(convert upload/test.pdf upload/test.jpg)
                  you noticed correct. it's only 1 line of code. i'm not sure if it can be used on a unix/linux server but there, installing imagick is a lot easier.

                  i hope i didn't offend anyone and helped a lot of ppl with this post

                  grtz

                  Jan

                  ps. srr if i sound rude in this post, but i'm a bit frustrated that i searched 3 weeks to find something that simple. and only because of ****** imagick.

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    This will be helpful to a lot of people, I expect.

                    I'll update the post title so that it'll get more attention (via google).

                    Comment

                    • Ciary
                      Recognized Expert New Member
                      • Apr 2009
                      • 247

                      #11
                      a final update on this post about imagick. as every morning, i turn on pc and started my apache. and as always i first run a php_info().

                      today (after 2 months of searching) ****** imagick suddenly appears in my info. which means it can be used X-|. why today: no idea, i think imagick suddenly thought "i waited long enough, let's start working"

                      so the solutions to install imagick is doing everything on google and then ... wait for 2 months.

                      Comment

                      • jayapalchandran
                        New Member
                        • Sep 2007
                        • 5

                        #12
                        how about using .so files in current folder of the server

                        hi,
                        i am going to try the above because this is what i was searching for. anyway...
                        like in windows why dont php offer an option to save the libraries in current script execution folder and load it dynamically instead of setting up it in the ini file...
                        because in shared hosting (where most of the sites are this) it is not possible to modify the php.ini because it reflects to all users... can you suggest something for this... it is really bad that we cannot use much third party controls in php becuse of shared hosting... then what is the point of the world upgrading and upgrading...
                        99 percent web site owners cannot offer a dedicated hosting... so.... expecting your comment...

                        Comment

                        • Ciary
                          Recognized Expert New Member
                          • Apr 2009
                          • 247

                          #13
                          well if you are using shared hosting, your provider will need to install it on it's server and give the posibility to its clients. it will cost you extra though. therefore, imagick isn't possible on most shared hosting servers. if you want it, you'll have to host it yourself or ask the hosting company to install it for you.

                          on the comment why you just can't copy your libraries. it's because imagick will just use imagemagick.exe to transform its images. so it needs to be installed. there is a reason why this isn't provided by most hosting companies though. imagemagick asks for a heavy CPU-use. because of this, other users might find problems connecting to the server.

                          if you really need PDF processing, try using your own webserver :-s

                          i hope this is an answer to your problem (although it isn't really a solution)

                          Comment

                          • jayapalchandran
                            New Member
                            • Sep 2007
                            • 5

                            #14
                            how to get it to work

                            Hi,
                            PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.

                            i followed the instructions in the above link... i downloaded the dll file and i pasted in ext folder... uncommented it in ini file.. restarted apache... (windows)...

                            it did not appear in phpinfo... class not found when i ran my script...

                            could you give me suggestions...

                            below the code in the above link another post stated that an old version of PECL made it work...

                            Comment

                            • Ciary
                              Recognized Expert New Member
                              • Apr 2009
                              • 247

                              #15
                              as said in a previous post, i encountered the same problem. i waited two months and then it suddenly did work. i cant explain how and why but it did

                              if you wont want to wait that long i suggest using exec and a full imagemagick command. this does work.

                              Comment

                              Working...