Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

c# - How to Get PDF page width and Height?

I have a pdf , and I want to get the width and Height for each page in pdf using iTextSharp?

given this is the pdf I want to work with

string source=@"D:pdfest.pdf";
PdfReader reader = new PdfReader(source); 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Do you want the MediaBox?

Rectangle mediabox = reader.GetPageSize(page); 

Do you want the rotation?

int rotation = reader.GetPageRotation(page);

Do you want the combination of both?

Rectangle pagesize = reader.GetPageSizeWithRotation(page);

Do you want the CropBox?

Rectangle cropbox = reader.GetCropBox(page);

Most of them return an object of type Rectangle that has methods such as getWidth() and getHeight() to get the width and the height of the page. Other useful methods are getLeft() and getRight() as well as getTop() and getBottom(). These four methods return the x and y coordinates that define the boundaries of your page.

Where did I find most of this documentation?

In chapter 6 of iText in Action.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...