How to open a created pdf file using pdf in append mode


#1

hi,

i had created a pdf file using the aspose.And i want to append some text into the same file.

Can you help me out in adding the text to the existing file.

i am sending you the code.

Code For Creating a pdf file and writing image into the file:

Part1:

Pdf pdf1 = new Pdf();

Section sec1 = pdf1.Sections.Add();

Aspose.Pdf.Image image1 = new Aspose.Pdf.Image(sec1);

sec1.Paragraphs.Add(image1);

image1.ImageInfo.File = "c:/dwclogo1.jpg";

image1.ImageInfo.ImageFileType = ImageFileType.Jpeg;

image1.ImageInfo.Title = "JPEG image";

pdf1.Save("c:/test.pdf");

Part2:

System.IO.FileStream fs1 = new System.IO.FileStream("C:/test1.pdf",System.IO.FileMode.Append,System.IO.FileAccess.Write);

Pdf pdf = new Pdf();

string s = "
This
is a test for HTML </ support in Text paragraph. ";

string s1 = "This is a test for HTML with colored text.";

string s2 = "

This is a test forHTML in text paragraph.


";

Text t1 = new Text(s);

t1.IsHtmlTagSupported = true;

Text t2 = new Text(s1);

t2.IsHtmlTagSupported = true;

Text t3 = new Text(s2);

t3.IsHtmlTagSupported = true;

//Add the text paragraphs containing HTML text to the section

sec1.Paragraphs.Add(t1);

sec1.Paragraphs.Add(t2);

sec1.Paragraphs.Add(t3);

// sec1.Paragraphs.Add(t4);

//Save the pdf document

pdf.Close();

//pdf.Save("c:/TestHtml.pdf");

If i am running the above part1 code individually i am getting the pdf file saved

in the 'C'drive.But i am not able to append the below text to the pdf file

"test.pdf".If i am trying to run the total code then i am getting the test.pdf as

blank.

Please help me out in appending the content to the existing file.Please solve this

problem for me


#2

Thanks for considering Aspose.

If you have to append additional texts to an existed pdf file, you can use Aspose.Pdf.Kit to fulfill it.

http://www.aspose.com/wiki/default.aspx/Aspose.Pdf.Kit/AppendPagestoPDFDocument.html

Aspose.Pdf.Kit is a component which is desigend for operating on existed pdf documents.


#3

I just combined code Part I and Part II into a code segment and get the result I guess you want to have. The precondition is not appending texts on an existed pdf file but generating all contents on one pdf document on the fly.

----------------------------------------------------------------------

//Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();


//Create a section in the Pdf object
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();


//Create an image object in the section
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image(sec1);


//Add image object into the Paragraphs collection of the section
sec1.Paragraphs.Add(image1);


//Set the path of image file
image1.ImageInfo.File = "76_57749.jpg";


//Set the type of image using ImageFileType enumeration
image1.ImageInfo.ImageFileType = ImageFileType.Jpeg;


//Set image title
image1.ImageInfo.Title = "JPEG image";

string s = "
This
is a test for HTML </ support in Text paragraph. ";

string s1 = "This is a test for HTML with colored text.";

string s2 = "

This is a test forHTML in text paragraph.


";

Text t1 = new Text(s);

t1.IsHtmlTagSupported = true;

Text t2 = new Text(s1);

t2.IsHtmlTagSupported = true;

Text t3 = new Text(s2);

t3.IsHtmlTagSupported = true;

//Add the text paragraphs containing HTML text to the section

sec1.Paragraphs.Add(t1);

sec1.Paragraphs.Add(t2);

sec1.Paragraphs.Add(t3);

//Save the pdf document

pdf1.Save("76_57750.pdf");

----------------------------------------------------------------------------