Results 1 to 9 of 9
  1. #1
    DMaharana is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default How to check the the size of a pdf file in java ??

    Hi,

    We are using Open Office UNO for pdf conversion. I want to check the size of the pdf file.
    I need to compare the size of 2 pdfs. How can I do??

    Please suggest. Thanks in Advance.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by DMaharana View Post
    Hi,

    We are using Open Office UNO for pdf conversion. I want to check the size of the pdf file.
    I need to compare the size of 2 pdfs. How can I do??

    Please suggest. Thanks in Advance.
    I assume you want the size of the file measured in bytes (what else?) Have a look at the File.length() method.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    DMaharana is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default

    Thank You Jos,

    I did one mistake(forgot to mention the extension). Its working using file.length().
    Its giving 1kb less for each pdf. I can able to resolve the issue now.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by DMaharana View Post
    Its giving 1kb less for each pdf. I can able to resolve the issue now.
    Can you elaborate on that because I don't understand; the File.length() method returns the size of the file measured in bytes and it is accurate.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    DMaharana is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default

    Hi Jos, Please find the code snippet I used to get the size of the file.

    Java Code:
    File file = new File("C:/test.pdf");
            long filesize = file.length();
            System.out.println("1:::" +filesize);
            long filesizeInKB = filesize / 1024;
            System.out.println("Size of File is: " + filesizeInKB + " KB");
    test.pdf is originally 9kb. It gives the size as 8kb.
    same for all files.

    I need to compare pdf files. So it won't be a problem for me.

    Thanks

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by DMaharana View Post
    Hi Jos, Please find the code snippet I used to get the size of the file.

    Java Code:
    File file = new File("C:/test.pdf");
            long filesize = file.length();
            System.out.println("1:::" +filesize);
            long filesizeInKB = filesize / 1024;
            System.out.println("Size of File is: " + filesizeInKB + " KB");
    test.pdf is originally 9kb. It gives the size as 8kb.
    same for all files.

    I need to compare pdf files. So it won't be a problem for me.

    Thanks
    That calculation rounds down; do this instead:

    Java Code:
    long filesizeInKB = (filesize+1023) / 1024;
    or if you don't want to round up do this instead:

    Java Code:
    long filesizeInKB = (filesize+512) / 1024;
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Ever heard of truncation in integer division?

    db

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by DarrylBurke View Post
    Ever heard of truncation in integer division?
    Who? Me? No, please enlighten me ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Quote Originally Posted by JosAH View Post
    Who? Me? No, please enlighten me ;-)

    kind regards,

    Jos
    Boo hoo, just because you got in seconds before me

Similar Threads

  1. Replies: 5
    Last Post: 10-17-2012, 10:07 AM
  2. Using .conf file URL check in java/servlet
    By vali786 in forum Advanced Java
    Replies: 1
    Last Post: 11-26-2010, 12:36 PM
  3. Create a file specifying the size JAVA
    By Harbox in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 01:42 PM
  4. Set the Size of jvm.log file
    By kasidandu in forum New To Java
    Replies: 0
    Last Post: 03-16-2009, 04:08 PM
  5. File size
    By eva in forum New To Java
    Replies: 2
    Last Post: 12-19-2007, 09:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •