Loosing appended pages

Hi ,

I am using the aspose append method in aspose.pdf.kit.

Append process is happening properly,but everytime it appends,it removes the previous appended page content.I am appending these pages in a loop.

Here is what i am doing.

ex:

1st template pdf has only one page

2nd template pdf also has only page

when i am appending the file in a loop page2 should get appended to the page1 with the new data as it loops.

But what I am getting is page2 gets appended at every loop by deleting the content in the page which got appended previously.Finally although all the pages are added ,i can find data only in the last page which belongs to the last loop.

Regards,

Jairam

Hi,

Thank you for considering Aspose.

Sorry I didn’t understand your problem. if in 1st and 2nd Template there are only one page, then why you are appending it in a loop. Please elaborate your problem with source code, may be then we can understand.

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team
http://www.aspose.com/Wiki/default.aspx/Aspose.Corporate/ContactChangsha.html

Hi,

Thanks for the quick response.

My requirement has lot of records to deal with.So i created a template which can hold 30 records.Now i want to reuse the template if the records are more than 30.Here comes my for loop. for each 30 records from database i run once a for loop ,that means if there are 60 records my loop runs for 2 times.In the loop what i am doing is,i am filling all these fields and then saveing them and then appending it to a template1 pdf.this works fine if the loop runs only once.Now if it runs more than once i am refilling the same template with different data and appending.Now here comes the problem.

when the loop is running for the second time it fills the data in the template2 and appends, but the data which was already appended when the loop ran for the first time doesnt get displayed.although the sheets are getting appended i can find data only in the last sheet of the final merged pdf file.

If u still have problem understanding i can post u the code.

Thanks & Regards,

Jairam

Hi,

I think the problem is that you are not closing the streams and hence the data is lost. After every loop please close the streams. Please check it, if you still have problems then send me the code and let us investigate this issue.

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team
http://www.aspose.com/Wiki/default.aspx/Aspose.Corporate/ContactChangsha.html

Hi ,

Below is the code .

Here LOC.i where i can be any number between 15 to 40 is the control name . temp2.pdf is my template2

new2 is my template1

and news.pdf is my output file .

i am really not sure why this is happening .is this because of the same control names repeated for all the sheets

please let me know asap where i made a mistake,

below is my code.

for (int i = 0; i < intPages; i++)

{

Form formpdf = new Form(@"D:\docs\secondpage.pdf", @"D:\docs\temp2.pdf");

if (i != intPages - 1)

{

for (int j = 15; j < 40; j++)

{

count++;

formpdf.FillField("LOC" + "." + j, "jairam" + count);

}

}

else

{

for (int j = 15; j < 15 + remainder; j++)

{

count++;

formpdf.FillField("LOC" + "." + j, "jairam" + count);

}

}

formpdf.Save();

mergepdf();

}

public void mergepdf()

{

PdfFileEditor editor = new PdfFileEditor();

string inFile1 = @"D:\docs\new2.pdf";

string inFile2 = @"D:\docs\temp2.pdf";

//Creating output stream object that will store the resulting PDF file after appending

string outFile = @"D:\docs\news.pdf";

FileStream outputStream = new FileStream(outFile, FileMode.Create);

//Creating stream objects holding the PDF files in Open Mode

FileStream inStream1 = new FileStream(inFile1, FileMode.Open);

FileStream inStream2 = new FileStream(inFile2, FileMode.Open);

//Calling Append method and providing five arguments

editor.Append(inStream1, inStream2, 1, 1, outputStream);

//Closing output stream

outputStream.Close();

inStream1.Close();

inStream2.Close();

File.Delete(@"D:\docs\new2.pdf");

File.Copy(@"D:\docs\news.pdf", @"D:\docs\new2.pdf");

File.Delete(@"D:\docs\news.pdf");

inStream1.Dispose();

inStream2.Dispose();

outputStream.Dispose();

//open the source file and append the page to the file

}

Hi,

Code look fine, but it is difficult for me to debug with out records and input Pdf files. Can you send me a runnable project and let us investigate this issue. For a workaround, why don’t you use “PdfFileEditor.Insert” and insert the pages in 2nd Template after filling it with records and add those pages in the end in 1st Template.

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team
http://www.aspose.com/Wiki/default.aspx/Aspose.Corporate/ContactChangsha.html