How to query pdf page size from the command line?












32















For scripting I need to get the page dimensions of a PDF file (in mm).



pdfinfo just prints it in 'pts', e.g.:



Page size:      624 x 312 pts


What should I use?



Or what unit is 'pts' anyway - in case I want to convert them ...










share|improve this question


















  • 2





    Point on Wikipedia

    – Mat
    May 27 '12 at 18:16













  • Which page did you want the size of? The legal size outer cover? The leaflet size "this page is intentionally blank"? The letter size double pages?

    – Ignacio Vazquez-Abrams
    May 28 '12 at 9:53
















32















For scripting I need to get the page dimensions of a PDF file (in mm).



pdfinfo just prints it in 'pts', e.g.:



Page size:      624 x 312 pts


What should I use?



Or what unit is 'pts' anyway - in case I want to convert them ...










share|improve this question


















  • 2





    Point on Wikipedia

    – Mat
    May 27 '12 at 18:16













  • Which page did you want the size of? The legal size outer cover? The leaflet size "this page is intentionally blank"? The letter size double pages?

    – Ignacio Vazquez-Abrams
    May 28 '12 at 9:53














32












32








32


4






For scripting I need to get the page dimensions of a PDF file (in mm).



pdfinfo just prints it in 'pts', e.g.:



Page size:      624 x 312 pts


What should I use?



Or what unit is 'pts' anyway - in case I want to convert them ...










share|improve this question














For scripting I need to get the page dimensions of a PDF file (in mm).



pdfinfo just prints it in 'pts', e.g.:



Page size:      624 x 312 pts


What should I use?



Or what unit is 'pts' anyway - in case I want to convert them ...







pdf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 27 '12 at 17:48









maxschlepzigmaxschlepzig

33.9k33136213




33.9k33136213








  • 2





    Point on Wikipedia

    – Mat
    May 27 '12 at 18:16













  • Which page did you want the size of? The legal size outer cover? The leaflet size "this page is intentionally blank"? The letter size double pages?

    – Ignacio Vazquez-Abrams
    May 28 '12 at 9:53














  • 2





    Point on Wikipedia

    – Mat
    May 27 '12 at 18:16













  • Which page did you want the size of? The legal size outer cover? The leaflet size "this page is intentionally blank"? The letter size double pages?

    – Ignacio Vazquez-Abrams
    May 28 '12 at 9:53








2




2





Point on Wikipedia

– Mat
May 27 '12 at 18:16







Point on Wikipedia

– Mat
May 27 '12 at 18:16















Which page did you want the size of? The legal size outer cover? The leaflet size "this page is intentionally blank"? The letter size double pages?

– Ignacio Vazquez-Abrams
May 28 '12 at 9:53





Which page did you want the size of? The legal size outer cover? The leaflet size "this page is intentionally blank"? The letter size double pages?

– Ignacio Vazquez-Abrams
May 28 '12 at 9:53










4 Answers
4






active

oldest

votes


















26














The 'pts' unit used by pdfinfo denotes a PostScript point. A PostScript point is defined in terms of an inch and a resolution of 72 dots per inch:




In the late 1980s to the 1990s, the traditional point was supplanted by the desktop publishing point (also called the PostScript point), which was defined as 72 points to the inch (1 point = 1⁄72 inches = 25.4⁄72 mm = 0.352¯7 mm [ ≙ 0.3528 mm] ).




The manual to gv contains a list of common paper formats specified in PostScript points.






share|improve this answer





















  • 1





    on common paper formats: pdfinfo sometimes gives me the paper format (like Page size: 595.28 x 841.89 pts (A4)) — I wonder if it does that for a list of page sizes it knows about?

    – njsg
    May 27 '12 at 20:45






  • 2





    A point is actually 0.352777777... mm, so 0.3528 mm is a closer approximation.

    – cjm
    May 28 '12 at 5:34



















13














Not the easiest way, but given imagemagick and units you could also use



$ identify -verbose some.pdf | grep "Print size" 
Print size: 8.26389x11.6944


to find the page size in inches (this may yield several results if the PDF uses different dimensions) and then convert the numbers like this:



$ units -t '8.26389 inch' 'mm'
209.90281


Meaning that 8.26 inches are 209.9 mm (I used an A4 PDF for this).






