How to programmatically remove PDF layers? - pdf

I know about Doc.SetOCGOrder() and the likes, but apparently the Acrobat API does not provide means to remove layers (aka optional content groups, ocgs), only to hide them from users while leaving them accessible via scripting.
I'm not forced to use Acrobat, in fact I'd prefer a FOSS-solution (or at least freeware) using e.g. pypdf2 or pdftk. edit There is another post using abcpdf, which is unfortunately not free. Is there any way to port that behaviour to Acrobat's JS or pypdf2? Essentially the answer seems to loop through every page's content, which seems to include the layers.
(Concerning merging, I notice pdftk does remove layers when merging multiple files, so one can simple pdftk A=input.pdf B=input.pdf cat A1-end output output.pdf.)

My approach so far: For the relevant layers obtained via GetOCGs() set locked=true and both initState=false and state=false. Then use SetOCGOrder() to remove the layer from the layers view. Unfortunately this is not perfect, since at least in Acrobat DC I can still select "show all layers" in the layers panel, which still shows the layer. One could merge all layers now, but neither did I find an option to achieve that programmatically nor do I believe that would actually remove the hidden layer's elements.

You can't do it programmatically but you can create an Action that will process a folder full of PDF files using Adobe Acrobat. Set the Action to use the PDF Optimizer to discard hidden layers and flatten visible ones. See the graphic.

Related

deleting and editing acrobat layers

I'm making an interactive map in Adobe Acrobat using layers. Imagine a map with property lines and I click a bookmark to see the property highlighted. click a different bookmark, highlight (with a layer) a different property.
I've got about 40 layers, and bookmarks for each property or category of properties so that when you click it, it displays just the associated image layer(s).
The problem is, people keep requesting changes to the map. I can't delete layers in Acrobat (?), and when I add a layer, the new layer appears with every single bookmark already set up.
The only way I've figured out to make this work is to basically redo the entire map every time. I want to access document javascript to show/hide layers based on bookmarks, but I'm not sure that's accessible. I'm open to options, anything that would get around redoing from scratch every time.
Adobe Acrobat does allow you to manipulate layers using JavaScript. The only confusing bit you need to know is that layers aren't called layers, but OCGs.
OCG stands for "Optional Content Group", which is a technically correct and completely bonkers way to name these things. But well.
From the Adobe Acrobat JavaScript SDK (which you can access on the Adobe DevNet pages for Acrobat):
function TurnOnOCGsForPage(doc, nPage) {
var ocgArray = doc.getOCGs(nPage);
for (var i=0; i < ocgArray.length; i++)
ocgArray[i].state = true;
}

Is it possible to use the After Effects 'Create Shapes from Vector Layer' functionality from within a script (Adobe ExtendScript)?

I am attempting to create a script for Adobe After Effects. Part of what I am attempting to accomplish will require converting layers imported from Illustrator into After Effects shape layers.
I am having trouble finding any info on how this can be accomplished in ExtendScript. Is it possible?
Any menu commands in After effects are available to extendscript, even if they're not included in the API. To invoke a command as you would with a menu you use
app.executeCommand(1234);
Where 1234 is the number of the command you want. To find this magic number there is a function
app.findMenuCommandId("Full text of command as it appears in the menu");
It's kludgy, and there's no guarantee that adobe will stay consistent with the numbers between releases, but it's all we have. More details and a list of magic numbers here

How to create switchable multi-language pdf form?

