text
stringlengths
0
15.7k
source
stringlengths
6
112
set TargetFold to POSIX path of ((parent of LeFi) as text)
lns1.scpt
set sourceFolder to sourceFile's URLByDeletingLastPathComponent
lns1.scpt
set sourceFolder to sourceFolder's URLByAppendingPathComponent:FoldNam
lns1.scpt
set sourcePageCount to sourceDoc's pageCount()
lns1.scpt
set LaList to {}
lns1.scpt
repeat with i from 1 to sourcePageCount
lns1.scpt
set targetDoc to current application's PDFDocument's new()
lns1.scpt
set aPage to (sourceDoc's pageAtIndex:((i as integer) - 1))
lns1.scpt
if i is not 1 then -- page one is already croped
lns1.scpt
set {{aE, bE}, {cE, dE}} to (aPage's boundsForBox:(current application's kPDFDisplayBoxMediaBox))
lns1.scpt
set pageSize to {{Lex1, dE - Ley1 - Ley2}, {Lex2, Ley2}}
lns1.scpt
(aPage's setBounds:pageSize forBox:(current application's kPDFDisplayBoxCropBox))
lns1.scpt
(targetDoc's insertPage:aPage atIndex:0)
lns1.scpt
copy (Lex2 * 2.09) as integer to LaW
lns1.scpt
copy (Ley2 * 2.09) as integer to LaH
lns1.scpt
set targetFile to (sourceFolder's URLByAppendingPathComponent:("Page " & i & ".pdf"))
lns1.scpt
(targetDoc's writeToURL:targetFile)
lns1.scpt
do shell script "/usr/bin/sips --cropToHeightWidth " & LaH & " " & LaW & " --out '" & DestFold & "Page " & i & " (c).pdf' '" & DestFold & "Page " & i & ".pdf'"
lns1.scpt
set end of LaList to (DestFold & "Page " & i & " (c).pdf")
lns1.scpt
set merged_pdf to (NSString's stringWithString:(TargetFold & TargetNam & " (Trimed).pdf"))'s stringByStandardizingPath()
lns1.scpt
set outurl to NSURL's fileURLWithPath:(item 1 of LaList)
lns1.scpt
set outpdf to PDFDocument's alloc()'s initWithURL:outurl
lns1.scpt
set LaList to rest of LaList
lns1.scpt
set lastPage to outpdf's pageCount()
lns1.scpt
repeat with pdfdoc in LaList
lns1.scpt
set thisURL to (NSURL's fileURLWithPath:(pdfdoc as text))
lns1.scpt
set thisPDF to (PDFDocument's alloc()'s initWithURL:thisURL)
lns1.scpt
repeat with n from 1 to thisPDF's pageCount()
lns1.scpt
set this_page to (thisPDF's pageAtIndex:(n - 1)) -- Pdf pages are 0 based
lns1.scpt
(outpdf's insertPage:this_page atIndex:lastPage)
lns1.scpt
outpdf's writeToFile:merged_pdf
lns1.scpt
on errorAlert(dialogMessage)
lns1.scpt
display alert "Can't proceed:" message dialogMessage as critical
lns1.scpt
end errorAlert
lns1.scpt
property mm2pts : 2.83464566929
lns1.scpt
set theURL to current application's NSURL's fileURLWithPath:"/some/original file.pdf"
lns1.scpt
set destURL to current application's NSURL's fileURLWithPath:"/some/destination file.pdf"
lns1.scpt
set leftCrop to 10
lns1.scpt
set rightCrop to 20
lns1.scpt
set topCrop to 30
lns1.scpt
set bottomCrop to 40
lns1.scpt
set theDoc to current application's PDFDocument's alloc()'s initWithURL:theURL
lns1.scpt
set pageCount to (theDoc's pageCount())
lns1.scpt
repeat with iPage from 0 to pageCount - 1
lns1.scpt
set nextPage to (theDoc's pageAtIndex:iPage)
lns1.scpt
set {{p1, p2}, {p3, p4}} to (nextPage's boundsForBox:(current application's kPDFDisplayBoxMediaBox))
lns1.scpt
set leftCrop to (leftCrop * mm2pts)
lns1.scpt
set bottomCrop to (bottomCrop * mm2pts)
lns1.scpt
set rightCrop to p3 - (rightCrop * mm2pts) - leftCrop
lns1.scpt
set topCrop to p4 - (topCrop * mm2pts) - bottomCrop
lns1.scpt
(nextPage's setBounds:{{leftCrop, bottomCrop}, {rightCrop, topCrop}} forBox:(current application's kPDFDisplayBoxCropBox))
lns1.scpt
(theDoc's writeToURL:destURL)
lns1.scpt
set theRect to (nextPage's boundsForBox:(current application's kPDFDisplayBoxMediaBox))
lns1.scpt
set {{p1, p2}, {p3, p4}} to theRect as record
lns1.scpt
set theCrop to current application's NSMakeRect(leftCrop, bottomCrop, rightCrop, topCrop)
lns1.scpt
(nextPage's setBounds:theCrop forBox:(current application's kPDFDisplayBoxCropBox))
lns1.scpt
set pdfURL to current application's NSURL's fileURLWithPath:"some.pdf"
lns1.scpt
set theName to pdfURL's URLByDeletingPathExtension()'s lastPathComponent()
lns1.scpt
set destURL to pdfURL's URLByDeletingLastPathComponent()'s URLByAppendingPathComponent:("" & theName & " [crop].pdf")
lns1.scpt
set leftCrop to 10 + 7.4
lns1.scpt
set rightCrop to 20 + 7.4
lns1.scpt
set topCrop to 30 + 7.4
lns1.scpt
set bottomCrop to 40 + 7.4 + 10
lns1.scpt
set desiredRez to 72
lns1.scpt
set theDoc to current application's PDFDocument's alloc()'s initWithURL:pdfURL
lns1.scpt
set newDoc to current application's PDFDocument's alloc()'s init()
lns1.scpt
repeat with iPage from 1 to pageCount
lns1.scpt
set thePage to (theDoc's pageAtIndex:(iPage - 1))
lns1.scpt
set theData to (thePage's dataRepresentation())
lns1.scpt
set pdfImageRep to (current application's NSPDFImageRep's imageRepWithData:theData)
lns1.scpt
set {{aLeft, aTop}, {aWidth, aHeight}} to pdfImageRep's |bounds|()
lns1.scpt
set rightCrop to (rightCrop * mm2pts)
lns1.scpt
set topCrop to (topCrop * mm2pts)
lns1.scpt
set cropWidth to (aWidth - (leftCrop + rightCrop))
lns1.scpt
set cropHeight to (aHeight - (topCrop + bottomCrop))
lns1.scpt
set cropRect to {{0, 0}, {cropWidth, cropHeight}}
lns1.scpt
set resizing to (desiredRez / 72)
lns1.scpt
set newBitmap to (current application's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:cropWidth * resizing pixelsHigh:cropHeight * resizing bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(current application's NSCalibratedRGBColorSpace) bytesPerRow:0 bitsPerPixel:0)
lns1.scpt
current application's NSGraphicsContext's saveGraphicsState()
lns1.scpt
set theContext to (current application's NSGraphicsContext's graphicsContextWithBitmapImageRep:newBitmap)
lns1.scpt
(current application's NSGraphicsContext's setCurrentContext:theContext)
lns1.scpt
(theContext's setShouldAntialias:true)
lns1.scpt
(theContext's setImageInterpolation:(current application's NSImageInterpolationHigh))
lns1.scpt
(pdfImageRep's drawInRect:{{-leftCrop * resizing, -bottomCrop * resizing}, {aWidth * resizing, aHeight * resizing}} fromRect:(current application's NSZeroRect) operation:(current application's NSCompositeSourceOver) fraction:(1.0) respectFlipped:true hints:(missing value))
lns1.scpt
current application's NSGraphicsContext's restoreGraphicsState()
lns1.scpt
set theData to (newBitmap's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:0.8, NSImageProgressive:false})
lns1.scpt
set theImage to (current application's NSImage's alloc()'s initWithData:theData)
lns1.scpt
set theImageView to (current application's NSImageView's alloc()'s initWithFrame:cropRect)
lns1.scpt
(theImageView's setImage:theImage)
lns1.scpt
set theData to (theImageView's dataWithPDFInsideRect:cropRect)
lns1.scpt
set nextPage to ((current application's PDFDocument's alloc()'s initWithData:theData)'s pageAtIndex:0)
lns1.scpt
(newDoc's insertPage:nextPage atIndex:(iPage - 1))
lns1.scpt
(newDoc's writeToURL:destURL)
lns1.scpt
current application's NSWorkspace's sharedWorkspace()'s openURL:destURL
lns1.scpt
set LeFi to item 1 of sourceFiles
lns1.scpt
set pdfURL to current application's NSURL's fileURLWithPath:sourceFile
lns1.scpt
set desiredRez to 300
lns1.scpt
set {{leftCrop, bottomCrop}, {cropWidth, cropHeight}} to (thePage's boundsForBox:(current application's kPDFDisplayBoxCropBox))
lns1.scpt
(pdfImageRep's drawInRect:{{0, 0}, {cropWidth * resizing, cropHeight * resizing}} fromRect:(current application's NSZeroRect) operation:(current application's NSCompositeSourceOver) fraction:(1.0) respectFlipped:true hints:(missing value))
lns1.scpt
set theData to (newBitmap's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:0.25, NSImageProgressive:false})
lns1.scpt