tags:

views:

545

answers:

2

I want to write an application to validate a PDF file. The validation that is required is to verify that all the text and images in the PDF should start after 0.5" margin from left and 0.5" margin from the right. If any of the text is going outside this margin then application should be able to catch this.

I tried to search this into iText but couldn't get anything usefull that can solve my purpose.

Can somebody help me out in writing this code in .net csharp.

Thanks, Praveen

A: 

use SetMarginMirroring(true)

joe
Could you please elaborate your answer. I am not creating the PDF, I have to read the PDF file and then check if any text of image is going beyond the specified margin.
A: 

The PDF standard doesn't really have the concept of margins, since a PDF is supposed to be device independent. What it can have is five boxes designed to constrain output: media box, crop box, bleed box, art box, and trim box. Usually the other four boxes are the same size or smaller than the media box.

If a mediabox is present in your pdfs, you could retrieve it and check to see that it is 0.5" smaller on each side than the page. Try comparing the results of reader.getPageSize(pageNumber) and reader.getBoxSize(pageNumber,"media"). Very likely they will be the same.

What you can do is rewrite the pdfs to make sure there are 1/2 inch margins. The easiest way to this is shrink the page.

R Ubben
I tried to use reader.getBodSize and reader.getPageSize. Both functions returned the page size like 8.5x11. But how would I get the information that from where my text is starting inside the media box. I want to progamatically check if any of the page contains any line which is starting before 0.5" margin from the left.I don't want to rewrite the PDF.Also is there any possiblity that mediabox on each page might have different starting position? What I understood is that any text can be contained inside the one of 5 boxes and if somehow I get the box start position then it can work out.
That probably means that the box is not set. Almost all of the stuff that can be in a pdf is optional, so without knowing how a particular pdf was constructed, it would be very difficult to detect margins without rendering it. iText cannot do that.
R Ubben