Results 1 to 5 of 5

Thread: how to convert pdf to jpg.Any code sniplet?

  1. #1
    Join Date
    Sep 2013
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default how to convert pdf to jpg.Any code sniplet?

    I know how to convert jpg to pdf. but how the reverse is possible?
    is there any way to get the size of Pdf? any native c++/c code?
    please help?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to convert pdf to jpg.Any code sniplet?

    There is nothing Qt to read and manipulate PDF files.
    Here are some open source libraries that do various things with PDFs: Poppler and PoDoFo
    Of course, Adobe offer such tools also.

  3. The following user says thank you to ChrisW67 for this useful post:

    blue_sky (19th December 2013)

  4. #3
    Join Date
    Feb 2014
    Location
    San Jose
    Posts
    4
    Platforms
    Windows

    Default Re: how to convert pdf to jpg.Any code sniplet?

    Hi, did you find anything else that does the pdf-to-image conversion?
    As for converting pdf to jpg, I've used an open source project a while back to turn uploaded pdfs into images for use in an online catalog. Not sure whether it helps. You may have a check.
    Qt Code:
    1. import org.icepdf.core.exceptions.PDFException;
    2. import org.icepdf.core.exceptions.PDFSecurityException;
    3. import org.icepdf.core.pobjects.Document;
    4. import org.icepdf.core.pobjects.Page;
    5. import org.icepdf.core.util.GraphicsRenderingHints;
    6.  
    7.  
    8. public byte[][] convert(byte[] pdf, String format) {
    9.  
    10. Document document = new Document();
    11. try {
    12. document.setByteArray(pdf, 0, pdf.length, null);
    13.  
    14. } catch (PDFException ex) {
    15. System.out.println("Error parsing PDF document " + ex);
    16. } catch (PDFSecurityException ex) {
    17. System.out.println("Error encryption not supported " + ex);
    18. } catch (FileNotFoundException ex) {
    19. System.out.println("Error file not found " + ex);
    20. } catch (IOException ex) {
    21. System.out.println("Error handling PDF document " + ex);
    22. }
    23. byte[][] imageArray = new byte[document.getNumberOfPages()][];
    24. // save page captures to bytearray.
    25. float scale = 1.75f;
    26. float rotation = 0f;
    27.  
    28. // Paint each pages content to an image and write the image to file
    29. for (int i = 0; i < document.getNumberOfPages(); i++) {
    30. BufferedImage image = (BufferedImage)
    31. document.getPageImage(i,
    32. GraphicsRenderingHints.SCREEN,
    33. Page.BOUNDARY_CROPBOX, rotation, scale);
    34. try {
    35. //get the picture util object
    36. PictureUtilLocal pum = (PictureUtilLocal) Component
    37. .getInstance("pictureUtil");
    38. //load image into util
    39. pum.loadBuffered(image);
    40.  
    41. //write image in desired format
    42. imageArray[i] = pum.imageToByteArray(format, 1f);
    43.  
    44. System.out.println("\t capturing page " + i);
    45.  
    46. } catch (IOException e) {
    47. e.printStackTrace();
    48. }
    49. image.flush();
    50. }
    51. // clean up resources
    52. document.dispose();
    53. return imageArray;
    54. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to convert pdf to jpg.Any code sniplet?

    How is this non-C++ (Java?) code related to Qt?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Jul 2016
    Posts
    1
    Platforms
    Windows

    Default Re: how to convert pdf to jpg.Any code sniplet?

    A c++ based open source library is xpdf: http://www.foolabs.com/xpdf/ and its free UI based software: http://pdf-to-jpg-convert.en.softonic.com

Similar Threads

  1. convert c++ class to python code
    By alrawab in forum Qt Programming
    Replies: 8
    Last Post: 25th June 2012, 08:43
  2. help to convert code from c++ to qt
    By ruben.rodrigues in forum Qt Programming
    Replies: 9
    Last Post: 11th May 2011, 14:18
  3. Replies: 3
    Last Post: 23rd December 2010, 00:01
  4. how to convert qt3 code into qt4...
    By kamal in forum Qt Programming
    Replies: 1
    Last Post: 30th June 2010, 08:25
  5. Pasting code from code tag in emacs
    By Gopala Krishna in forum General Discussion
    Replies: 0
    Last Post: 16th February 2007, 05:47

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.