hi,
thankx
for solving all my previous thread
right now my problem is that i have to get width and height of pdf file

Dani AI

Generated

Short version: for an existing PDF use a PdfReader and read the page box (MediaBox/CropBox) — that gives a Rectangle you can query for width/height. ’s pointer to standard PageSize constants is useful when creating new pages, but to get the actual size of an existing file you must read the page dictionary at runtime (MediaBox/CropBox and rotation). (javadoc.io)

Example (iText 5, Java):

PdfReader reader = new PdfReader("input.pdf");
Rectangle r = reader.getPageSizeWithRotation(1); // takes rotation into account
float widthPts  = r.getWidth();
float heightPts = r.getHeight();
reader.close();

Those values are in PDF user units (points): 72 points = 1 inch, convert as mm = pts * 25.4f / 72f. The Rectangle class exposes getWidth()/getHeight(), getLeft()/getRight()/getTop()/getBottom() if you need coordinates. (api.itextpdf.com)

Notes/troubleshooting: getPageSize(int) returns the MediaBox without rotation; use getPageSizeWithRotation() or check getPageRotation() for orientation. If the visible page differs from MediaBox check getCropBox() or getBoxSize(...) (crop/trim/art/bleed/media). These differences are the common cause of “wrong” dimensions. (javadoc.io)

Placing a table at the bottom: build and lock the table width, compute table.getTotalHeight(), then write it absolutely with writeSelectedRows(...) onto the writer’s direct content. Y coordinate math matters — to place inside the bottom margin use document.bottom() + table.getTotalHeight(); to place exactly in the margin use document.bottom() (or adjust as needed). (api.itextpdf.com)

Tying back: ’s advice to read the docs is right — the javadocs/Kb pages above show the exact methods to use.

Recommended Answers

All 4 Replies

well, you have to search on an iText Forum, or read docs comings with API

iText has PageSize class, nice sample can be found

well, you have to search on an iText Forum, or read docs comings with API

how can i palace table in pdf file at rigth position
i want to palce that table at bottom of page

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.