Jump to content
xilopaint

Alfred PDF Tools – Optimize, encrypt and manipulate PDF files

Recommended Posts

Oh nice, I actually just posted on the other workflows GitHub seeing if 2016 support was possible and he said no.

 

I agree that it isn't really a good fit for APT I was just naming features of ilovepdf.com that are useful.

 

 

Share this post


Link to post

Currently the source files are moved to trash after merging so it's not possible. However it can be easily implemented. Give me a couple days and I will add the feature in the next release.

Edited by xilopaint

Share this post


Link to post

Update (v2.4):


Improved merge feature

 

Added ability to merge the selected PDF files without moving them to Trash. Use the modifier key instead if you want to move them to Trash after merging.

Edited by xilopaint

Share this post


Link to post

Update (v2.4.1):

 

Minor fix

 

Fixed an issue that prevented notifications to be posted when the merge file action was followed by the  modifier key.

Edited by xilopaint

Share this post


Link to post

@deanishe

 

The Optimize action of this workflow executes a subprocess called k2pdfopt. While running, this subprocess outputs the progress of the operation (tipically informing the conclusion of each page of the PDF file). Look:

 

ZJYMM7t.png

 

Since the operation can take a long time in larger PDF files it would be very neat to show the progress of the operation in Alfred bar, maybe invoking a Script Filter or something that can inform how many pages were processed. Do you know if it's possible to retrieve the output of the subprocess for this purpose?

Edited by xilopaint

Share this post


Link to post

You can read the "SOURCE PAGE X of 4" lines by capturing the STDOUT/STDERR output of the process.

 

Here's a bit of code from a program I wrote that does something similar:

proc = subprocess.Popen(cmd,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.STDOUT)

while True:
    if proc.poll() is not None:  # subprocess has finished
        break
    line = proc.stdout.readline().strip()
    if not line:
        continue

    # parse output here

 

Edited by deanishe

Share this post


Link to post

Thank you, @deanishe.

 

I had already read a similar solution here. My problem is my subprocess is executed from a Run Script object and I need the capability of invoking a Script Filter whenever I want to check the progress (what can happen multiple times in a single execution with large files) . How can I better achieve this? Should I write the output of the subprocess in a file and retrieve the data with the Script Filter or there is any better way?

Edited by xilopaint

Share this post


Link to post

Yup. Writing the status to a file is probably the best way.

 

Another possibility is to start a server for your Script Filter to fetch the status from, but that seems like overkill. 

Share this post


Link to post
6 hours ago, deanishe said:

Yup. Writing the status to a file is probably the best way.

 

Another possibility is to start a server for your Script Filter to fetch the status from, but that seems like overkill. 

 

I tried to use settings API of alfred-workflow and had some issues. In some tests the last line of the subprocess output was not added to settings.json file. Using "with statements" to write and open the files I had no issues. Is wf.settings somewhat slow or bad for using in loops?

 

This is working well:

proc = Popen(command, shell=True, stdout=PIPE)
page_number = 1

while proc.poll() is None:
    line = proc.stdout.readline()
    if "SOURCE PAGE" in line:
        with open(file_page_number, 'w') as f2:
            f2.write(str(page_number))
        page_number = page_number + 1

But this is not always working:

proc = Popen(command, shell=True, stdout=PIPE)
page_number = 1

while proc.poll() is None:
    line = proc.stdout.readline()
    if "SOURCE PAGE" in line:
        wf.settings['page_number'] = str(page_number)
        page_number = page_number + 1

I would like to use wf.settings if possible, but it seems unreliable in my tests. I should be missing something.

Edited by xilopaint

Share this post


Link to post

You shouldn't use the settings API because each Workflow instance assumes it's the only one accessing the settings.json file and will overwrite changes made by other instances/processes running at the same time.

 

It's a bad choice anyway: the settings are persistent data, meant to be kept as long as the workflow is installed. Such data very clearly belong in the cache directory. It's not as if Workflow.cache_data() is any harder to use.

Edited by deanishe

Share this post


Link to post

Update (v2.5):

 

Ability to track the optimization process

 

Added script filter to track the optimization process by the keyword progress, especially useful for large files.

 

Cx94ufN.gif

Edited by xilopaint

Share this post


Link to post

Update (v2.7)

  • Removed support for OneUpdater. From now Alfred PDF Tools relies on Alfred-Workflow library for self-updating.
  • Significant code improvements for better stability and maintenance.


 

Share this post


Link to post

Update (v2.9)

 

Added progress bar for a more friendly tracking of the Optimize action.

 

s8MslWi.gif

 

Thanks @jeffsui for the sample workflow and @deanishe for his contribution in that thread:

 

_

Edited by xilopaint

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×