Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9206833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:15:32+00:00 2026-06-18T00:15:32+00:00

I have a bunch of PDF files- I read these as requested into a

  • 0

I have a bunch of PDF files- I read these as requested into a byte array and then also pass it to a iTextSharp PdfReader instance. I want to then grab the dimensions of each page- in pixels. From what I’ve read so far it seems by PDF files work in points- a point being a configurable unit stored in some kind of dictionary in an element called UserUnit.

Loading my PDF File into a PdfReader, what do I need to do to get the UserUnit for each page (apparently it can vary from page to page) so I can then get the page dimensions in pixels.

At present I have this code, which grabs the dimensions for each page in “points” – guess I just need the UerUnit, and can then multiply these dimensions by that to get pixels or something similar.

//Create an object to read the PDF
PdfReader reader = new iTextSharp.text.pdf.PdfReader(file_content);

for (int i = 1; i <= reader.NumberOfPages; i++)
{
  Rectangle dim = reader.GetPageSize(i);
  int[] xy = new int[] { (int)dim.Width, (int)dim.Height };  // returns page size in "points"
  page_data[objectid + '-' + i] = xy;
}

Cheers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:15:33+00:00Added an answer on June 18, 2026 at 12:15 am

    Allow me to quote from my book:

    iText in Action – Second Edition, page 9:

    FAQ What is the measurement unit in PDF documents? Most of the measurements
    in PDFs are expressed in user space units. ISO-32000-1 (section 8.3.2.3) tells us
    “the default for the size of the unit in default user space (1/72 inch) is
    approximately the same as a point (pt), a unit widely used in the printing
    industry. It is not exactly the same; there is no universal definition of a point.”
    In short, 1 in. = 25.4 mm = 72 user units (which roughly corresponds to 72 pt).

    On the next page, I explain that it’s possible to change the default value of the user unit, and I add an example on how to create a document with pages that have a different user unit.

    Now for your question: suppose you have an existing PDF, how do you find which user unit was used? Before we answer this, we need to take a look at ISO-32000-1.

    In section 7.7.3.3Page Objects, you’ll find the description of UserUnit in Table 30, “Entries in a page object”:

    (Optional; PDF 1.6) A positive number that shall give the size of
    default user space units, in multiples of 1⁄72 inch. The range of
    supported values shall be implementation-dependent. Default value: 1.0
    (user space unit is 1⁄72 inch).

    This key was introduced in PDF 1.6; you won’t find it in older files. It’s optional, so you won’t always find it in every page dictionary. In my book, I also explain that the maximum value of the UserUnit key is 75,000.

    Now how to retrieve this value with iTextSharp?

    You already have Rectangle dim = reader.GetPageSize(i); which returns the MediaBox. This may not be the size of the visual part of the page. If there’s a CropBox defined for the page, viewers will show a much smaller size than what you have in xy (but you probably knew that already).

    What you need now is the page dictionary, so that you can retrieve the value of the UserUnit key:

    PdfDictionary pageDict = reader.GetPageN(i);
    PdfNumber userUnit = pageDict.GetAsNumber(PdfName.USERUNIT);
    

    Most of the times userUnit will be null, but if it isn’t you can use userUnit.FloatValue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of pdf files that starts with a unique number. And
I have a bunch of PDF files that came from scanned documents. The files
I have a bunch of PDF files that I need to convert to TXT.
I have a bunch of PDF files that I receive once a week. Some
In a directory, I have a bunch of files like file1.tex, file1.pdf, file2.tex, file2.pdf
I have a bunch of files that get updated in the folder C:\Email. These
I have a bunch of PDF files and my Perl program needs to do
Have a bunch of pdf files I want to display on a web page
week DKK id=radio2 value=75 /> I have bunch of these div entry generated by
I have a bunch of files in a folder checked out from a repository.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.