share|improve this answer



















  • 1





    When I identify a PDF on OS X I don't get any output.

    – David Moles
    May 31 '16 at 20:58











  • very late, but identify requires ImageMagick

    – defuzed
    Jan 22 at 14:15



















6














Came across the same problem and came to the following solution.
I didn't get into the documentation of how pdf files are constructed I just compared two empty pdf files with different page sizes.



It looks like pdfs have all kinds of attributes embedded between "<<" and ">>". I found that the page size info is there in plain text and can be found with a simple regex search.



This may or may not be true to all pdfs but it worked on all I could find from different sources.



The relevant part can look like any of these for a size A4 page:



/MediaBox [0 0 595 842]
/MediaBox[0 0 595 842]
/MediaBox[ 0 0 595.32 841.92]


It means [0 0 width height] so here is my super lame but working solution to extract this:



cat test.pdf | egrep -ao "/MediaBox ?[ ?[0-9]+ [0-9]+ [0-9]+(.[0-9]+)? [0-9]+(.[0-9]+)?]" | head -1


Just change test.pdf to your file.






share|improve this answer
























  • note that the values returned by this are in "points" not mm, pixels or inches

    – defuzed
    Jan 22 at 14:09



















0














I used maxchlepzigs answer to calculate the mm directly:



$ pdfinfo test.pdf | grep "Page size" | grep -Eo '[-+]?[0-9]*.?[0-9]+' | awk -v x=0.3528 '{print $1*x}'



