Rogner un PDF automatiquement

Gregoryen

Membre actif
Club iGen
16 Juin 2013
653
45
32
Arles
www.gregoryen.fr
Bonsoir !

Je vends beaucoup sur leboncoin et j'ai une machine pour imprimer les étiquettes, c'est vraiment top !

Seulement lorsque je reçois le PDF avec l'étiquette prépayé, elle est au format A4.

Voici son format :

macg.jpg

Seulement ce qui m'intéresse c'est uniquement la partie de gauche avec l'adresse, comme ça j'ai juste à la glisser dans mon icône d'imprimante pour que ça sorte.

J'aimerais rogner de sorte à obtenir ça :

macg.jpg

Comment faire avec automator et peut-être un script ?

J'ai la même chose avec les étiquettes de mondial relay. Selon le script j'aurais juste à modifier les valeurs pour qu'il coupe X pixels en haut X à droite, X à gauche et X en bas.

Merci de votre aide et bon week-end !
 
Merci pour la réponse, j'ai essayé.

PDF Zone : je n'ai surement pas compris le fonctionnement mais je n'ai pas réussi faire ce que je voulais.
GraphicConverter : il propose de rogner a X de hauteur et X de largeur, mais ne dit pas à partir de quel pixel faire cela, et comment l'automatiser ?

J'aurais aimé n'ouvrir aucun logiciel et juste le glisser dans une app automator et que le travail se fasse super rapidement.
 
Bonjour,

Pour faire un script de ce que tu demandes, il y a plusieurs choses à savoir.

  • Je sais recadrer un JPEG mais pas un PDF, donc il faut que le script change le PDF en jpeg. Lors de ce changement le nombre de pixel du document change.
  • Pour obtenir les dimensions du recadrage il faut savoir si ton document pdf est horizontal (paysage) ou vertical (portrait) et calculer non pas le nombre de pixel mais un pourcentage (ou un dimension en cm) des valeurs que tu veux supprimer(haut , bas, droite, gauche)

Avec ces infos, je peux essayer de te faire un applescript.
 
Je t'ai préparé un script pour tester
J'ai mis les valeurs de coupe par défaut au vu de ta copie d'écran.
Testé chez moi sur "Mojave"

Au lancement il demande de sélectionner le fichier à traiter
Il le transforme en un fichier du même nom en "Nom_du_fichier.JPEG" enregistré au même endroit
Il te demande d'entrer les valeurs de coupe en millimètres (bas, haut, gauche, droite) des valeurs par défaut son affichées.
il applique les coupes
Il enregistre le nouveau fichier au nom de "Nom_du_fichier-2.JPEG" enregistré au même endroit
il ouvre le fichier et demande son impression.

Il te restera à supprimer ces 2 nouveaux fichiers

Si cela fonctionne je regarderai pour en faire un "droplet"

Bloc de code:
tell application "Finder"
    set monfichier to choose file with prompt "Sélectionnez le fichier PDF à traiter"
    set nom to name of monfichier
    set AppleScript's text item delimiters to {"."} --récupère la partie avant le dernier "."
    set elements to text items of nom
    set nomcourt to (items 1 thru -2 of elements) as string
    set ancien_nom to nomcourt
    
end tell

tell application "Image Events"
    set chemin to the container of monfichier
    set uneimage to open monfichier
    set nouveau to nomcourt & ".JPEG"
    save uneimage as "JPEG" in file nouveau of chemin
    close uneimage
end tell


tell application "Finder"
    set chemin to the container of monfichier as string
    set nouveau to nomcourt & ".JPEG"
end tell

set thePath to chemin & nouveau
set thePath to POSIX path of thePath

my padBottomOfImageAt:(thePath) byPoints:100

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

