Open Jem2104 opened 4 years ago
hi @Jem2104, if this is something you're still struggling with, can you verify that docx2pdf is the issue by trying to convert this single file using the docx2pdf command line interface?
So you mean by just saving the new updated docx on my laptop and then converting it to pdf through the command line in my IDE?
Yup!
I just tried it and it gave me the exact same problem / error as I explained in my initial post. If I need to check anything else, let me know and I'll try it! :)
Really hoping this is something that can be fixed as this module would make my project perfect
@Jem2104 yes, if possible can you attach a version of your document that reproduces the error? of course stripped of any sensitive or personal information
Do you mean the code I'm working with? If so, please have a look at the original post of this thread. If you need it in any other format, please let me know and I'll provide it.
If you mean the original docx that get's updated into a new docx and then saved as a new docx before being converted to pdf: this is the one Contract.GithubVersion.docx
Unfortunately I'm not experienced enough with JXA to find out what's going wrong, but I had the same problem. I solved it by making this AppleScript version -- save it as an applescript droplet app and then just drag the files/folders to convert onto it. You may need to 'prime' word's permissions so that it can access the folders by first dragging the parent folder onto Word, otherwise you could get a 'grant permission' dialog for each file.
@sourtin I'm getting "grant folder access" errors too, what do you mean by "dragging the parent folder onto Word" to 'prime' the permissions? That seems like what I want to do but not sure exactly how...
@sourtin I'm getting "grant folder access" errors too, what do you mean by "dragging the parent folder onto Word" to 'prime' the permissions? That seems like what I want to do but not sure exactly how...
It's been a while, but I think what I did was:
@wearley thanks, I was actually trying to get docx2pdf
to work, but that didn't work for me. However what DID work was using this applescript I could run with automator as a quick action:
use scripting additions
property word_docs : {"org.openxmlformats.wordprocessingml.document", "com.microsoft.word.doc"}
property default_path : (path to desktop) as alias
property Delim : {".docx", ".doc"}
property PDF : ".pdf"
on run {input, parameters}
set outPDF to {}
-- replace Word document extensions with PDF, and append to outPDF list
set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, Delim}
repeat with afile in input
copy item 1 of text items of (afile as text) & PDF to the end of outPDF
end repeat
set AppleScript's text item delimiters to TID
tell application id "com.microsoft.Word"
set visible to false
activate
repeat with i from 1 to count of input
open (item i of input)
set theOutputPath to (item 1 of outPDF)
open for access file theOutputPath
tell active document
save as it file name theOutputPath file format format PDF
close saving yes
end tell
end repeat
quit
end tell
return input
end run
which ALSO didn't work until I specifically added the line open for access file theOutputPath
.
Link here: https://apple.stackexchange.com/questions/269539/applescript-pages-export-to-pdf-fails-due-to-sandbox-permissions
I'm not super sure how all the mac sandbox permissions work, but that fixed it, and the script works without getting the "grant access for this file..." dialog in word.
@AlJohri Is there any way to add anything similar to docx2pdf
to make it work without the permissions dialog?
First of all, I think this module is awesome as there are nearly no other easy options to convert a docx to a pdf using Python. So if this problem could be solved, I'd be very happy.
I created a script that opens a docx, edit some text variables according to a Tkinter Entry input and then saves it as a new docx. I then want to convert it to a pdf so that I don't need to do that manually but that's the part which I can't get to succeed. I'll share with you my code and all the output it gives me:
My code:
Before I added the os.chmod(path, 0o777), it would ask me for permission. After I added that, it wouldn't ask me for permission anymore but it still didn't work. In this SO question, I've also asked my question. After running the above code, it gives me
0%| | 0/1 [00:02<?, ?it/s]
It then opens the file in MS Word but doesn't do anything in Word and then it gives me:{'input': '/Users/Jem/Documents/Huurovereenkomsten/Specifiek/slotlaan73/contractabc.docx', 'output': '/Users/Jem/Documents/Huurovereenkomsten/Specifiek/slotlaan73/contractabc.pdf', 'result': 'error', 'error': 'Error: Er heeft zich een fout voorgedaan.'}
'Er heeft zich een fout voorgedaan.' is Dutch for: an error has occurred.I'm using python 3.8 and docx2pdf 0.1.7
Really hoping you can find a solution for this because, as said, I think this module can be very useful.