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

Free Support Forum - aspose.com

Add PDF Page Stamp to Add Existing PDF Document in new PDF - Add Text in Existing PDF

Hi all,

is there as possibility to add an existing pdf as Background to a generated pdf with sections and paragraphs?

Thanks, Tobi

Hi Tobi,


Thanks for contacting support.

You can add an existing PDF file as background/stamp to an existing PDF document. Please visit the following link for further information on Adding PDF Page Stamp in the PDF File

In case of any further query, please feel free to contact.

OK sorry I didn't get it.

I generate my pdf with aspose.pdf.generator like this:

Dim pdf1 As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf
Dim Sec1 As Section = pdf1.Sections.Add()

then I work with Sec1.TextInfo, and tables...

How can I add a Stamp with AddStamp to that Kind of generated pdf?

An other way could probably be to open an existing pdf file and place a FloatingBox with all the paragraphs, text and tables on it.

Thanks and regards,
Tobi

Hi,

can you please look on my problem again?

Regards, Tobi

Hi Tobi,


Thanks for your sharing the details.

The PdfFileStamp object is used when manipulating existing PDF files. However as per your requirement, you are creating PDF document from scratch using Aspose.Pdf.Generator so as per current scenario, I would suggest you to please try using Aspose.Pdf namespace and try using Document class. This class supports the feature to create as well as manipulate existing PDF files. Please take a look over following code snippet where I have created PDF file from scratch and have added existing PDF file as its background/watermark.

You may also check the following links for information on


[C#]

//open document<o:p></o:p>

Document pdfDocument = new Document();

//get particular page

Page pdfPage = pdfDocument.Pages.Add();

//create text fragment

TextFragment textFragment = new TextFragment("main text");

textFragment.Position = new Position(100, 600);

//set text properties

textFragment.TextState.FontSize = 12;

// create TextBuilder object

TextBuilder textBuilder = new TextBuilder(pdfPage);

// append the text fragment to the PDF page

textBuilder.AppendText(textFragment);

//load existing PDF file which will be used as stamp object

Document Stamp_pdfDocument = new Document("c:/pdftest/A0000238.pdf");

//create page stamp

PdfPageStamp pageStamp = new PdfPageStamp(Stamp_pdfDocument.Pages[1]);

pageStamp.Background = true;

pageStamp.XIndent = 100;

pageStamp.YIndent = 100;

//add stamp to particular page

pdfDocument.Pages[1].AddStamp(pageStamp);

//save document

pdfDocument.Save(“c:/pdftest/PDFwithStampObject.pdf”);

Hi Nayyer,


is there any performance difference when I use the following snipped to add a background to my generated pdf and to the code snipped you suggested?

#region one possible way to add background…
Aspose.pdf.Generator.Pdf pdf = new Aspose.pdf.Generator.Pdf();
// Create FloatingBox with x as width and y as height
Aspose.Pdf.Generator.FloatingBox background = new Aspose.Pdf.Generator.FloatingBox(); // width, height
Aspose.Pdf.Generator.Image back = new Aspose.Pdf.Generator.Image();

// read the source image file
System.IO.MemoryStream streamBack = new System.IO.MemoryStream(backBuffer, false);

// specify image source as stream
back.ImageInfo.ImageStream = streamBack;
// add image to paragraphs collection of FloatingBox
background.Paragraphs.Add(back);

// specify FloatingBox as watermark object
pdf.Watermarks.Add(background);

// specify that the watermark will appear behind PDF file contents (text)
pdf.IsWatermarkOnTop = false;

// save the final output PDF
pdf.Save(“c:\temp\workoutput\output_v2.pdf”);
#endregion
Note: The Image File type here can be i.e. PNG.

And on the other hand the way to add a background you have suggested.

Suppose you have a PDF with 10000 Pages, you have to modify every page and this will not be well run time optimized i think.

Is there any better optimized way to work with the PdfStamper or to add a background(= of the file type pdf) to a pdf File?

Best Regards
Sebastian

Hi Sebastian,


Thanks for using our products.

The approach which I have shared earlier is for adding watermark/stamp to pages of existing PDF files whereas the approach which you shared is for adding stamp/watermark while creating PDF file from scratch using Aspose.Pdf.Generator namespace. Instead of using PdfFileStamp class of Aspose.Pdf.Facades namespace, I would recommend you to please try using TextStamp or ImageStamp classes of Aspose.Pdf namespace.

In case you encounter any performance related issues, please share the code snippet and the resource files so that we can test the scenario at our end.