Welcome Guest Search | Active Topics | Sign In | Register

Index was outside the bounds of the array Options
Vijay Pote
Posted: Friday, March 15, 2013 2:26:18 AM
Rank: Newbie
Groups: Member

Joined: 3/15/2013
Posts: 4
PdfDocument[] docs = new PdfDocument[] { };
docs[0] = new PdfDocument("D:\\For Delete\\1.pdf");
docs[1] = new PdfDocument("D:\\For Delete\\2.pdf");

//Merge them into a single PDF file
mergedDoc = PdfDocument.Merge(docs);

//You are also free to modify the merged document
PdfPage page = mergedDoc.Pages.Add();

//Save the result
mergedDoc.Save("D:\\For Delete\\Merge.pdf");

Please help

Thanks
VJ
Mark Rae
Posted: Friday, March 15, 2013 8:17:46 AM
Rank: Advanced Member
Groups: Member

Joined: 11/13/2008
Posts: 43
Vijay Pote wrote:
Please help

What's the problem...?
eo_support
Posted: Friday, March 15, 2013 11:09:59 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi Vijay,

You need to troubleshoot such simple problem yourself. We do not troubleshoot your code.

Thanks!
Vijay Pote
Posted: Friday, March 15, 2013 12:06:30 PM
Rank: Newbie
Groups: Member

Joined: 3/15/2013
Posts: 4
That is fine, i did my troubleshooting. but this is something i am trying to merge multiple pdf documents into one single pdf dynamically.

if i use :

PdfDocument docs1 = new PdfDocument("D:\\For Delete\\1.pdf");
PdfDocument docs2 = new PdfDocument("D:\\For Delete\\2.pdf");

it works fine, but i am trying to do it dynamically it fails.

PdfDocument[] docs = new PdfDocument[] { };
while(_reader.read())
{
docs[i] = new PdfDocument("D:\\For Delete\\1.pdf");
}

The code is compiles fine with no error but when i run it i get Index was outside the bounds of the array

I am asking everyone here ... what is the alternative to do this. Has any one tried creating pdf merge dynamically ?

let me know as i am fighting on this for quite some time now.

Thanks
VJ
Mark Rae
Posted: Friday, March 15, 2013 12:14:45 PM
Rank: Advanced Member
Groups: Member

Joined: 11/13/2008
Posts: 43
Vijay Pote wrote:
PdfDocument[] docs = new PdfDocument[] { };VJ

That's an array, not a generic collection.

Look at it again - how big is it, i.e. how many "spaces" does the PdfDocument[] have?

Have a read through this: http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx
Vijay Pote
Posted: Friday, March 15, 2013 12:34:08 PM
Rank: Newbie
Groups: Member

Joined: 3/15/2013
Posts: 4
Hi Mark,

Thanks for your reply, will go over it tonight and will let you know.

Thanks
Mark Rae
Posted: Friday, March 15, 2013 12:41:03 PM
Rank: Advanced Member
Groups: Member

Joined: 11/13/2008
Posts: 43
OK, in the interests of helping you out, this has NOTHING to do with EssentialObjects - it's purely a C# problem.

Look at this:

Code: C#
int[] IntegerArray = new int[] { };
IntegerArray[0] = 0;
IntegerArray[1] = 1;


It will compile fine, but will break on the second line, just like your code does. Why, because IntegerArray[0] doesn't exist, so you can't store a value there. All the first line has done is to create an array with no size.

However, this will also compile but will not break on the second line:

Code: C#
int[] IntegerArray = new int[2];
IntegerArray[0] = 0;
IntegerArray[1] = 1;


Generics were introduced in .NET 2 to get round this "problem" - I suggest you read up on them...
Vijay Pote
Posted: Friday, March 15, 2013 12:48:25 PM
Rank: Newbie
Groups: Member

Joined: 3/15/2013
Posts: 4
Cool, Thanks Mark!

I will go over it and will resolve my issue bases on your suggestion.

Appreciate for your help!

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.