<commit_before>---
layout: post
title:  "Alfresco pdf rotation"
date:   2015-07-22 23:56:45
comments: true
categories:
- blog
permalink: rotate-pdf
description: Create a custom action to rotate pdf and add it to share.
---

Let's see how to create a custom action to rotate pdf files. We will use the library pdfBox for which Alfresco
already depends. The result will be display in the Share UI:

![rotate.screen]({{ site.url }}/assets/posts/rotate/rotate-screen.png)

>My config:
>
> > * Alfresco Community 5.0.c
> > * Fedora 20
> > * Maven 3.2.3
> > * Maven SDK 2.0.0
> > * Intellij Idea 14

## Repository

### Create action

The action itself is quite simple. It takes only one parameter to tell which direction you want to rotate.
{% gist 6a33dd8adb60e112ead6 %}

### Spring context
You need to register the bean in the spring context. The id of the bean will re-used later to call the action. Notice
 the parent `action-executer`.
{% highlight xml%}
  <bean id="rotate-pdf" class="somepath/action/RotatePdfAction" parent="action-executer"/>
{% endhighlight %}

## Share

### Share custom config
On the share side, most of the work is done in the `share-config-custom.xml`. We will define two actions, one to rotate
clockwise and
one to rotate counter-clockwise. At the end, we add the actions in the document details page.
{% highlight xml%}
<alfresco-config>

  <config evaluator="string-compare" condition="DocLibActions">
    <actions>
<!-- Action rotate clockwise -->
      <action id="rotate-pdf-clockwise" type="javascript" label="action.rotate-pdf-clockwise" icon="rotate_cw">
        <param name="function">onActionSimpleRepoAction</param>
        <permissions>
          <permission allow="true">Write</permission>
        </permissions>
        <!-- point to the action newly created, here the bean id is used -->
        <param name="action">rotate-pdf</param>
        <!-- param of the action -->
        <param name="clockwise">true</param>
        <param name="failureMessage">message.rotate-pdf.failure</param>
        <evaluator>custom.evaluator.pdf</evaluator>
      </action>
<!-- Action rotate counter-clockwise -->
      <action id="rotate-pdf-anti-clockwise" type="javascript" label="action.rotate-pdf-anti-clockwise" icon="rotate">
        <param name="function">onActionSimpleRepoAction</param>
        <permissions>
          <permission allow="true">Write</permission>
        </permissions>
        <param name="action">rotate-pdf</param>
        <param name="clockwise">false</param>
        <param name="failureMessage">message.rotate-pdf.failure</param>
        <evaluator>custom.evaluator.pdf</evaluator>
      </action>
    </actions>

<!-- Extend the document details action group to add our actions there -->
    <actionGroups>
      <actionGroup id="document-details">
        <action index="600" id="rotate-pdf-clockwise"/>
      </actionGroup>
      <actionGroup id="document-details">
        <action index="601" id="rotate-pdf-anti-clockwise"/><commit_msg>Simply share custom - actions<commit_after>---
layout: post
title:  "Alfresco pdf rotation"
date:   2015-07-22 23:56:45
comments: true
categories:
- blog
permalink: rotate-pdf
description: Create a custom action to rotate pdf and add it to share.
---

Let's see how to create a custom action to rotate pdf files. We will use the library pdfBox for which Alfresco
already depends. The result will be display in the Share UI:

![rotate.screen]({{ site.url }}/assets/posts/rotate/rotate-screen.png)

>My config:
>
> > * Alfresco Community 5.0.c
> > * Fedora 20
> > * Maven 3.2.3
> > * Maven SDK 2.0.0
> > * Intellij Idea 14

## Repository

### Create action

The action itself is quite simple. It takes only one parameter to tell which direction you want to rotate.
{% gist 6a33dd8adb60e112ead6 %}

### Spring context
You need to register the bean in the spring context. The id of the bean will re-used later to call the action. Notice
 the parent `action-executer`.
{% highlight xml%}
  <bean id="rotate-pdf" class="somepath/action/RotatePdfAction" parent="action-executer"/>
{% endhighlight %}

## Share

### Share custom config
On the share side, most of the work is done in the `share-config-custom.xml`. We will define two actions, one to rotate
clockwise and
one to rotate counter-clockwise. At the end, we add the actions in the document details page.
{% highlight xml%}
<alfresco-config>

  <config evaluator="string-compare" condition="DocLibActions">
    <actions>
<!-- Action rotate clockwise -->
      <action id="rotate-pdf-clockwise" type="javascript" label="action.rotate-pdf-clockwise" icon="rotate_cw">
        <param name="function">onActionSimpleRepoAction</param>
        <permissions>
          <permission allow="true">Write</permission>
        </permissions>
        <!-- point to the action newly created, here the bean id is used -->
        <param name="action">rotate-pdf</param>
        <!-- param of the action -->
        <param name="clockwise">true</param>
        <param name="failureMessage">message.rotate-pdf.failure</param>
        <evaluator>custom.evaluator.pdf</evaluator>
      </action>
<!-- Action rotate counter-clockwise -->
      <action id="rotate-pdf-anti-clockwise" type="javascript" label="action.rotate-pdf-anti-clockwise" icon="rotate">
        <param name="function">onActionSimpleRepoAction</param>
        <permissions>
          <permission allow="true">Write</permission>
        </permissions>
        <param name="action">rotate-pdf</param>
        <param name="clockwise">false</param>
        <param name="failureMessage">message.rotate-pdf.failure</param>
        <evaluator>custom.evaluator.pdf</evaluator>
      </action>
    </actions>

<!-- Extend the document details action group to add our actions there -->
    <actionGroups>
      <actionGroup id="document-details">
        <action index="600" id="rotate-pdf-clockwise"/>
        <action index="601" id="rotate-pdf-anti-clockwise"/>
{'fraction_non_alphanumeric': 0.1290539405141993, 'fraction_numerical': 0.014115274743740547, 'mean_word_length': 3.4988662131519273, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5922559', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1724, 'n_words': 543}