xilopaint / alfred-pdf-tools

Optimize, encrypt and manipulate PDF files.
MIT License
149 stars 10 forks source link

Can't merge two pdfs #3

Closed ckotte closed 7 years ago

ckotte commented 7 years ago

Looks like there's something wrong with one of the pdfs!? How can I enable debugging of the workflow or the Python scripts??

xilopaint commented 7 years ago

There's a debug tool for workflows in Alfred Preferences:

screen shot 2017-05-07 at 3 18 42 pm

ckotte commented 7 years ago

here's the output:

[2017-05-08 10:33:34][trigger.action] Processing output of 'utility.argument' with arg '( "/Users/xxx/Documents/test/5.pdf", "/Users/xxx/Documents/test/6.pdf" )' [2017-05-08 10:33:34][utility.argument] Processing output of 'input.keyword' with arg '' [2017-05-08 10:33:40][input.keyword] Processing output of 'utility.argument' with arg 'test3' [2017-05-08 10:33:40][utility.argument] Processing output of 'action.script' with arg '' [2017-05-08 10:33:40][ERROR: action.script] Traceback (most recent call last): File "/Users/xxx/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.EED19C5F-EA04-4641-BF0F-95F36108230B/merge.py", line 64, in sys.exit(main()) File "/Users/xxx/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.EED19C5F-EA04-4641-BF0F-95F36108230B/merge.py", line 36, in main reader = PdfFileReader(open(pdf, 'rb')) File "/Users/xxx/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.EED19C5F-EA04-4641-BF0F-95F36108230B/PyPDF2/pdf.py", line 1084, in init self.read(stream) File "/Users/xxx/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.EED19C5F-EA04-4641-BF0F-95F36108230B/PyPDF2/pdf.py", line 1901, in read raise utils.PdfReadError("Could not find xref table at specified location") PyPDF2.utils.PdfReadError: Could not find xref table at specified location [2017-05-08 10:33:40][action.script] Processing output of 'output.notification' with arg '' [2017-05-08 10:33:40][action.script] Processing output of 'action.script' with arg ''

ckotte commented 7 years ago

I doesn't get the error with other pdfs

xilopaint commented 7 years ago

Please, test this build and tell me what happens:

beta build.zip

ckotte commented 7 years ago

looks like its the same issue:

Starting debug for 'Alfred PDF Tools'

[2017-05-08 19:25:22][trigger.action] Processing output of 'utility.argument' with arg '( "/Users/xx/Documents/test/5.pdf", "/Users/xx/Documents/test/6.pdf" )' [2017-05-08 19:25:22][utility.argument] Processing output of 'input.keyword' with arg '' [2017-05-08 19:25:25][input.keyword] Processing output of 'utility.argument' with arg 'test3' [2017-05-08 19:25:25][utility.argument] Processing output of 'action.script' with arg '' [2017-05-08 19:25:25][ERROR: action.script] Traceback (most recent call last): File "/Users/xxx/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.8F206B4F-4FC3-450E-A6DB-41275900C545/merge.py", line 64, in sys.exit(main()) File "/Users/xxx/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.8F206B4F-4FC3-450E-A6DB-41275900C545/merge.py", line 36, in main reader = PdfFileReader(open(pdf, 'rb'), strict=False) File "/Users/xxx/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.8F206B4F-4FC3-450E-A6DB-41275900C545/PyPDF2/pdf.py", line 1084, in init self.read(stream) File "/Users/xxx/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.8F206B4F-4FC3-450E-A6DB-41275900C545/PyPDF2/pdf.py", line 1901, in read raise utils.PdfReadError("Could not find xref table at specified location") PyPDF2.utils.PdfReadError: Could not find xref table at specified location [2017-05-08 19:25:25][action.script] Processing output of 'output.notification' with arg '' [2017-05-08 19:25:25][action.script] Processing output of 'action.script' with arg ''

xilopaint commented 7 years ago

It might be difficult to debug the issue without the offending PDF file. Would it be possible to share the file in case it doesn't have any sensitive information?

ckotte commented 7 years ago

unfortunately, it's an invoice..

Looks like the pdf is corrupt. I couldn't find much about "Could not find xref table at specified location" except that a guy has the same issue with a corrupted pdf.

I get the same if I execute:

from PyPDF2 import PdfFileReader, PdfFileWriter test_reader = PdfFileReader(file("6.pdf", "rb")) Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/site-packages/PyPDF2/pdf.py", line 1084, in init self.read(stream) File "/usr/local/lib/python2.7/site-packages/PyPDF2/pdf.py", line 1901, in read raise utils.PdfReadError("Could not find xref table at specified location") PyPDF2.utils.PdfReadError: Could not find xref table at specified location test_reader = PdfFileReader(file("eee.pdf", "rb"))

Is it possible to implement a popup in Alfred that shows me the file that couldn't be merged or just merge all files before the one that doesn't work?? I had several pdfs and I needed to find the non-working file by merging only two files at the same time..

xilopaint commented 7 years ago

Unfortunately I would need the offending file to reproduce the issue and implement such feature.

ckotte commented 7 years ago

How can I send you the file? I don't want to post it here.

I also found a solution: You can repair a corrupted file with Ghostscript: gs -o repaired.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress corrupted.pdf GPL Ghostscript 9.21 (2017-03-16) Copyright (C) 2017 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. **** Warning: File has some garbage before %PDF- . Processing pages 1 through 1. Page 1

It would be nice if you could implement this in the workflow and post an OSX Notification if a file was corrupted or if it can't be processed at all.

xilopaint commented 7 years ago

You can send me a share link by private message in Alfred Forum where I have the same username.

Regarding the suggested repair solution, I don't plan to implement it, since to bundle the workflow with Ghostscript would double its size in order to address an individual and rare issue.

xilopaint commented 7 years ago

Please, if you don't want to send the file anymore let me know and I will close the issue.