Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7991657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:21:14+00:00 2026-06-04T13:21:14+00:00

static void Main(string[] args) { string saveFileAs = D:\\Hello.pdf; Program p = new Program();

  • 0
static void Main(string[] args)
    {
        string saveFileAs = "D:\\Hello.pdf";
        Program p = new Program();
        Document doc = p.CreateDocument();
        PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
        renderer.Document = doc;
        renderer.RenderDocument();
        renderer.PdfDocument.Save("D:\\Hello.pdf");
        Process.Start(saveFileAs);
    }

public Document CreateDocument()
    {
        // Create a new MigraDoc document
        this.document = new Document();
        this.document.Info.Title = "A sample invoice";
        this.document.Info.Subject = "Demonstrates how to create an invoice.";
        this.document.Info.Author = "Chandana Amarnath";

        DefineStyles();

        CreatePage();

        FillContent();

        return this.document;
   }

void CreatePage()
    {
        // Each MigraDoc document needs at least one section.
        Section section = this.document.AddSection();

        // Put a logo in the header
        Image image = section.Headers.Primary.AddImage("D:\\Cubes.jpg");
        image.Height = "2.5cm";
        image.LockAspectRatio = true;
        image.RelativeVertical = RelativeVertical.Line;
        image.RelativeHorizontal = RelativeHorizontal.Margin;
        image.Top = ShapePosition.Top;
        image.Left = ShapePosition.Right;
        image.WrapFormat.Style = WrapStyle.Through;

        // Create footer
        Paragraph paragraph = section.Footers.Primary.AddParagraph();
        // The following one prints at the footer;
        paragraph.AddText("Aldata Inc.");
        paragraph.Format.Font.Size = 9;
        paragraph.Format.Alignment = ParagraphAlignment.Center;

        // Create the text frame for the address
        this.addressFrame = section.AddTextFrame();
        this.addressFrame.Height = "3.0cm";
        this.addressFrame.Width = "7.0cm";
        this.addressFrame.Left = ShapePosition.Left;
        this.addressFrame.RelativeHorizontal = RelativeHorizontal.Margin;
        this.addressFrame.Top = "5.0cm";
        this.addressFrame.RelativeVertical = RelativeVertical.Page;

        // Put sender in address frame
        paragraph = this.addressFrame.AddParagraph("Aldata-Apollo Inc.");
        paragraph.Format.Font.Name = "Times New Roman";
        paragraph.Format.Font.Size = 7;
        paragraph.Format.SpaceAfter = 3;

        // Add the print date field
        paragraph = section.AddParagraph();
        paragraph.Format.SpaceBefore = "8cm";
        paragraph.Style = "Reference";
        paragraph.AddFormattedText("Section Comparator", TextFormat.Bold);
        paragraph.AddTab();
        paragraph.AddText("Date: ");
        paragraph.AddDateField("dd.MM.yyyy");

        // Create the item table
        this.table = section.AddTable();
        this.table.Style = "Table";
        this.table.Borders.Color = Color.Parse("Black");
        this.table.Borders.Width = 0.25;
        this.table.Borders.Left.Width = 0.5;
        this.table.Borders.Right.Width = 0.5;
        this.table.Rows.LeftIndent = 0;

        //************ Before you can add a row, you must define the columns **********
        Column column = this.table.AddColumn("4cm");
        column.Format.Alignment = ParagraphAlignment.Center;

        column = this.table.AddColumn("3cm");
        column.Format.Alignment = ParagraphAlignment.Right;

        // Create the header of the table
        Row row = table.AddRow();
        row.HeadingFormat = true;
        row.Format.Alignment = ParagraphAlignment.Center;
        row.Format.Font.Bold = true;
        row.Shading.Color = Color.Parse("White");

        row.Cells[0].AddParagraph("Added");
        row.Cells[0].Format.Font.Bold = true;
        row.Cells[0].Format.Alignment = ParagraphAlignment.Center;
        row.Cells[0].MergeRight = 3;

        row = table.AddRow();
        row.HeadingFormat = true;
        row.Format.Alignment = ParagraphAlignment.Center;
        row.Format.Font.Bold = true;
        row.Cells[0].AddParagraph("Deleted Items");
        row.Cells[0].Format.Font.Bold = true;
        row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
        row.Cells[0].MergeRight = 3;

        this.table.SetEdge(0, 0, 2, 3, Edge.Box, BorderStyle.Single, 0.75, Color.Empty);
    }

   void FillContent()
    {
        string xmlFileName = "C:\\Section.xml";
        XPathDocument xPathDocument = new XPathDocument(xmlFileName);
        XPathNavigator item = xPathDocument.CreateNavigator();

        XPathNodeIterator iter = item.Select("/Hello/*");
        while (iter.MoveNext())
        {
            string name = iter.Current.Name;
            item = iter.Current;
            Row row1 = this.table.AddRow();
            Row row2 = this.table.AddRow();

            row1.TopPadding = 1.5;
            row1.Cells[0].Shading.Color = Color.Parse("Gray");
            row1.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row1.Cells[0].MergeDown = 1;
            row1.Cells[1].Format.Alignment = ParagraphAlignment.Left;
            row1.Cells[1].MergeRight = 3;
            row1.Cells[0].AddParagraph(item.ToString());

            Console.WriteLine(name + "\t:" +item);
        }
        Console.ReadKey();
    }

I am writing code for generating my report in PDF using MigraDoc. I have downloaded the code from PDFSharp site. The following has 3 functions DefineStyles(), CreatePage(), FillContent(). I made changes in function CreatePage(), FillContent(); But when I am running the program I am getting error saying

Argument out of Exception:
Specified argument was out of the range of valid values.

In the CreatePage() I added 2 rows and 2 columns to a table. And in the FillContent() function I read my XML file. But I am unable to find where I am crossing my index range.

SOLVED

The problem is when I am setting the table.SetEdge(…). I am accessing the columns that I have not created.
Thank u all .. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:21:16+00:00Added an answer on June 4, 2026 at 1:21 pm

    At this step I was setting the rows that are not yet created.

    this.table.SetEdge(0, 0, 2, 3, Edge.Box, BorderStyle.Single, 0.75, Color.Empty);
    

    Instead of 3 which are the number of rows I should use 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Program { static void Main(string[] args) { List<Book> books = new List<Book> {
class Program { static void Main(string[] args) { var dictionary = new Dictionary<string, int>()
class Program { static void Main(string[] args) { var getfiles = new fileshare.Program(); string
class Program { static void Main(string[] args) { baseClass obj = new baseClass(); obj.intF
class Program { static void Main(string[] args) { Func<Object> someMethod = new Func<Object>(((Object)null).ToString); String
class Program { static void Main(string[] args) { A a = new A(); a.print();
static void Main(string[] args) { //read in the file StreamReader convert = new StreamReader(../../convert.txt);
public class Main { public static void main(String[] args){ Class2 class2Object = new Class2();
My main method: public static void main(String[] args) { Scanner input = new Scanner(System.in);
Consider following program: static void Main (string[] args) { int i; uint ui; i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.