I want to create a pdf form for two language (Chinese/English) UI, and there's a button(s) or somethings on the form for language switch, is there anyway can make it? and how to do?
thanks!
Thanks for all reply!
Actually I got a sample like this,
PDF Sample
there're two checkbox on the top-left of the form, one is for English UI, the other is Chinese, I just want to know how to make PDF like that sample? (and I don't see any layers on the sample...)
thx
mkl's comment (which he should turn into a full answer, really) already hinted at the option to use different page templates residing in the same file.
Another option you could explore is this:
put the two language versions into 2 different layers (or 'optional content groups' in PDF parlance)
make the visibility of the two layers toggeable
let the user activate that layer which he/she needs.
Layer activation can be handled through normal Acrobat Reader user interface elements.
The layer switching can be made accessible via a "button" on the PDF page too -- but that requires additional JavaScript to be embedded in the PDF (something many people are not particularly keen about).
As Kurt proposed, I make my comment on Frank's answer an answer in its own right:
Actually there is a pdf feature seldomly used nowerdays, page
templates. Thus, those two forms can reside in the same file in
different page templates, and based on some initially present buttons
("English version", ...) the desired form is spawned.
Unfortunately I don't know how to create page templates using some easy-to-use tool, I only came a cross them in the context of integrated PDF signatures (depending on the signature type, page template instantiation is a document change not breaking the signature) and tested them with low-level tools.
Essentially page templates are PDF objects just like page dictionaries of the normal pages, they are not XFA stuff. They merely are not referenced in the pages tree but instead in the name tree.
There is a JavaScript command which creates a visible page based on such a template --- I don't know which anymore; I may be able to find out when I'm back in office next week. This command would have to be bound to the inital language selection button in the file.
The problem will be in switching the static text - PDF does not allow this.
If I were you, I would split the document into two identical forms in the respective languages. You can use bookmarks and links on the first page to navigate to the right part of the document.
Note that it is possible to assign the same field names to the Enlgish/Chinese versions of your fields. This will make it easier to process the submitted form data because the process path would be independent of the chosen language. It will also simplify any JavaScript (validation, summing, etc.) you plan to add.

Extract layers from PDF file to HTML

I have a PDF file, containing layers.
For example, on some pages, there are graphs, with additional data displayed on top of that graph, when clicking (layers).
Now I need to try to fetch all these layers out of the PDF file, or to be precise, I need ALL the data from that PDF file, including layers. The pdf file contains javascript to show/hide the layers when appropriate.
What is the best approach? Is there any tool that actually works for my intentions? Or should I write something myself? (If this is possible ofcourse).
Edit:
Here you can download the PDF file:
http://www.2shared.com/document/IutUfDfr/OR_erasmus.html
The password for viewing is: erasmus
I do not know if there are any tools per se but if you cannot find those you might do the following:
for each combination of on/off layers that you are interested in walk all pages and collect the content streams. Tokenize those and cut out the content you do not want to see (the commands you need to monitor to determine this are BDC and EMC). Save the stream again with the clipped content (naturally save the result in different files). You need something to read the PDF object structure and update some objects (there are lot's of libraries for that), plus you need tobe able to parse the content streams.
Now you will have a set of PDF files without layers (optional content) for which there are plenty tools to render to HTML etc.
Note: optional content <--> layer switches in the PDF viewer usually are 1:1 but the standard supports a full n:m mapping. I would concentrate on the real optional content blocks that can be turned on/off to keep things simple.
you can use this tool to extract images and text from even locked pdfs
http://download.cnet.com/Able2Extract/3000-2079_4-10249654.html
I use it myself sometimes and it has the ability to convert to HTML

Is it possible to reference a photoshop file or layer comp from within another photoshop file?

Creating all the art for a large website often involves a couple dozen 50+mb photoshop files. Frequently, a given module may appear in more than one file.
Is there a way to reference an oft-used module from another file?
For instance -
"site-section-2.psd" references "common-module-h.psd", and "site-section-6.psd" also references "common-module-h.psd", so that any time updates are made to "common-module-h.psd", the updates appear in both files which reference it.
Possible?
(maybe with photoshop javascript?)
I've checked the JSX Photoshop Object Model, and you can access LayerComps, but there is no magic function to save from one file to another. Something like this could be written to disk, from file1.psd for example, then loaded into file2.psd.
It's a bit of a long shot and I don't know if it's worth the trouble.
For web prototyping I use Fireworks and and I'm pretty happy. You can easily create symbols (much like in Flash and Illustrator) and even save them to a Common Library, which means it will be easy peasy to keep your navigation items for example up to date, for all the files using it. You can even import PSD files into Fireworks, only not all the filters will be supported.
Don't know if you can keep most of the eye-candy in Photoshop and then assemble reamble versions with ease using Fireworks.
You can try converting all the layers into one smart object and then drag the smart object layer into the new .psd file.
Go to the Layers palette: Window > Layers(F7).
LMB SINGLE CLICK the top layer.
Scroll down Layer palette until you get to the bottom.
SHIFT + LMB SINGLE CLICK. At this point all the layers should be hilighted.
RMB SINGLE CLICK any of Layer "Titles".
You should see a menu pop up so use the mouse to scroll until you find "Convert to Smart Object". LMB SINGLE CLICK to convert all the layers into one smart object. The smart object can be edited by double clicking it in the Layers palette. You can also drag a smart object from one .PSD into another .PSD. I usually just open both .PSD files and drag the smart object form one Layers palette to the other Layers palette.