this also works with Alex Knaufs answer but identify takes much longer than pdfinfo and requires imagemagick, the upside though is that you can use this for multiple files (ie by cd'ing into a directory and using *.pdf):



$ identify -verbose some.pdf | grep "Print size" | grep -Eo '[-+]?[0-9]*.?[0-9]+' | awk -v x=25.4 '{print $1*x}'



The second grep command gets the two point/inch values. I'm fairly sure you can skip the grep regex and do it directly with awk but i couldn't figure it out.






share|improve this answer

























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f39464%2fhow-to-query-pdf-page-size-from-the-command-line%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    26














    The 'pts' unit used by pdfinfo denotes a PostScript point. A PostScript point is defined in terms of an inch and a resolution of 72 dots per inch:




    In the late 1980s to the 1990s, the traditional point was supplanted by the desktop publishing point (also called the PostScript point), which was defined as 72 points to the inch (1 point = 1⁄72 inches = 25.4⁄72 mm = 0.352¯7 mm [ ≙ 0.3528 mm] ).




    The manual to gv contains a list of common paper formats specified in PostScript points.






    share|improve this answer





















    • 1





      on common paper formats: pdfinfo sometimes gives me the paper format (like Page size: 595.28 x 841.89 pts (A4)) — I wonder if it does that for a list of page sizes it knows about?

      – njsg
      May 27 '12 at 20:45






    • 2





      A point is actually 0.352777777... mm, so 0.3528 mm is a closer approximation.

      – cjm
      May 28 '12 at 5:34
















    26














    The 'pts' unit used by pdfinfo denotes a PostScript point. A PostScript point is defined in terms of an inch and a resolution of 72 dots per inch:




    In the late 1980s to the 1990s, the traditional point was supplanted by the desktop publishing point (also called the PostScript point), which was defined as 72 points to the inch (1 point = 1⁄72 inches = 25.4⁄72 mm = 0.352¯7 mm [ ≙ 0.3528 mm] ).




    The manual to gv contains a list of common paper formats specified in PostScript points.






    share|improve this answer





















    • 1





      on common paper formats: pdfinfo sometimes gives me the paper format (like Page size: 595.28 x 841.89 pts (A4)) — I wonder if it does that for a list of page sizes it knows about?

      – njsg
      May 27 '12 at 20:45






    • 2





      A point is actually 0.352777777... mm, so 0.3528 mm is a closer approximation.

      – cjm
      May 28 '12 at 5:34














    26












    26








    26







    The 'pts' unit used by pdfinfo denotes a PostScript point. A PostScript point is defined in terms of an inch and a resolution of 72 dots per inch:




    In the late 1980s to the 1990s, the traditional point was supplanted by the desktop publishing point (also called the PostScript point), which was defined as 72 points to the inch (1 point = 1⁄72 inches = 25.4⁄72 mm = 0.352¯7 mm [ ≙ 0.3528 mm] ).




    The manual to gv contains a list of common paper formats specified in PostScript points.






    share|improve this answer















    The 'pts' unit used by pdfinfo denotes a PostScript point. A PostScript point is defined in terms of an inch and a resolution of 72 dots per inch:




    In the late 1980s to the 1990s, the traditional point was supplanted by the desktop publishing point (also called the PostScript point), which was defined as 72 points to the inch (1 point = 1⁄72 inches = 25.4⁄72 mm = 0.352¯7 mm [ ≙ 0.3528 mm] ).




    The manual to gv contains a list of common paper formats specified in PostScript points.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 28 '12 at 9:47

























    answered May 27 '12 at 19:00









    maxschlepzigmaxschlepzig

    33.9k33136213




    33.9k33136213








    • 1





      on common paper formats: pdfinfo sometimes gives me the paper format (like Page size: 595.28 x 841.89 pts (A4)) — I wonder if it does that for a list of page sizes it knows about?

      – njsg
      May 27 '12 at 20:45






    • 2





      A point is actually 0.352777777... mm, so 0.3528 mm is a closer approximation.

      – cjm
      May 28 '12 at 5:34














    • 1





      on common paper formats: pdfinfo sometimes gives me the paper format (like Page size: 595.28 x 841.89 pts (A4)) — I wonder if it does that for a list of page sizes it knows about?

      – njsg
      May 27 '12 at 20:45






    • 2





      A point is actually 0.352777777... mm, so 0.3528 mm is a closer approximation.

      – cjm
      May 28 '12 at 5:34








    1




    1





    on common paper formats: pdfinfo sometimes gives me the paper format (like Page size: 595.28 x 841.89 pts (A4)) — I wonder if it does that for a list of page sizes it knows about?

    – njsg
    May 27 '12 at 20:45





    on common paper formats: pdfinfo sometimes gives me the paper format (like Page size: 595.28 x 841.89 pts (A4)) — I wonder if it does that for a list of page sizes it knows about?

    – njsg
    May 27 '12 at 20:45




    2




    2





    A point is actually 0.352777777... mm, so 0.3528 mm is a closer approximation.

    – cjm
    May 28 '12 at 5:34





    A point is actually 0.352777777... mm, so 0.3528 mm is a closer approximation.

    – cjm
    May 28 '12 at 5:34













    13














    Not the easiest way, but given imagemagick and units you could also use



    $ identify -verbose some.pdf | grep "Print size" 
    Print size: 8.26389x11.6944


    to find the page size in inches (this may yield several results if the PDF uses different dimensions) and then convert the numbers like this:



    $ units -t '8.26389 inch' 'mm'
    209.90281


    Meaning that 8.26 inches are 209.9 mm (I used an A4 PDF for this).






    share|improve this answer



















    • 1





      When I identify a PDF on OS X I don't get any output.

      – David Moles
      May 31 '16 at 20:58











    • very late, but identify requires ImageMagick

      – defuzed
      Jan 22 at 14:15
















    13














    Not the easiest way, but given imagemagick and units you could also use



    $ identify -verbose some.pdf | grep "Print size" 
    Print size: 8.26389x11.6944


    to find the page size in inches (this may yield several results if the PDF uses different dimensions) and then convert the numbers like this:



    $ units -t '8.26389 inch' 'mm'
    209.90281


    Meaning that 8.26 inches are 209.9 mm (I used an A4 PDF for this).






    share|improve this answer



















    • 1





      When I identify a PDF on OS X I don't get any output.

      – David Moles
      May 31 '16 at 20:58











    • very late, but identify requires ImageMagick

      – defuzed
      Jan 22 at 14:15














    13












    13








    13







    Not the easiest way, but given imagemagick and units you could also use



    $ identify -verbose some.pdf | grep "Print size" 
    Print size: 8.26389x11.6944


    to find the page size in inches (this may yield several results if the PDF uses different dimensions) and then convert the numbers like this:



    $ units -t '8.26389 inch' 'mm'
    209.90281


    Meaning that 8.26 inches are 209.9 mm (I used an A4 PDF for this).






    share|improve this answer













    Not the easiest way, but given imagemagick and units you could also use



    $ identify -verbose some.pdf | grep "Print size" 
    Print size: 8.26389x11.6944


    to find the page size in inches (this may yield several results if the PDF uses different dimensions) and then convert the numbers like this:



    $ units -t '8.26389 inch' 'mm'
    209.90281


    Meaning that 8.26 inches are 209.9 mm (I used an A4 PDF for this).







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered May 28 '12 at 17:59









    Axel KnaufAxel Knauf

    98465




    98465








    • 1





      When I identify a PDF on OS X I don't get any output.

      – David Moles
      May 31 '16 at 20:58











    • very late, but identify requires ImageMagick

      – defuzed
      Jan 22 at 14:15














    • 1





      When I identify a PDF on OS X I don't get any output.

      – David Moles
      May 31 '16 at 20:58











    • very late, but identify requires ImageMagick

      – defuzed
      Jan 22 at 14:15








    1




    1





    When I identify a PDF on OS X I don't get any output.

    – David Moles
    May 31 '16 at 20:58





    When I identify a PDF on OS X I don't get any output.

    – David Moles
    May 31 '16 at 20:58













    very late, but identify requires ImageMagick

    – defuzed
    Jan 22 at 14:15





    very late, but identify requires ImageMagick

    – defuzed
    Jan 22 at 14:15











    6














    Came across the same problem and came to the following solution.
    I didn't get into the documentation of how pdf files are constructed I just compared two empty pdf files with different page sizes.



    It looks like pdfs have all kinds of attributes embedded between "<<" and ">>". I found that the page size info is there in plain text and can be found with a simple regex search.



    This may or may not be true to all pdfs but it worked on all I could find from different sources.



    The relevant part can look like any of these for a size A4 page:



    /MediaBox [0 0 595 842]
    /MediaBox[0 0 595 842]
    /MediaBox[ 0 0 595.32 841.92]


    It means [0 0 width height] so here is my super lame but working solution to extract this:



    cat test.pdf | egrep -ao "/MediaBox ?[ ?[0-9]+ [0-9]+ [0-9]+(.[0-9]+)? [0-9]+(.[0-9]+)?]" | head -1


    Just change test.pdf to your file.






    share|improve this answer
























    • note that the values returned by this are in "points" not mm, pixels or inches

      – defuzed
      Jan 22 at 14:09
















    6














    Came across the same problem and came to the following solution.
    I didn't get into the documentation of how pdf files are constructed I just compared two empty pdf files with different page sizes.



    It looks like pdfs have all kinds of attributes embedded between "<<" and ">>". I found that the page size info is there in plain text and can be found with a simple regex search.



    This may or may not be true to all pdfs but it worked on all I could find from different sources.



    The relevant part can look like any of these for a size A4 page:



    /MediaBox [0 0 595 842]
    /MediaBox[0 0 595 842]
    /MediaBox[ 0 0 595.32 841.92]


    It means [0 0 width height] so here is my super lame but working solution to extract this:



    cat test.pdf | egrep -ao "/MediaBox ?[ ?[0-9]+ [0-9]+ [0-9]+(.[0-9]+)? [0-9]+(.[0-9]+)?]" | head -1


    Just change test.pdf to your file.






    share|improve this answer
























    • note that the values returned by this are in "points" not mm, pixels or inches

      – defuzed
      Jan 22 at 14:09














    6












    6








    6







    Came across the same problem and came to the following solution.
    I didn't get into the documentation of how pdf files are constructed I just compared two empty pdf files with different page sizes.



    It looks like pdfs have all kinds of attributes embedded between "<<" and ">>". I found that the page size info is there in plain text and can be found with a simple regex search.



    This may or may not be true to all pdfs but it worked on all I could find from different sources.



    The relevant part can look like any of these for a size A4 page:



    /MediaBox [0 0 595 842]
    /MediaBox[0 0 595 842]
    /MediaBox[ 0 0 595.32 841.92]


    It means [0 0 width height] so here is my super lame but working solution to extract this:



    cat test.pdf | egrep -ao "/MediaBox ?[ ?[0-9]+ [0-9]+ [0-9]+(.[0-9]+)? [0-9]+(.[0-9]+)?]" | head -1


    Just change test.pdf to your file.






    share|improve this answer













    Came across the same problem and came to the following solution.
    I didn't get into the documentation of how pdf files are constructed I just compared two empty pdf files with different page sizes.



    It looks like pdfs have all kinds of attributes embedded between "<<" and ">>". I found that the page size info is there in plain text and can be found with a simple regex search.



    This may or may not be true to all pdfs but it worked on all I could find from different sources.



    The relevant part can look like any of these for a size A4 page:



    /MediaBox [0 0 595 842]
    /MediaBox[0 0 595 842]
    /MediaBox[ 0 0 595.32 841.92]


    It means [0 0 width height] so here is my super lame but working solution to extract this:



    cat test.pdf | egrep -ao "/MediaBox ?[ ?[0-9]+ [0-9]+ [0-9]+(.[0-9]+)? [0-9]+(.[0-9]+)?]" | head -1


    Just change test.pdf to your file.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 1 '14 at 12:53









    Peter RakmanyiPeter Rakmanyi

    16112




    16112













    • note that the values returned by this are in "points" not mm, pixels or inches

      – defuzed
      Jan 22 at 14:09



















    • note that the values returned by this are in "points" not mm, pixels or inches

      – defuzed
      Jan 22 at 14:09

















    note that the values returned by this are in "points" not mm, pixels or inches

    – defuzed
    Jan 22 at 14:09





    note that the values returned by this are in "points" not mm, pixels or inches

    – defuzed
    Jan 22 at 14:09











    0














    I used maxchlepzigs answer to calculate the mm directly:



    $ pdfinfo test.pdf | grep "Page size" | grep -Eo '[-+]?[0-9]*.?[0-9]+' | awk -v x=0.3528 '{print $1*x}'



    this also works with Alex Knaufs answer but identify takes much longer than pdfinfo and requires imagemagick, the upside though is that you can use this for multiple files (ie by cd'ing into a directory and using *.pdf):



    $ identify -verbose some.pdf | grep "Print size" | grep -Eo '[-+]?[0-9]*.?[0-9]+' | awk -v x=25.4 '{print $1*x}'



    The second grep command gets the two point/inch values. I'm fairly sure you can skip the grep regex and do it directly with awk but i couldn't figure it out.






    share|improve this answer






























      0














      I used maxchlepzigs answer to calculate the mm directly:



      $ pdfinfo test.pdf | grep "Page size" | grep -Eo '[-+]?[0-9]*.?[0-9]+' | awk -v x=0.3528 '{print $1*x}'



      this also works with Alex Knaufs answer but identify takes much longer than pdfinfo and requires imagemagick, the upside though is that you can use this for multiple files (ie by cd'ing into a directory and using *.pdf):



      $ identify -verbose some.pdf | grep "Print size" | grep -Eo '[-+]?[0-9]*.?[0-9]+' | awk -v x=25.4 '{print $1*x}'



      The second grep command gets the two point/inch values. I'm fairly sure you can skip the grep regex and do it directly with awk but i couldn't figure it out.






      share|improve this answer




























        0












        0








        0







        I used maxchlepzigs answer to calculate the mm directly:



        $ pdfinfo test.pdf | grep "Page size" | grep -Eo '[-+]?[0-9]*.?[0-9]+' | awk -v x=0.3528 '{print $1*x}'



        this also works with Alex Knaufs answer but identify takes much longer than pdfinfo and requires imagemagick, the upside though is that you can use this for multiple files (ie by cd'ing into a directory and using *.pdf):



        $ identify -verbose some.pdf | grep "Print size" | grep -Eo '[-+]?[0-9]*.?[0-9]+' | awk -v x=25.4 '{print $1*x}'



        The second grep command gets the two point/inch values. I'm fairly sure you can skip the grep regex and do it directly with awk but i couldn't figure it out.






        share|improve this answer















        I used maxchlepzigs answer to calculate the mm directly:



        $ pdfinfo test.pdf | grep "Page size" | grep -Eo '[-+]?[0-9]*.?[0-9]+' | awk -v x=0.3528 '{print $1*x}'



        this also works with Alex Knaufs answer but identify takes much longer than pdfinfo and requires imagemagick, the upside though is that you can use this for multiple files (ie by cd'ing into a directory and using *.pdf):



        $ identify -verbose some.pdf | grep "Print size" | grep -Eo '[-+]?[0-9]*.?[0-9]+' | awk -v x=25.4 '{print $1*x}'



        The second grep command gets the two point/inch values. I'm fairly sure you can skip the grep regex and do it directly with awk but i couldn't figure it out.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 23 at 9:50

























        answered Jan 22 at 11:32









        defuzeddefuzed

        1012




        1012






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f39464%2fhow-to-query-pdf-page-size-from-the-command-line%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to make a Squid Proxy server?

            第一次世界大戦

            Touch on Surface Book