Programmatically adding JavaScripts to existent PDF files?

Hello:

I searched in the PDFNetC help and there is only one mention of the term
"JavaScript".
I assume that JavaScripts are added to PDF files at the COS SDF/level,
correct?

Can anyone please provide an example?

TIA,

-RFH

In PDF format, JavaScript is usually added as part of JavaScript
Action objects (see “JavaScript Actions” on page 709 in PDF Reference
Manual rev 1.7).

Using PDFNet you can create a JavaScript Action as follows:

// In C# (JAVA, C++, VB.NET is similar...)
Obj act_dict = doc.CreateIndirectDict();
act_dict.PutName("S", "JavaScript");
act_dict.PutString("JS", "alert(' Hello World! ');");
Action action = new Action(act_dict);

The action can be assigned to a bookmark:

bookmark.SetAction(action);

or with a link annotation:

link.SetLinkAction(action);

or with a 'document' specific event (see See Table 8.47 in PDF
Reference):

// Add Document Close Action
Obj root = pdfdoc.GetRoot();
Obj aa = root.PutDict("AA");
aa.Put("DC", act_dict);

and so forth ...

I would like to extract a TIFF file from a PDF document. The next step will
be to use some OCR software to scrutinize the TIFF file internals. The catch
is that I do no want to save the TIFF file in the filesystem. I prefer
to pass a handle
or pointer provided by SDKNet to the TIFF processing function.

In short: what I need is the TIFF file in RAM, and a pointer to it.

How can I accomplish that?

TIA,

-RFH

Hello Ramon,

You can use image.ExportAsTiff() method that accepts FilterWriter. For
example,

// using C#
MemoryFilter mem = new MemoryFilter(8192, false);
FilterWriter writer = FilterWriter(mem);

image.ExportAsTiff(writer);
writer.FlushAll();

mem.GetBuffer();
int tiff_gif_sz = mem.Count();

// C# / JAVA / VB.NET implementation should be along the same lines:

MemoryFilter mem = new MemoryFilter(8192, false);
FilterWriter writer = new FilterWriter(mem);

image.ExportAsTiff(writer);
writer.FlushAll();

mem.GetBuffer();
mem.Count();
------
On May 29, 1:12 pm, Ramon F Herrera <ra...@forcewise.com> wrote:

I would like to extract a TIFF file from a PDF document. The next step will
be to use some OCR software to scrutinize the TIFF file internals. The catch
is that I do no want to save the TIFF file in the filesystem. I prefer
to pass a handle
or pointer provided by SDKNet to the TIFF processing function.

In short: what I need is the TIFF file in RAM, and a pointer to it.

How can I accomplish that?

TIA,

-RFH

Great! That seems like a really good solution. I am going to
try it right now.

Thanks so much.

-Ramon

Support wrote:

I believe there are some errors in the attached explanation that you
folks kindly sent me.

- The upper snippet uses the variable 'doc', while the lower snippet
uses 'pdfdoc'
   This can be unnecessarily confusing to some users.

- The JavaScript statement alert() should be app.alert()

Thanks and keep up the good work!

-Ramon F Herrera