Setting margin of pdf-file

Hi,
I tried my first steps with Aspose PDF and got some troubles.
I added an table to the document. This works, but there is a wide margin on top and left, which I tried to remove - without success.
I tried to set pdf.PageSetup… but nothing changed.

I use version 3.7.0.0
Here is my code, see the attachment for pdf…


public override void Export(HttpResponse response)
{
Pdf exportPdf = new Pdf();
Section tableContainer = new Section();
Table tableWithGridViewItems = new Table();
tableContainer.Paragraphs.Add(tableWithGridViewItems);

tableWithGridViewItems.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.1F);
this.WriteTableHeader(tableWithGridViewItems);
this.WriteTableContent(tableWithGridViewItems);
exportPdf.Sections.Add(tableContainer);
exportPdf.Save(“mypdf.pdf”, SaveType.OpenInAcrobat, response);
}

private void WriteTableHeader(Table tableToWrite)
{
Row headerRow = tableToWrite.Rows.Add();
//Durchlaufe alle HeaderItems und schreibe sie ins Excel
foreach (var nextHeaderText in ExportData.HeaderItems)
{
Cell headerCell = headerRow.Cells.Add(nextHeaderText.HeaderText);
this.SetFont(headerCell, true);
this.SetPadding(headerCell);
}
}
private void WriteTableContent(Table tableToWrite)
{
//Durchlaufe jedes VO, dass in den Exportdaten enthalten ist
foreach (var valueObject in this.ExportData.ValueObjects)
{
Row contentRow = tableToWrite.Rows.Add();
//Durchlaufe alle Headerspalten des zu erstellenden PDF,
//finde die dazugehörigen Items und schreibe sie ins PDF
foreach (var headerItem in ExportData.HeaderItems)
{
var valueToWriteInCell = base.GetPropertyValueOfAnValueObject(valueObject, headerItem.DataItem);
Cell contentCell = contentRow.Cells.Add(valueToWriteInCell.ToString());
this.SetFont(contentCell, false);
this.SetPadding(contentCell);
}
}
}
private void SetFont(Cell cellToStyle, Boolean isBold)
{
TextInfo style = new TextInfo();
style.FontName = “Verdana”;
style.IsTrueTypeFontBold = isBold;
style.FontSize = 8;
cellToStyle.DefaultCellTextInfo = style;
}
private void SetPadding(Cell cellToStyle)
{
MarginInfo padding = new MarginInfo();
padding.Bottom = 3;
padding.Left = 3;
padding.Top = 3;
padding.Right = 3;
cellToStyle.Padding = padding;
}



Do I miss anything?
Thanks, tokh.

Hi,

Thanks for considering Aspose.

There are two mechanisms to accomplish your requirement. One is to set the Margin information for the section containing Table object and second is to specify the Margin information for the table object.

[C#]

MarginInfo marginInfo = new MarginInfo();
marginInfo.Top = 10;
marginInfo.Left = 10;
tableContainer.PageInfo.Margin = marginInfo;

or [C#]

MarginInfo minfo = new MarginInfo();
tableWithGridViewItems.Margin = minfo;
minfo.Left = -40f;
minfo.Top = -40f;

The resultant PDF that I've generated using Aspose.Pdf for .NET 4.1.1 is in attachment. Please take a look.

I would reccomend you to visit the following links