We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Big PDF to Check if DIN A4 Format

Hi, i have a pdf with > 1000 Pages.
I will check if all Pages have the margin of
left - 2cm
right -. 1cm
botton - 2cm
upper - 2cm
Actualy i scan each page of the pdf document, but it takes a long time (5-8 min)
What is the best way to check each page with the given margin?
Regards
Horst

@hstumpf

I request you to share the code which you are using to check all pages so that we can review it.

Hi,

In Word, each page automatically has a one-inch margin. You can customize or choose predefined margin settings, set margins for facing pages, allow extra margin space to allow for document binding, and change how margins are measured.

@sub_systems

I request you to explain your requirements with expected output file and snapshots.

Hi here the code:

///


/// check page margins from app config
///

/// pdf document
/// The error list to fill if check fails
private void CheckPageMargins(Document doc, List errorList)
{
foreach (var page in doc.Pages)
{
	var marginLeft = GetRectangleText(page, 0, 0, 28.3, page.PageInfo.Height);
	var marginBottom = GetRectangleText(page, 0, 0, page.PageInfo.Width, 28.3);
	var marginRight = GetRectangleText(page, (page.PageInfo.Width - 14), 0, page.PageInfo.Width, page.PageInfo.Height);
	var marginTop = GetRectangleText(page, 0, (page.PageInfo.Height - 28.3), page.PageInfo.Width, page.PageInfo.Height);

	if (!marginLeft.Equals(string.Empty) ||
		!marginBottom.Equals(string.Empty) ||
		!marginRight.Equals(string.Empty) ||
		!marginTop.Equals(string.Empty))
	{
		errorList.Add("margin not in range");
		break;
	}
}

}

private string GetRectangleText(Page page, double llx, double lly, double urx, double ury)
{
var absorber = new TextAbsorber
{
TextSearchOptions =
{
LimitToPageBounds = true,
Rectangle = new Rectangle(llx, lly, urx, ury)
}
};
// Accept the absorber for first page
page.Accept(absorber);
// Get the extracted text
return absorber.Text;
}

Regards
Horst

@hstumpf

Thanks for sharing your code. However, I request you to explain current and expected output so that we can investigate accordingly.

Hi,

The aim is that only PDFs with the specified settings (margins) can be uploaded to our web service.
There should be no text outside the margins.

Regards
Horst

@hstumpf

You can simply check margins of the document or for every page.

var pdfDocument = new Document("test.pdf");
if (pdfDocument.PageInfo.Margin.Bottom == 72 && pdfDocument.PageInfo.Margin.Top == 72)
{
    Console.WriteLine("Margin Checked");
} 

I request you to share a sample file if you need to improve the code.

Hi,
I create the pdf in word without margin - see attachment
With my code, the text is recognized outside the margins.
With the pageInfo - the text outside is not recognized.

Regards
Horst
BriefOhneRand.pdf (63.2 KB)

@hstumpf

The BriefOhneRand.pdf file does not satisfy your requirements in the first place so this should not be able to be uploaded on your webservice because of zero left margin. If your requirements about margins are different then please rephrase the details for our investigations.