I have existing Pdf files that have 1/4 inch left margins. I need to increase left margin to 1/2 inch. I tried to move the text with the following code to crop the content of each page. The content is moved to the left which is opposite of my intentions. Any suggestion on how to accomplish this would be appreciated.
public void ResetMargin(string inputFilePath, string outputFilePath, int count)
{
using (PdfReader pdf = new PdfReader(inputFilePath))
{
PdfDictionary pageDict;
PdfArray cropBox;
PdfArray mediaBox;
float letterWidth = PageSize.LETTER.Width;
float letterHeight = PageSize.LETTER.Height;
int pageCount = pdf.NumberOfPages;
for (int i = 1; i <= pageCount; i++)
{
pageDict = pdf.GetPageN(i);
cropBox = pageDict.GetAsArray(PdfName.CROPBOX);
mediaBox = pageDict.GetAsArray(PdfName.MEDIABOX);
cropBox[0] = new PdfNumber(36);
cropBox[1] = new PdfNumber(0);
cropBox[2] = new PdfNumber(letterWidth);
cropBox[3] = new PdfNumber(letterHeight);
mediaBox[0] = new PdfNumber(36);
mediaBox[1] = new PdfNumber(0);
mediaBox[2] = new PdfNumber(letterWidth);
mediaBox[3] = new PdfNumber(letterHeight);
pageDict.Put(PdfName.CROPBOX, cropBox);
pageDict.Put(PdfName.MEDIABOX, mediaBox);
}
PdfStamper stamper = new PdfStamper(pdf, new FileStream(outputFilePath, FileMode.Create));
stamper.Close();
}
}