I am trying to add images using the addWatermarkfromFile. These images
are variable and depend on certain text that has been placed in the PDF.
The PDF is about 2000 pages with 4 different images placed on every other page. When I run in batch, I get a COS document table error around the 264th page. Any ideas on how to fix this. Here is my code just in case you want to look:
/* Put script title here */
var ckWord, numWords, pgNum, vertPos, horzPos, pagePos;
for (var p = 0; p < this.numPages; p++)
{
vertPos = 0;
horzPos = 0;
pagePos = 0;
//while (ckWord != "IMAGE")
var numWords = this.getPageNumWords(p);
for (var i=0; i
The reason you are having this problem is because you are placing unique watermarks on all the pages, this eats up huge amounts of memory and bloats your PDF. Since you are using the same image on many, many pages. It's worthwhile to run through all the pages and collect information on what images are needed on what pages, then use the page range options in the watermark function. All images place in the "range" are the same image. This will reduce file bloat and hopefully reduce the overflow error.
A better solution is to use Page Templates. The template.spawn() function returns a CosObj object that can be reused many times to overlay an image on a PDF Page. This way all the same images are really the same image internally in the PDF, even if they are placed on non-sequential pages.
To use this strategy you will first have to place one image on a blank page of the correct size. There is a "doc.newPage()" function that will help. Then turn that page into a "Template". Then save the result from the first spawn to use with later image overlays. When the document is finished, delete the template page.
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script