on padBottomOfImageAt:POSIXPath byPoints:padDepth
    -- build path for new file
    set anNSString to current application's NSString's stringWithString:POSIXPath
    set newPath to anNSString's stringByDeletingPathExtension()
    set theExt to anNSString's pathExtension() as text
    set newPath to (newPath's stringByAppendingString:"-2")'s stringByAppendingPathExtension:theExt
    -- load image as bitmap and get its size
    set oldRep to current application's NSBitmapImageRep's imageRepWithContentsOfFile:POSIXPath
    set {width:theWidth, height:theHeight} to oldRep's |size|()
    set newHeight to theHeight + padDepth
    -- make new bitmapImageRep
    set newRep to (current application's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:theWidth pixelsHigh:newHeight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(current application's NSCalibratedRGBColorSpace) bitmapFormat:(current application's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
    -- store the existing graphics context
    current application's NSGraphicsContext's saveGraphicsState()
    -- set graphics context to new context based on the new bitmapImageRep
    (current application's NSGraphicsContext's setCurrentContext:(current application's NSGraphicsContext's graphicsContextWithBitmapImageRep:newRep))
    -- set the color to black
    current application's NSColor's blackColor()'s |set|()
    -- fill the bottom area with black
    current application's NSRectFill({origin:{x:0, y:0}, |size|:{width:theWidth, height:padDepth}})
    -- draw from the original bitmapImageRep to the new one above the black area
    
    tell application "Finder"
        activate
        display dialog "Entrer la dimension a couper en bas (en milimètres)" default answer "27"
        set bas to text returned of result
        display dialog "Entrer la dimension a couper en haut (en milimètres)" default answer "0"
        set haut to text returned of result
        display dialog "Entrer la dimension a couper à gauche (en milimètres)" default answer "0"
        set gauche to text returned of result
        display dialog "Entrer la dimension a couper à droite (en milimètres)" default answer "114"
        set droite to text returned of result
        if theWidth < theHeight then
            set H to 210
            set V to 297
        else
            set H to 297
            set V to 210
        end if
    end tell
    
    set OX to theWidth / H * gauche
    set OY to theHeight / V * bas
    set SX to theWidth / H * (H - droite - gauche)
    set SY to theHeight / V * (V - haut - bas)
    
    oldRep's drawInRect:{origin:{x:0, y:padDepth}, |size|:{width:theWidth, height:theHeight}} fromRect:{origin:{x:OX, y:OY}, |size|:{width:(SX), height:(SY)}} operation:(current application's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
    -- restore graphics state
    current application's NSGraphicsContext's restoreGraphicsState()
    -- save bitmapImageRep as image
    if {"tif", "tiff"} contains {theExt} then
        set theData to (newRep's representationUsingType:(current application's NSTIFFFileType) |properties|:{NSTIFFCompression:(current application's NSTIFFCompressionLZW)})
    else if {"jpg", "jpeg"} contains {theExt} then
        set theData to (newRep's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:0.8, NSImageProgressive:true})
    else if theExt = "png" then
        set theData to (newRep's representationUsingType:(current application's NSPNGFileType) |properties|:{NSImageInterlaced:true})
    else -- unsupported type
        return false
    end if
    set theResult to (theData's writeToFile:newPath atomically:true)
    return (theResult as boolean)
end padBottomOfImageAt:byPoints:

tell application "Finder"
    set imp to chemin & nomcourt & "-2.JPEG"
    delay 2
    print imp
end tell
 
Merci beaucoup pour ton aide !

Lorsque j'ouvre l'app il m'affiche ce message :

Screenshot - 07-11-2022 à 19h21 09s - CleanShot - CleanShot.png

Mais on ne peux pas garder le format PDF ? J'arrive à crop un PDF avec aperçu.

Voici les valeurs que je dois croper mais je ne sait pas ou les modifier :

367 à droite
44 à gauche
239 en bas
50 en haut

Est-ce qu'on peux faire en sorte que je glisse le fichier sur l'app, et que celui-ci soit automatiquement remplacé ?

Merci beaucoup en tout cas !
 
Peux-tu me détailler comment tu procèdes pour ouvrir l'application ?
et sur quel ordi et quel OS car j'ai des doute sur le procès utilisé "Image Events" qui fonctionne sans problème chez moi sur OS Mojave, mais à l'air d'avoir des soucis sur des OS plus récent, Malheureusement je ne peux pas tester.

Dans "Aperçu" je n'ai pas trouver de possibilités de le scripter pour ce que tu demandes.

Autre solution : Si tu possèdes photoshop tu as la possibilité de créer un script et d'en faire un droplet.
 
Dernière édition:
Bonjour,
J'ai légèrement modifié le script pour un nouvel essai...
Dis-moi si cela fonctionne !
Est-ce qu'on peux faire en sorte que je glisse le fichier sur l'app, et que celui-ci soit automatiquement remplacé ?
Oui , si le script fonctionne on pourra faire ça!

Bloc de code:
tell application "Finder"
    set monfichier to choose file with prompt "Sélectionnez le fichier PDF à traiter"
    set nom to name of monfichier
    set AppleScript's text item delimiters to {"."} --récupère la partie avant le dernier "."
    set elements to text items of nom
    set nomcourt to (items 1 thru -2 of elements) as string
    set ancien_nom to nomcourt
    set chemin to the container of monfichier as alias
end tell

tell application "Image Events"
    set uneimage to open monfichier
    set nouveau to nomcourt & ".JPEG"
    save uneimage as "JPEG" in file nouveau of chemin
    close uneimage
end tell

tell application "Finder"
    set chemin to the container of monfichier as string
    set nouveau to nomcourt & ".JPEG"
end tell

set thePath to chemin & nouveau
set thePath to POSIX path of thePath

my padBottomOfImageAt:(thePath) byPoints:100

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

on padBottomOfImageAt:POSIXPath byPoints:padDepth
    -- build path for new file
    set anNSString to current application's NSString's stringWithString:POSIXPath
    set newPath to anNSString's stringByDeletingPathExtension()
    set theExt to anNSString's pathExtension() as text
    set newPath to (newPath's stringByAppendingString:"-2")'s stringByAppendingPathExtension:theExt
    -- load image as bitmap and get its size
    set oldRep to current application's NSBitmapImageRep's imageRepWithContentsOfFile:POSIXPath
    set {width:theWidth, height:theHeight} to oldRep's |size|()
    set newHeight to theHeight + padDepth
    -- make new bitmapImageRep
    set newRep to (current application's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:theWidth pixelsHigh:newHeight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(current application's NSCalibratedRGBColorSpace) bitmapFormat:(current application's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
    -- store the existing graphics context
    current application's NSGraphicsContext's saveGraphicsState()
    -- set graphics context to new context based on the new bitmapImageRep
    (current application's NSGraphicsContext's setCurrentContext:(current application's NSGraphicsContext's graphicsContextWithBitmapImageRep:newRep))
    -- set the color to black
    current application's NSColor's blackColor()'s |set|()
    -- fill the bottom area with black
    current application's NSRectFill({origin:{x:0, y:0}, |size|:{width:theWidth, height:padDepth}})
    -- draw from the original bitmapImageRep to the new one above the black area
    
    tell application "Finder"
        activate
        display dialog "Entrer la dimension a couper en bas (en milimètres)" default answer "27"
        set bas to text returned of result
        display dialog "Entrer la dimension a couper en haut (en milimètres)" default answer "0"
        set haut to text returned of result
        display dialog "Entrer la dimension a couper à gauche (en milimètres)" default answer "0"
        set gauche to text returned of result
        display dialog "Entrer la dimension a couper à droite (en milimètres)" default answer "114"
        set droite to text returned of result
        if theWidth < theHeight then
            set H to 210
            set V to 297
        else
            set H to 297
            set V to 210
        end if
    end tell
    
    set OX to theWidth / H * gauche
    set OY to theHeight / V * bas
    set SX to theWidth / H * (H - droite - gauche)
    set SY to theHeight / V * (V - haut - bas)
    
    oldRep's drawInRect:{origin:{x:0, y:padDepth}, |size|:{width:theWidth, height:theHeight}} fromRect:{origin:{x:OX, y:OY}, |size|:{width:(SX), height:(SY)}} operation:(current application's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
    -- restore graphics state
    current application's NSGraphicsContext's restoreGraphicsState()
    -- save bitmapImageRep as image
    if {"tif", "tiff"} contains {theExt} then
        set theData to (newRep's representationUsingType:(current application's NSTIFFFileType) |properties|:{NSTIFFCompression:(current application's NSTIFFCompressionLZW)})
    else if {"jpg", "jpeg"} contains {theExt} then
        set theData to (newRep's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:0.8, NSImageProgressive:true})
    else if theExt = "png" then
        set theData to (newRep's representationUsingType:(current application's NSPNGFileType) |properties|:{NSImageInterlaced:true})
    else -- unsupported type
        return false
    end if
    set theResult to (theData's writeToFile:newPath atomically:true)
    return (theResult as boolean)
end padBottomOfImageAt:byPoints:

tell application "Finder"
    set imp to chemin & nomcourt & "-2.JPEG"
    delay 2
    print imp
end tell
 
Bonsoir, j'ai toujours le même message. Est-ce lié a Ventura ou au fait que je suis sur M1 ?

Après j'ai procédé de la sortes, j'ai ouvert automator, mis le script, et crée un .app , peut-être ai-je mal procédé aussi !
 
Bonjour,

Il ne faut pas se servir d'automator !

Tu ouvres "Editeur de script" qui est dans Applications-->Utilitaires
Dans la fenêtre qui s'ouvre tu choisis nouveau document en bas à gauche
Dans la nouvelle fenêtre qui s'ouvre tu fais un copier coller du script
Tu le lances en cliquant sur exécuter en haut à gauche.
 
OK!
Ils ont du changer un truc dans le procès "image Events", et je ne peux pas vérifier le dictionnaire de l'application vu que je n'ai pas de M1 ni ventura !

Je tente un nouvel essai ...

Edit: j'y pense tu peux essayer d'autoriser "image Events" dans :
  • Accessibilité
  • Accès complet au disque
  • Automatisation
Cela se passe dans préférence système --> sécurité et confidentialité

Bloc de code:
tell application "Finder"
    set monfichier to choose file with prompt "Sélectionnez le fichier PDF à traiter"
    set nom to name of monfichier
    set AppleScript's text item delimiters to {"."} --récupère la partie avant le dernier "."
    set elements to text items of nom
    set nomcourt to (items 1 thru -2 of elements) as string
    set ancien_nom to nomcourt
    set chemin to the container of monfichier as alias
    set nouveau to nomcourt & ".JPEG"
end tell

tell application "Image Events"
    set uneimage to open monfichier
    save uneimage as "JPEG" in file nouveau of chemin
    close uneimage
end tell

tell application "Finder"
    set chemin to the container of monfichier as string
    set nouveau to nomcourt & ".JPEG"
end tell

set thePath to chemin & nouveau
set thePath to POSIX path of thePath

my padBottomOfImageAt:(thePath) byPoints:100

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

on padBottomOfImageAt:POSIXPath byPoints:padDepth
    -- build path for new file
    set anNSString to current application's NSString's stringWithString:POSIXPath
    set newPath to anNSString's stringByDeletingPathExtension()
    set theExt to anNSString's pathExtension() as text
    set newPath to (newPath's stringByAppendingString:"-2")'s stringByAppendingPathExtension:theExt
    -- load image as bitmap and get its size
    set oldRep to current application's NSBitmapImageRep's imageRepWithContentsOfFile:POSIXPath
    set {width:theWidth, height:theHeight} to oldRep's |size|()
    set newHeight to theHeight + padDepth
    -- make new bitmapImageRep
    set newRep to (current application's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:theWidth pixelsHigh:newHeight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(current application's NSCalibratedRGBColorSpace) bitmapFormat:(current application's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
    -- store the existing graphics context
    current application's NSGraphicsContext's saveGraphicsState()
    -- set graphics context to new context based on the new bitmapImageRep
    (current application's NSGraphicsContext's setCurrentContext:(current application's NSGraphicsContext's graphicsContextWithBitmapImageRep:newRep))
    -- set the color to black
    current application's NSColor's blackColor()'s |set|()
    -- fill the bottom area with black
    current application's NSRectFill({origin:{x:0, y:0}, |size|:{width:theWidth, height:padDepth}})
    -- draw from the original bitmapImageRep to the new one above the black area
  
    tell application "Finder"
        activate
        display dialog "Entrer la dimension a couper en bas (en milimètres)" default answer "27"
        set bas to text returned of result
        display dialog "Entrer la dimension a couper en haut (en milimètres)" default answer "0"
        set haut to text returned of result
        display dialog "Entrer la dimension a couper à gauche (en milimètres)" default answer "0"
        set gauche to text returned of result
        display dialog "Entrer la dimension a couper à droite (en milimètres)" default answer "114"
        set droite to text returned of result
        if theWidth < theHeight then
            set H to 210
            set V to 297
        else
            set H to 297
            set V to 210
        end if
    end tell
  
    set OX to theWidth / H * gauche
    set OY to theHeight / V * bas
    set SX to theWidth / H * (H - droite - gauche)
    set SY to theHeight / V * (V - haut - bas)
  
    oldRep's drawInRect:{origin:{x:0, y:padDepth}, |size|:{width:theWidth, height:theHeight}} fromRect:{origin:{x:OX, y:OY}, |size|:{width:(SX), height:(SY)}} operation:(current application's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
    -- restore graphics state
    current application's NSGraphicsContext's restoreGraphicsState()
    -- save bitmapImageRep as image
    if {"tif", "tiff"} contains {theExt} then
        set theData to (newRep's representationUsingType:(current application's NSTIFFFileType) |properties|:{NSTIFFCompression:(current application's NSTIFFCompressionLZW)})
    else if {"jpg", "jpeg"} contains {theExt} then
        set theData to (newRep's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:0.8, NSImageProgressive:true})
    else if theExt = "png" then
        set theData to (newRep's representationUsingType:(current application's NSPNGFileType) |properties|:{NSImageInterlaced:true})
    else -- unsupported type
        return false
    end if
    set theResult to (theData's writeToFile:newPath atomically:true)
    return (theResult as boolean)
end padBottomOfImageAt:byPoints:

tell application "Finder"
    set imp to chemin & nomcourt & "-2.JPEG"
    delay 1
    --print imp
    delay 2
    set efface to POSIX path of imp
    set efface1 to POSIX path of (chemin & nomcourt & ".JPEG")
    do shell script "rm " & efface
    do shell script "rm " & efface1
end tell
 
Dernière édition:
OK!
Ils ont du changer un truc dans le procès "image Events", et je ne peux pas vérifier le dictionnaire de l'application vu que je n'ai pas de M1 ni ventura !

Je tente un nouvel essai ...

Edit: j'y pense tu peux essayer d'autoriser "image Events" dans :
  • Accessibilité
  • Accès complet au disque
  • Automatisation
Cela se passe dans préférence système --> sécurité et confidentialité

Bloc de code:
tell application "Finder"
    set monfichier to choose file with prompt "Sélectionnez le fichier PDF à traiter"
    set nom to name of monfichier
    set AppleScript's text item delimiters to {"."} --récupère la partie avant le dernier "."
    set elements to text items of nom
    set nomcourt to (items 1 thru -2 of elements) as string
    set ancien_nom to nomcourt
    set chemin to the container of monfichier as alias
    set nouveau to nomcourt & ".JPEG"
end tell

tell application "Image Events"
    set uneimage to open monfichier
    save uneimage as "JPEG" in file nouveau of chemin
    close uneimage
end tell

tell application "Finder"
    set chemin to the container of monfichier as string
    set nouveau to nomcourt & ".JPEG"
end tell

set thePath to chemin & nouveau
set thePath to POSIX path of thePath

my padBottomOfImageAt:(thePath) byPoints:100

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

on padBottomOfImageAt:POSIXPath byPoints:padDepth
    -- build path for new file
    set anNSString to current application's NSString's stringWithString:POSIXPath
    set newPath to anNSString's stringByDeletingPathExtension()
    set theExt to anNSString's pathExtension() as text
    set newPath to (newPath's stringByAppendingString:"-2")'s stringByAppendingPathExtension:theExt
    -- load image as bitmap and get its size
    set oldRep to current application's NSBitmapImageRep's imageRepWithContentsOfFile:POSIXPath
    set {width:theWidth, height:theHeight} to oldRep's |size|()
    set newHeight to theHeight + padDepth
    -- make new bitmapImageRep
    set newRep to (current application's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:theWidth pixelsHigh:newHeight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(current application's NSCalibratedRGBColorSpace) bitmapFormat:(current application's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
    -- store the existing graphics context
    current application's NSGraphicsContext's saveGraphicsState()
    -- set graphics context to new context based on the new bitmapImageRep
    (current application's NSGraphicsContext's setCurrentContext:(current application's NSGraphicsContext's graphicsContextWithBitmapImageRep:newRep))
    -- set the color to black
    current application's NSColor's blackColor()'s |set|()
    -- fill the bottom area with black
    current application's NSRectFill({origin:{x:0, y:0}, |size|:{width:theWidth, height:padDepth}})
    -- draw from the original bitmapImageRep to the new one above the black area
 
    tell application "Finder"
        activate
        display dialog "Entrer la dimension a couper en bas (en milimètres)" default answer "27"
        set bas to text returned of result
        display dialog "Entrer la dimension a couper en haut (en milimètres)" default answer "0"
        set haut to text returned of result
        display dialog "Entrer la dimension a couper à gauche (en milimètres)" default answer "0"
        set gauche to text returned of result
        display dialog "Entrer la dimension a couper à droite (en milimètres)" default answer "114"
        set droite to text returned of result
        if theWidth < theHeight then
            set H to 210
            set V to 297
        else
            set H to 297
            set V to 210
        end if
    end tell
 
    set OX to theWidth / H * gauche
    set OY to theHeight / V * bas
    set SX to theWidth / H * (H - droite - gauche)
    set SY to theHeight / V * (V - haut - bas)
 
    oldRep's drawInRect:{origin:{x:0, y:padDepth}, |size|:{width:theWidth, height:theHeight}} fromRect:{origin:{x:OX, y:OY}, |size|:{width:(SX), height:(SY)}} operation:(current application's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
    -- restore graphics state
    current application's NSGraphicsContext's restoreGraphicsState()
    -- save bitmapImageRep as image
    if {"tif", "tiff"} contains {theExt} then
        set theData to (newRep's representationUsingType:(current application's NSTIFFFileType) |properties|:{NSTIFFCompression:(current application's NSTIFFCompressionLZW)})
    else if {"jpg", "jpeg"} contains {theExt} then
        set theData to (newRep's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:0.8, NSImageProgressive:true})
    else if theExt = "png" then
        set theData to (newRep's representationUsingType:(current application's NSPNGFileType) |properties|:{NSImageInterlaced:true})
    else -- unsupported type
        return false
    end if
    set theResult to (theData's writeToFile:newPath atomically:true)
    return (theResult as boolean)
end padBottomOfImageAt:byPoints:

tell application "Finder"
    set imp to chemin & nomcourt & "-2.JPEG"
    delay 1
    --print imp
    delay 2
    set efface to POSIX path of imp
    set efface1 to POSIX path of (chemin & nomcourt & ".JPEG")
    do shell script "rm " & efface
    do shell script "rm " & efface1
end tell
Dans "Automatisation", Image Events est bien coché.
Dans "Accès complet au disque" je ne peux rajouter que des .app alors j'ai autorisé Éditeur de script mais ça n'a rien donné hélas.
Il est également activé dans "Accessibilité".

J'ai essayé de sélectionner une image à la place du PDF mais j'ai le même message.
 
le nouveau script provoque toujours l’erreur?

Alors je n’ai plus rien à tester, reste Photoshop…
 
Je pense avoir trouver une solution !
Encore une question:
Après l'impression veux-tu conserver le fichier "croper " ou j'efface ce fichier ?
 
La solution
Tu ouvres Editeur de script, dans une nouvelle fenêtre tu fais un copier-coller de ce script.

Tu enregistres : menu—> fichier—> enregistrer sous et dans la fenêtre , dans format de fichier tu choisis —> Application tu enregistres cette application avec le nom de ton choix à un endroit à ta convenance.

Tu peux quitter.

Tu glisses ton fichier PDF à traiter sur l’ icone de cette nouvelle application
Lors de la première utilisation il va te demander d’autoriser cette application…
Le fichier imprimé sera dans le même dossier que le PDF et s'appelle : Nom_du_fichier-2.JPEG
Rappel les dimensions demandées sont à renseigner en millimètres …

Bloc de code:
on open monfichier
    tell application "Finder"
        set a to monfichier as string
        set monfichier to a as alias
        set nom to name of monfichier
        set AppleScript's text item delimiters to {"."} --récupère la partie avant le dernier "."
        set elements to text items of nom
        set nomcourt to (items 1 thru -2 of elements) as string
        set ancien_nom to nomcourt
        set chemin to the container of monfichier as string
        set nouveau to nomcourt & ".JPEG"
        set enrg to chemin & nouveau as string
        set chemin to the container of monfichier as string
        set nouveau to nomcourt & ".JPEG"
    end tell
    
    set enrg to quoted form of POSIX path of enrg
    set lefichier to quoted form of POSIX path of monfichier
    set commande to "sips -s format JPEG " & lefichier & " --out " & enrg
    do shell script "sips -s format JPEG " & lefichier & " --out " & enrg
    
    set thePath to chemin & nouveau
    set thePath to POSIX path of thePath
    
    my padBottomOfImageAt:(thePath) byPoints:100
    
    tell application "Finder"
        set imp to chemin & nomcourt & "-2.JPEG"
        delay 1
        print imp
        delay 2
        --set efface to quoted form of POSIX path of imp
        set efface1 to quoted form of POSIX path of (chemin & nomcourt & ".JPEG")
        --do shell script "rm " & efface
        do shell script "rm " & efface1
    end tell
    
end open
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

on padBottomOfImageAt:POSIXPath byPoints:padDepth
    -- build path for new file
    set anNSString to current application's NSString's stringWithString:POSIXPath
    set newPath to anNSString's stringByDeletingPathExtension()
    set theExt to anNSString's pathExtension() as text
    set newPath to (newPath's stringByAppendingString:"-2")'s stringByAppendingPathExtension:theExt
    -- load image as bitmap and get its size
    set oldRep to current application's NSBitmapImageRep's imageRepWithContentsOfFile:POSIXPath
    set {width:theWidth, height:theHeight} to oldRep's |size|()
    set newHeight to theHeight + padDepth
    -- make new bitmapImageRep
    set newRep to (current application's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:theWidth pixelsHigh:newHeight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(current application's NSCalibratedRGBColorSpace) bitmapFormat:(current application's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
    -- store the existing graphics context
    current application's NSGraphicsContext's saveGraphicsState()
    -- set graphics context to new context based on the new bitmapImageRep
    (current application's NSGraphicsContext's setCurrentContext:(current application's NSGraphicsContext's graphicsContextWithBitmapImageRep:newRep))
    -- set the color to black
    current application's NSColor's blackColor()'s |set|()
    -- fill the bottom area with black
    current application's NSRectFill({origin:{x:0, y:0}, |size|:{width:theWidth, height:padDepth}})
    -- draw from the original bitmapImageRep to the new one above the black area
    
    tell application "Finder"
        activate
        display dialog "Entrer la dimension a couper en bas (en milimètres)" default answer "27"
        set bas to text returned of result
        display dialog "Entrer la dimension a couper en haut (en milimètres)" default answer "0"
        set haut to text returned of result
        display dialog "Entrer la dimension a couper à gauche (en milimètres)" default answer "0"
        set gauche to text returned of result
        display dialog "Entrer la dimension a couper à droite (en milimètres)" default answer "114"
        set droite to text returned of result
        if theWidth < theHeight then
            set H to 210
            set V to 297
        else
            set H to 297
            set V to 210
        end if
    end tell
    
    set OX to theWidth / H * gauche
    set OY to theHeight / V * bas
    set SX to theWidth / H * (H - droite - gauche)
    set SY to theHeight / V * (V - haut - bas)
    
    oldRep's drawInRect:{origin:{x:0, y:padDepth}, |size|:{width:theWidth, height:theHeight}} fromRect:{origin:{x:OX, y:OY}, |size|:{width:(SX), height:(SY)}} operation:(current application's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
    -- restore graphics state
    current application's NSGraphicsContext's restoreGraphicsState()
    -- save bitmapImageRep as image
    if {"tif", "tiff"} contains {theExt} then
        set theData to (newRep's representationUsingType:(current application's NSTIFFFileType) |properties|:{NSTIFFCompression:(current application's NSTIFFCompressionLZW)})
    else if {"jpg", "jpeg"} contains {theExt} then
        set theData to (newRep's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:0.8, NSImageProgressive:true})
    else if theExt = "png" then
        set theData to (newRep's representationUsingType:(current application's NSPNGFileType) |properties|:{NSImageInterlaced:true})
    else -- unsupported type
        return false
    end if
    set theResult to (theData's writeToFile:newPath atomically:true)
    return (theResult as boolean)
end padBottomOfImageAt:byPoints:
 
Dernière édition:
Après l'impression oui je veux garder le format cropé, qu'il remplace l'original.

Alors j'ai crée le .app avec Editeur de script, et j'ai ce message.

Screenshot - 09-11-2022 à 21h38 22s - CleanShot - CleanShot.png

La résolution de mon fichier initial fait 595x420, j'ai essayé avec un png mais j'ai le même message.
 
Le message dit que ton Shell (terminal) ne supporte pas la commande « sips » avec le format tel que je l’ écrit .

Mon Shell est bash et date de Mojave , et chez moi tout fonctionne. Du coup je ne peux pas tester…
désolé !