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

Free Support Forum - aspose.com

Just starting out

Hi there,


I am trying to generate a PDF document using the Aspose PDF. Just wondering if somebody could help me with couple of issues that I am facing.

1. I am using generator to create the document, is this the preferred way, I have XML data coming from database ?

2. When I generate a PDF document, I am using sections to create various parts, is this the best option ?

I am seeing number of section appearing on new pages and not one after the other on the same page. I have included the sample code that I am using

private Pdf.Generator.Pdf CreateDocumentSection(Project project, Pdf.Generator.Pdf pdfDocument)
{
//Create the section in the Pdf object
var sec1 = pdfDocument.Sections.Add();
        <span style="color:#57a64a;">//Instantiate a table object</span>
        <span style="color:#569cd6;">var</span> tab1 <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Table</span>();

        <span style="color:#57a64a;">//Add the table in paragraphs collection of the desired section</span>
        sec1<span style="color:#b4b4b4;">.</span>Paragraphs<span style="color:#b4b4b4;">.</span>Add(tab1);

        <span style="color:#57a64a;">//Set with column widths of the table</span>
        tab1<span style="color:#b4b4b4;">.</span>ColumnWidths <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"100 370"</span>;
        tab1<span style="color:#b4b4b4;">.</span>Margin<span style="color:#b4b4b4;">.</span>Left <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">0</span>;
        

        <span style="color:#57a64a;">//Set default cell border using BorderInfo object</span>
        tab1<span style="color:#b4b4b4;">.</span>DefaultCellBorder <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">BorderInfo</span>((<span style="color:#569cd6;">int</span>)Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#b8d7a3;">BorderSide</span><span style="color:#b4b4b4;">.</span>All, <span style="color:#b5cea8;">0.1F</span>);

        <span style="color:#57a64a;">//Set table border using another customized BorderInfo object</span>
        tab1<span style="color:#b4b4b4;">.</span>Border <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">BorderInfo</span>((<span style="color:#569cd6;">int</span>)Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#b8d7a3;">BorderSide</span><span style="color:#b4b4b4;">.</span>All, <span style="color:#b5cea8;">1F</span>);
        <span style="color:#57a64a;">//Create MarginInfo object and set its left, bottom, right and top margins</span>
        Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">MarginInfo</span> margin <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">MarginInfo</span>
        {
            Top <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">2f</span>,
            Left <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">2f</span>,
            Right <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">2f</span>,
            Bottom <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">2f</span>
        };

        tab1<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>FontName <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"Helvetica"</span>;
        tab1<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>FontSize <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">10</span>;

        <span style="color:#57a64a;">//Set the default cell padding to the MarginInfo object</span>
        tab1<span style="color:#b4b4b4;">.</span>DefaultCellPadding <span style="color:#b4b4b4;">=</span> margin;

        Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Row</span> row0 <span style="color:#b4b4b4;">=</span> tab1<span style="color:#b4b4b4;">.</span>Rows<span style="color:#b4b4b4;">.</span>Add();
        row0<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(<span style="color:#d69d85;">"Project Details"</span>);
        row0<span style="color:#b4b4b4;">.</span>Cells[<span style="color:#b5cea8;">0</span>]<span style="color:#b4b4b4;">.</span>ColumnsSpan <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">2</span>;


        <span style="color:#57a64a;">//Create rows in the table and then cells in the rows</span>
        Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Row</span> row1 <span style="color:#b4b4b4;">=</span> tab1<span style="color:#b4b4b4;">.</span>Rows<span style="color:#b4b4b4;">.</span>Add();
        row1<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(<span style="color:#d69d85;">"Department"</span>);
        row1<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(project<span style="color:#b4b4b4;">.</span>Department);
        
        Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Row</span> row2 <span style="color:#b4b4b4;">=</span> tab1<span style="color:#b4b4b4;">.</span>Rows<span style="color:#b4b4b4;">.</span>Add();
        row2<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(<span style="color:#d69d85;">"Division"</span>);
        row2<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(project<span style="color:#b4b4b4;">.</span>Division);

        Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Row</span> row3 <span style="color:#b4b4b4;">=</span> tab1<span style="color:#b4b4b4;">.</span>Rows<span style="color:#b4b4b4;">.</span>Add();
        row3<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(<span style="color:#d69d85;">"Branch"</span>);
        row3<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(project<span style="color:#b4b4b4;">.</span>Branch);

        Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Row</span> row4 <span style="color:#b4b4b4;">=</span> tab1<span style="color:#b4b4b4;">.</span>Rows<span style="color:#b4b4b4;">.</span>Add();
        row4<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(<span style="color:#d69d85;">"Project Name"</span>);
        row4<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(project<span style="color:#b4b4b4;">.</span>Name);

        Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Row</span> row5 <span style="color:#b4b4b4;">=</span> tab1<span style="color:#b4b4b4;">.</span>Rows<span style="color:#b4b4b4;">.</span>Add();
        row5<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(<span style="color:#d69d85;">"Project Description"</span>);
        row5<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(project<span style="color:#b4b4b4;">.</span>Description);

        Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Row</span> row6 <span style="color:#b4b4b4;">=</span> tab1<span style="color:#b4b4b4;">.</span>Rows<span style="color:#b4b4b4;">.</span>Add();
        row6<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(<span style="color:#d69d85;">"Funding Contract Type"</span>);
        row6<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(project<span style="color:#b4b4b4;">.</span>FundingContractType);


        <span style="color:#57a64a;">//Create the section in the Pdf object</span>
        <span style="color:#569cd6;">var</span> sec2 <span style="color:#b4b4b4;">=</span> pdfDocument<span style="color:#b4b4b4;">.</span>Sections<span style="color:#b4b4b4;">.</span>Add();

        <span style="color:#57a64a;">//Instantiate a table object</span>
        <span style="color:#569cd6;">var</span> tab2 <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Table</span>
        {
            IsFirstRowRepeated <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">true</span>
        };


        <span style="color:#57a64a;">//Add the table in paragraphs collection of the desired section</span>
        sec2<span style="color:#b4b4b4;">.</span>Paragraphs<span style="color:#b4b4b4;">.</span>Add(tab2);

        <span style="color:#57a64a;">//Set with column widths of the table</span>
        tab2<span style="color:#b4b4b4;">.</span>ColumnWidths <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"90 250, 90"</span>;
        tab2<span style="color:#b4b4b4;">.</span>Margin<span style="color:#b4b4b4;">.</span>Left <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">3f</span>;
        tab2<span style="color:#b4b4b4;">.</span>Margin<span style="color:#b4b4b4;">.</span>Right <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">3f</span>;
        tab2<span style="color:#b4b4b4;">.</span>Margin<span style="color:#b4b4b4;">.</span>Top <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">3f</span>;
        tab2<span style="color:#b4b4b4;">.</span>Margin<span style="color:#b4b4b4;">.</span>Bottom <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">3f</span>;

        <span style="color:#57a64a;">//Set default cell border using BorderInfo object</span>
        tab2<span style="color:#b4b4b4;">.</span>DefaultCellBorder <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">BorderInfo</span>((<span style="color:#569cd6;">int</span>)Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#b8d7a3;">BorderSide</span><span style="color:#b4b4b4;">.</span>All, <span style="color:#b5cea8;">0.1F</span>);


        <span style="color:#57a64a;">//Set the default cell padding to the MarginInfo object</span>
        tab2<span style="color:#b4b4b4;">.</span>DefaultCellPadding <span style="color:#b4b4b4;">=</span> margin;

        Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">MarginInfo</span> margin1 <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">MarginInfo</span>
        {
            Top <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">1f</span>,
            Left <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">1f</span>,
            Right <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">1f</span>,
            Bottom <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">1f</span>
        };

        <span style="color:#57a64a;">// header row</span>

        Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Row</span> docRow <span style="color:#b4b4b4;">=</span> tab2<span style="color:#b4b4b4;">.</span>Rows<span style="color:#b4b4b4;">.</span>Add();
        docRow<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(<span style="color:#d69d85;">"Document Type"</span>);
        docRow<span style="color:#b4b4b4;">.</span>BackgroundColor <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Color</span>(<span style="color:#d69d85;">"#0494d0"</span>);
        docRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>Color <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Color</span>(<span style="color:#d69d85;">"white"</span>);
        docRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>FontName <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"Helvetica"</span>;
        docRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>FontSize <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">8</span>;
        docRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>Alignment <span style="color:#b4b4b4;">=</span> <span style="color:#b8d7a3;">AlignmentType</span><span style="color:#b4b4b4;">.</span>Center;


        docRow<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(<span style="color:#d69d85;">"Description"</span>);
        docRow<span style="color:#b4b4b4;">.</span>BackgroundColor <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Color</span>(<span style="color:#d69d85;">"#0494d0"</span>);
        docRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>Color <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Color</span>(<span style="color:#d69d85;">"white"</span>);
        docRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>FontName <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"Helvetica"</span>;
        docRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>FontSize <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">8</span>;
        docRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>Alignment <span style="color:#b4b4b4;">=</span> <span style="color:#b8d7a3;">AlignmentType</span><span style="color:#b4b4b4;">.</span>Center;

        docRow<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(<span style="color:#d69d85;">"Download"</span>);
        docRow<span style="color:#b4b4b4;">.</span>BackgroundColor <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Color</span>(<span style="color:#d69d85;">"#0494d0"</span>);
        docRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>Color <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Color</span>(<span style="color:#d69d85;">"white"</span>);
        docRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>FontName <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"Helvetica"</span>;
        docRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>FontSize <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">8</span>;
        docRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>Alignment <span style="color:#b4b4b4;">=</span> <span style="color:#b8d7a3;">AlignmentType</span><span style="color:#b4b4b4;">.</span>Center;
        docRow<span style="color:#b4b4b4;">.</span>DefaultRowCellPadding <span style="color:#b4b4b4;">=</span> margin1;

       <span style="color:#57a64a;">// docRow.Cells[0].Add("Document Type");</span>


       

        <span style="color:#569cd6;">foreach</span> (<span style="color:#569cd6;">var</span> document <span style="color:#569cd6;">in</span> project<span style="color:#b4b4b4;">.</span>AttachedDocuments)
        {
            Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Row</span> itemRow <span style="color:#b4b4b4;">=</span> tab2<span style="color:#b4b4b4;">.</span>Rows<span style="color:#b4b4b4;">.</span>Add();

          
            itemRow<span style="color:#b4b4b4;">.</span>DefaultRowCellPadding <span style="color:#b4b4b4;">=</span> margin1;
            itemRow<span style="color:#b4b4b4;">.</span>BackgroundColor <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Color</span>(<span style="color:#d69d85;">"white"</span>);
            itemRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>Color <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Color</span>(<span style="color:#d69d85;">"grey"</span>);
            itemRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>FontName <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"Arial"</span>;
            itemRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>FontSize <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">5</span>;
            itemRow<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>Alignment <span style="color:#b4b4b4;">=</span> <span style="color:#b8d7a3;">AlignmentType</span><span style="color:#b4b4b4;">.</span>Left;

            itemRow<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(document<span style="color:#b4b4b4;">.</span>DocumentType);
            itemRow<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(document<span style="color:#b4b4b4;">.</span>Description);
            itemRow<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(document<span style="color:#b4b4b4;">.</span>FileName);
            itemRow<span style="color:#b4b4b4;">.</span>DefaultRowCellPadding<span style="color:#b4b4b4;">.</span>Outer <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">2</span>;
        }
    

       

        <span style="color:#569cd6;">return</span> pdfDocument;
    }</pre></div><div><br></div><div>Also I only see header and footer appearing on the last page.. again why and if i am doing the right thing ?</div><div><br></div><div><pre style="font-family:Consolas;font-size:13;color:gainsboro;background:#1e1e1e;"><span style="color:#569cd6;">public</span>  Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Pdf</span> GenerateHeader(<span style="color:#569cd6;">string</span> headerText, Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Pdf</span> pdfDocument, <span style="color:#569cd6;">string</span> footerText <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">""</span> )
    {
        <span style="color:#57a64a;">//Instantiate PDF instance by calling empty constructor</span>
        <span style="color:#57a64a;">// var pdfDocument = new Pdf.Generator.Pdf();</span>
        <span style="color:#57a64a;">//Create a section in the pdf document</span>

        


        <span style="color:#569cd6;">var</span> sec1 <span style="color:#b4b4b4;">=</span> pdfDocument<span style="color:#b4b4b4;">.</span>Sections<span style="color:#b4b4b4;">.</span>Add();

        <span style="color:#57a64a;">// Create a Header Section of the PDF file</span>
        <span style="color:#569cd6;">var</span> header <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:#4ec9b0;">HeaderFooter</span>(sec1);
        <span style="color:#57a64a;">// Set the Odd Header for the PDF file</span>
        sec1<span style="color:#b4b4b4;">.</span>OddHeader <span style="color:#b4b4b4;">=</span> header;
        sec1<span style="color:#b4b4b4;">.</span>EvenHeader <span style="color:#b4b4b4;">=</span> header;

        <span style="color:#57a64a;">//Add Distance From Edge Property to 80 unit Points</span>
        header<span style="color:#b4b4b4;">.</span>DistanceFromEdge <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">10</span>;

        <span style="color:#57a64a;">// set the top margin for the header section</span>
        header<span style="color:#b4b4b4;">.</span>Margin<span style="color:#b4b4b4;">.</span>Top <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">0</span>;
        header<span style="color:#b4b4b4;">.</span>Margin<span style="color:#b4b4b4;">.</span>Left <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">0</span>;
        header<span style="color:#b4b4b4;">.</span>Margin<span style="color:#b4b4b4;">.</span>Right <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">0</span>;


        <span style="color:#57a64a;">//Instantiate a table object</span>
        <span style="color:#569cd6;">var</span> tab1 <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Table</span>();
        <span style="color:#57a64a;">//Add the table in paragraphs collection of the desired section</span>
        <span style="color:#57a64a;">//tab1.FixedWidth = 1000;</span>
        header<span style="color:#b4b4b4;">.</span>Paragraphs<span style="color:#b4b4b4;">.</span>Add(tab1);
        <span style="color:#57a64a;">//Set default cell border using BorderInfo object</span>
        tab1<span style="color:#b4b4b4;">.</span>DefaultCellBorder <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:#4ec9b0;">BorderInfo</span>((<span style="color:#569cd6;">int</span>)Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#b8d7a3;">BorderSide</span><span style="color:#b4b4b4;">.</span>All, <span style="color:#b5cea8;">0.1F</span>);
        <span style="color:#57a64a;">//Set with column widths of the table</span>
        tab1<span style="color:#b4b4b4;">.</span>Margin<span style="color:#b4b4b4;">.</span>Left <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">0</span>;
        tab1<span style="color:#b4b4b4;">.</span>ColumnWidths <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"480"</span>;




        <span style="color:#57a64a;">//Create rows in the table and then cells in the rows</span>
        <span style="color:#569cd6;">var</span> row2 <span style="color:#b4b4b4;">=</span> tab1<span style="color:#b4b4b4;">.</span>Rows<span style="color:#b4b4b4;">.</span>Add();
        <span style="color:#57a64a;">// set the background color for Row2</span>
        row2<span style="color:#b4b4b4;">.</span>BackgroundColor <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Color</span>(<span style="color:#d69d85;">"#FFFFCC"</span>);




        row2<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(headerText);
        row2<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>FontName <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"Helvetica"</span>;
        <span style="color:#57a64a;">// set the vertical alignment of the text as center aligned</span>
        row2<span style="color:#b4b4b4;">.</span>Cells[<span style="color:#b5cea8;">0</span>]<span style="color:#b4b4b4;">.</span>VerticalAlignment <span style="color:#b4b4b4;">=</span> <span style="color:#b8d7a3;">VerticalAlignmentType</span><span style="color:#b4b4b4;">.</span>Center;
        row2<span style="color:#b4b4b4;">.</span>Cells[<span style="color:#b5cea8;">0</span>]<span style="color:#b4b4b4;">.</span>Alignment <span style="color:#b4b4b4;">=</span> <span style="color:#b8d7a3;">AlignmentType</span><span style="color:#b4b4b4;">.</span>Left;



        <span style="color:#57a64a;">//=====================================================//</span>
        <span style="color:#57a64a;">//	Footer to show Page Number</span>
        <span style="color:#57a64a;">//=====================================================//</span>

        <span style="color:#57a64a;">// Create a Footer Section of the document</span>
        Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">HeaderFooter</span> footer <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">HeaderFooter</span>(sec1);
        <span style="color:#57a64a;">// set the Odd footer of the PDF file</span>
        sec1<span style="color:#b4b4b4;">.</span>OddFooter <span style="color:#b4b4b4;">=</span> footer;
        <span style="color:#57a64a;">// set the Even footer of the PDF file</span>
        sec1<span style="color:#b4b4b4;">.</span>EvenFooter <span style="color:#b4b4b4;">=</span> footer;

        <span style="color:#569cd6;">var</span> tab2 <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Table</span>();
        <span style="color:#57a64a;">//Add the table in paragraphs collection of the desired section</span>
        <span style="color:#57a64a;">//tab1.FixedWidth = 1000;</span>
        footer<span style="color:#b4b4b4;">.</span>Paragraphs<span style="color:#b4b4b4;">.</span>Add(tab2);
        
        <span style="color:#57a64a;">//Set default cell border using BorderInfo object</span>
        tab2<span style="color:#b4b4b4;">.</span>DefaultCellBorder <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:#4ec9b0;">BorderInfo</span>((<span style="color:#569cd6;">int</span>)Aspose<span style="color:#b4b4b4;">.</span>Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#b8d7a3;">BorderSide</span><span style="color:#b4b4b4;">.</span>All, <span style="color:#b5cea8;">0.1F</span>);
        <span style="color:#57a64a;">//Set with column widths of the table</span>
        tab2<span style="color:#b4b4b4;">.</span>Margin<span style="color:#b4b4b4;">.</span>Left <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">0</span>;
        tab2<span style="color:#b4b4b4;">.</span>ColumnWidths <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"480"</span>;


        <span style="color:#57a64a;">// if footer text was passed lets put it somewhere</span>
        <span style="color:#569cd6;">if</span> (<span style="color:#b4b4b4;">!</span><span style="color:#569cd6;">string</span><span style="color:#b4b4b4;">.</span>IsNullOrWhiteSpace(footerText))
        {
            <span style="color:#57a64a;">//Create rows in the table and then cells in the rows</span>
            <span style="color:#569cd6;">var</span> footerRow1 <span style="color:#b4b4b4;">=</span> tab2<span style="color:#b4b4b4;">.</span>Rows<span style="color:#b4b4b4;">.</span>Add();

            <span style="color:#57a64a;">// set the background color for Row2</span>
            footerRow1<span style="color:#b4b4b4;">.</span>BackgroundColor <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> Pdf<span style="color:#b4b4b4;">.</span>Generator<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Color</span>(<span style="color:#d69d85;">"#FFFFCC"</span>);
            footerRow1<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(footerText);
            footerRow1<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>FontName <span style="color:#b4b4b4;">=</span> <span style="color:#d69d85;">"Helvetica"</span>;
            footerRow1<span style="color:#b4b4b4;">.</span>DefaultCellTextInfo<span style="color:#b4b4b4;">.</span>FontSize <span style="color:#b4b4b4;">=</span> <span style="color:#b5cea8;">5</span>;
           
                <span style="color:#57a64a;">// set the vertical alignment of the text as center aligned</span>
            footerRow1<span style="color:#b4b4b4;">.</span>Cells[<span style="color:#b5cea8;">0</span>]<span style="color:#b4b4b4;">.</span>VerticalAlignment <span style="color:#b4b4b4;">=</span> <span style="color:#b8d7a3;">VerticalAlignmentType</span><span style="color:#b4b4b4;">.</span>Center;
            footerRow1<span style="color:#b4b4b4;">.</span>Cells[<span style="color:#b5cea8;">0</span>]<span style="color:#b4b4b4;">.</span>Alignment <span style="color:#b4b4b4;">=</span> <span style="color:#b8d7a3;">AlignmentType</span><span style="color:#b4b4b4;">.</span>Left;

        }

        <span style="color:#569cd6;">var</span> pageNumberRow <span style="color:#b4b4b4;">=</span> tab2<span style="color:#b4b4b4;">.</span>Rows<span style="color:#b4b4b4;">.</span>Add();

        pageNumberRow<span style="color:#b4b4b4;">.</span>Cells<span style="color:#b4b4b4;">.</span>Add(<span style="color:#d69d85;">"Page: ($p of $P ) "</span>);
        pageNumberRow<span style="color:#b4b4b4;">.</span>Cells[<span style="color:#b5cea8;">0</span>]<span style="color:#b4b4b4;">.</span>VerticalAlignment <span style="color:#b4b4b4;">=</span> <span style="color:#b8d7a3;">VerticalAlignmentType</span><span style="color:#b4b4b4;">.</span>Center;
        pageNumberRow<span style="color:#b4b4b4;">.</span>Cells[<span style="color:#b5cea8;">0</span>]<span style="color:#b4b4b4;">.</span>Alignment <span style="color:#b4b4b4;">=</span> <span style="color:#b8d7a3;">AlignmentType</span><span style="color:#b4b4b4;">.</span>Right;

        <span style="color:#569cd6;">return</span> pdfDocument;
    }</pre></div><div><br></div><div>Any help will be greatly appreciated.</div><div><br></div><div>Thanks</div><div><br></div><div>Juan</div><div><br></div><div><br></div>

Ok so even after 17 view no one can actually help me ?

Hi Sunny,


Thanks for your inquiry. Please note Aspose.Pdf.Document(DOM) approach is preferable to create new PDF document. Old generator(Aspose.Pdf.Generator) is will be obsolete in near future and we are making enhancements in new generator(Aspose.Pdf.Document). New approach is more improved and efficient. Please find a sample code snippet to create tables and headers in a PDF document using new DOM approach. Please also check following documentation link for details.



Please feel free to contact us for any further assistance.

Best Regards,