Debenu Quick PDF Library lets you programmatically stamp one PDF onto another PDF. This can be done using the CapturePage and DrawCapturedPage functions to overlay a PDF file onto another.

Here is a small JScript code snippet that uses CapturePage, DrawCapturedPage and a few other Debenu Quick PDF Library functions to complete this task.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Overlay one page from a document onto a different page in a different document */
 
// Load fileA
DPL.LoadFromFile("firstPDF.pdf", "");
fileA = DPL.SelectedDocument();
 
// Load fileB
DPL.LoadFromFile("secondPDF.pdf", "");
fileB = DPL.SelectedDocument();
 
// Select fileA
DPL.SelectDocument(fileA);
 
// Merge fileA with fileB
DPL.MergeDocument(fileB);
 
// Set orgin co-ordinates to top left of page
DPL.SetOrigin(1);
 
// Select page 1 of fileA
DPL.SelectPage(1);
 
// Get page height and width
xPageHeight = DPL.PageHeight();
xPageWidth = DPL.PageWidth();
 
// Capture page 2
CapturedPageID = DPL.CapturePage(2);
 
// Create OCG for the background
OCG1 = DPL.NewOptionalContentGroup("Background");
 
// Create a new content stream that we can draw onto
contentstreamPos = DPL.NewContentStream();
DPL.SelectContentStream(contentstream);
 
// Draw the captured page onto the current page
ret = DPL.DrawCapturedPage(CapturedPageID, 0, 0, xPageWidth, xPageHeight);
 
// Associate the new content stream with the new OCG
DPL.SetContentStreamOptional(OCG1);
 
// Make the OCG visible
DPL.SetOptionalContentGroupVisible(OCG1, 1);
 
// Save the file
DPL.SaveToFile("overlay.pdf");

// Load fileA
DPL.LoadFromFile("firstPDF.pdf", "");
fileA = DPL.SelectedDocument();

// Load fileB
DPL.LoadFromFile("secondPDF.pdf", "");
fileB = DPL.SelectedDocument();

// Select fileA
DPL.SelectDocument(fileA);

// Merge fileA with fileB
DPL.MergeDocument(fileB);

// Set orgin co-ordinates to top left of page
DPL.SetOrigin(1);

// Select page 1 of fileA
DPL.SelectPage(1);

// Get page height and width
xPageHeight = DPL.PageHeight();
xPageWidth = DPL.PageWidth();

// Capture page 2
CapturedPageID = DPL.CapturePage(2);

// Create OCG for the background
OCG1 = DPL.NewOptionalContentGroup("Background");

// Create a new content stream that we can draw onto
contentstreamPos = DPL.NewContentStream();
DPL.SelectContentStream(contentstream);

// Draw the captured page onto the current page
ret = DPL.DrawCapturedPage(CapturedPageID, 0, 0, xPageWidth, xPageHeight);

// Associate the new content stream with the new OCG
DPL.SetContentStreamOptional(OCG1);

// Make the OCG visible
DPL.SetOptionalContentGroupVisible(OCG1, 1);

// Save the file
DPL.SaveToFile("overlay.pdf");