These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to stop screen blinking when inserting pages (sliently)

gavin2u
Registered: Jul 3 2009
Posts: 76
Answered

Hi, all

In my code, the method insertPages() has been executed for hundreds of times, and the screen was always winking crazily when program run insertPages().

How could i stop the screen refreshment? part of my js as follows,

...
 
var tempPDF = app.newDoc();
 
for(var i = 0; i < iPageCount; i++) {
    var iPadPageNo = fnPadZeros(i + 1, iPageCount.toString().length);
    var tempNewPDF = app.openDoc({ cPath: sTempPngFolderPath + sBaseFileName
                                       + "_Page_"
                                       + iPadPageNo
                                       + ".png",
                                   bUseConv: true,
                                   bHidden: true });
    //
    tempNewPdfPath = sTempPdfFolderPath + sBaseFileName + iPadPageNo + ".pdf";
    tempNewPDF.saveAs({ cPath: tempNewPdfPath });
    //
    tempPDF.insertPages({ nPage: tempPDF.numPages - 1, cPath: tempNewPdfPath });
    //
    tempNewPDF.closeDoc(true);
}
 
tempPDF.saveAs({ cPath: sReleasedPdfFolderPath + sBaseFileName + ".pdf" });
tempPDF.closeDoc(true);
 
console.println( sBaseFileName + ".pdf - Created Successfully!");
 
...

Thanks

- gavin

My Product Information:
Acrobat Pro 9.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Hey, this is pretty good!! There a few things you can do to clean up your process and maybe make it faster and more robust.

1) Saving the newly created image files can add a lot of space to your drive, especially since they could be very large. Try using the existing path for the newly created file (tempNewPDF.path), then closing the doc without saving. I don't know if this will work because the file has a ".tmp" extension.

2) The blinking migth be reduced or go away if all the files are opened as hidden. For the "tempPDF" file, Save and close it first, then reopen as hidden.

3) There are a couple of totally different strategies for creating an image PDF. Either of these might improve the process. For both situations it would be best to start off with a PDF that's already has the correct number of blank pages.
a) Create a Button field on each page, that is the size of the page and setup to display an image.
fld.buttonPosition = position.iconOnly. You can also set the scaling and postion parameters if you want. In your loop use the fld.buttonImportIcon() function to load the images. At the end you can flatten the PDF to get rid of the button objects. but this is optional

b) Use the doc.addWatermarkFromFile() function to place the images on each page. This technique has to be used carefully. Watermarking is non-blocking and so it can cause a timing problem that will crash Acrobat. You'll also need to acquire and rename the OCG each time the watermark is applied. You'll find code and an example in this article.

http://www.acrobatusers.com/tutorials/2006/create_use_layers

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
One other thing. If you have a file name pattern for your pngs, but don't know how many files are in a folder, you can run a while loop, instead of the for loop, until the openDoc function throws an exception, catch the exception and use it to end the loop.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

gavin2u
Registered: Jul 3 2009
Posts: 76
Above all, THANK YOU VERY MUCH for your so detailed clarification.

My Hearty thanks. :)

thomp wrote:
1) Saving the newly created image files can add a lot of space to your drive, especially since they could be very large. Try using the existing path for the newly created file (tempNewPDF.path), then closing the doc without saving. I don't know if this will work because the file has a ".tmp" extension.
this idea is so good, i am troubling with a mess of one-page PDFs. k, i will try it out.


thomp wrote:
2) The blinking might be reduced or go away if all the files are opened as hidden. For the "tempPDF" file, Save and close it first, then reopen as hidden.
Great! just closing and re-opening the doc, the blinking would be disappeared. Thomp, you are the man of genius. This simple step would solved my winking problem. :)


thomp wrote:
3) There are a couple of totally different strategies for creating an image PDF. Either of these might improve the process. For both situations it would be best to start off with a PDF that's already has the correct number of blank pages.
a) Create a Button field on each page, that is the size of the page and setup to display an image.
fld.buttonPosition = position.iconOnly. You can also set the scaling and postion parameters if you want. In your loop use the fld.buttonImportIcon() function to load the images. At the end you can flatten the PDF to get rid of the button objects. but this is optional

b) Use the doc.addWatermarkFromFile() function to place the images on each page. This technique has to be used carefully. Watermarking is non-blocking and so it can cause a timing problem that will crash Acrobat. You'll also need to acquire and rename the OCG each time the watermark is applied.
See, what I wanna achieve as follows three steps,
1. add watermark to each page of original PDF page.
2. 'couse watermark in the PDF file could be removed in just one menu command, so easily, I, as described in my former question threads, save the PDF file as PNG image files. This step would merge PDF page content and watemark absolutely.
3. convert and merge those png image files generated in step 2.
Before action, I was attempting to merge PDF page content and watermark absolutely in various way. However, merging layers, flattening layers ... etc, those operations are not merge them absolutely, they could be taken apart easily, using the menu item - Tools > Advanced Editing > TouchUp Object Tool.Thanks again, Thomp.

Regards,

- gavin
gavin2u
Registered: Jul 3 2009
Posts: 76
thomp wrote:
One other thing. If you have a file name pattern for your pngs, but don't know how many files are in a folder, you can run a while loop, instead of the for loop, until the openDoc function throws an exception, catch the exception and use it to end the loop.
The numPages of the document is retrieved in the step 1, which i described in the reply i just posted.

Thanks for your tips.

:D
gavin2u
Registered: Jul 3 2009
Posts: 76
PS, the content of original pdf is also images, not editable text or other editable element, produced by my Fujitsu ScanSnap. :)

good day.
gavin2u
Registered: Jul 3 2009
Posts: 76
Hi :)

I rewrite some of my code, as follows,

... // create a pdf to store finally generated documentvar oReleasedPDF = app.newDoc(); for(var i = 0; i < iPageCount; i++) {var iPadPageNo = fnPadZeros(i + 1, iPageCount.toString().length);var oTempPDF = app.openDoc({ cPath: sTempPngFolderPath + sBaseFileName+ "_Page_"+ iPadPageNo+ ".png",bUseConv: true,bHidden: true });// path to save temp pdfvar sTempPdfPath = soReleasedPDFFolderPath + "tmp.pdf";oTempPDF.saveAs({ cPath: sTempPdfPath });// close temp pdf fileoTempPDF.closeDoc(true);// insert page to released pdfoReleasedPDF.insertPages({ nPage: oReleasedPDF.numPages - 1, cPath: sTempPdfPath });}// remove the blank page generated when creationoReleasedPDF.deletePages({ nStart: 0, nEnd: 0 });oReleasedPDF.saveAs({ cPath: sReleasedPdfFolderPath + sBaseFileName + ".pdf" });oReleasedPDF.closeDoc(true);// display success messageconsole.println( sBaseFileName + ".pdf - Success!"); ..

saveAs() method can overwrite an existing file which stay closed. this is so important.

this way, the program only generated one temp pdf file, and it will be always one. :)

and, i noticed that, the blinking problem is caused by the temp pdf (oTempPDF).

once a temp pdf created from png, the screen winks a time, although i add the [b]bHidden: true[/b] to [b]oTempPDF = app.openDoc[/b]

any ideas? thanks

- gavin
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I was afraid that wouldn't work:( Acrobat probably ignores the hidden attribute when converting the PNG files. There's a document attribute for suspending the redrawing of field appearances, "doc.delay", give it a try, but I don't think it'll help with this. I think it's just going to blink with this method. One of the other methods I outlined will help, placing the images in buttons or watermarks.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script