Script to resize pdf-files by percentage

Dear all,
I have a rather simple problem: I need to resize a collection of several pdf files (around 60) by a certain percentage, because those files are included in a text (LaTex) - and I need to change the LaTex page style (in other words: the layout) - so that my old images are all a bit too large for the layout; thus I want to do a quick-and-dirty solution and resize them all by a certain percentage (defined by the difference between my old layout and the new, more slim one).
So - the simple question is: does anyone know either if there is simple free software out there that can do this (I didn't find any - and Acrobat 9 doesn't offer the possibility to change the dimensions of pdf images) - or, b) if this would be possible to do with Applescript? Off course, I wouldn't mind a ready-made script - but, since I don't know, but want to learn Applescript, I thought that this might be a good task to start with - although I also need a solution in 3 to 4 days - hope it wouldn't be a too frustrating task to start with...
Thanks for any hints!
With kind regards,
Björn
Message was edited by: bBcuda

Hello
You might try something like the following script.
It will a) resize the pdf image by using Image Events and save it as png and b) convert png to pdf by png2pdf.
You'd need to have png2pdf installed in advance.
(Image Events can open pdf but cannot save as pdf according to the document.)
The script will let you choose source folder where original pdfs reside and destination folder where modified pdfs are to be stored. Also it will let you specify scaling factor. After that it will open each pdf file (*.pdf) in source folder, resize and save as new png file in destination and then convert the png to pdf (and delete png if successful). Hopefully it's like that.
Script is NOT tested and I don't know how good (or bad) Image Events and png2pdf are, for I don't use OSX for myself. Sorry about that.
Good luck,
H
--SCRIPT (NOT TESTED)
Using Image Events and png2pdf
Image Events
http://www.apple.com/applescript/imageevents/
http://www.apple.com/applescript/imageevents/04.html
http://www.apple.com/applescript/imageevents/08.html
png2pdf
http://png2pdf.sourceforge.net/
http://png2pdf.sourceforge.net/png2pdf.pdf
main()
on main()
script o
property scaling_factor : 0.8 -- default scaling factor
property remove_png : true -- whether remove intermediate png files or not
property nn : {} -- working list
--(0) preparation
-- (0.1) set input and output directories (= ind, indp, outd, outdp)
set ind to choose folder with prompt "Choose source folder."
set outd to choose folder with prompt "Choose destination folder."
set indp to ind as Unicode text
set outdp to outd as Unicode text
-- (0.2) set scaling factor (= r)
set r0 to scaling_factor as string -- default scaling factor as string
repeat
display dialog "Enter scaling factor." default answer r0 with icon 1
try
set r to text returned of result as real
exit repeat
on error --
end try
end repeat
-- (1) process each pdf file in input directory
set nn to list folder ind without invisibles -- get item names
repeat with n in my nn
set n to n's contents
if n ends with ".pdf" then -- only process "*.pdf"
-- (1.1) open pdf, resize and save it as new png file
set infp to indp & n
set outfp to outdp & n's text 1 thru -4 & "png" -- set output path
tell application "Image Events"
set p to open (infp as alias)
scale p by factor r
save p as PNG in file outfp
close p
end tell
-- (1.2) convert png to pdf (and optionally remove png if successful)
set infpx to quoted form of POSIX path of (outfp as alias)
set outfpx to quoted form of ((POSIX path of outd) & n)
if remove_png then
do shell script ("png2pdf -p1.4 -n -a " & infpx & " " & outfpx & " && rm -f " & infpx)
else
do shell script ("png2pdf -p1.4 -n -a " & infpx & " " & outfpx)
end if
end if
end repeat
-- (2) decent notice
display dialog "Done." with icon 1 giving up after 5
end script
tell o to run
end main
--END OF SCRIPT
Message was edited by: Hiroto (fixed typo)

Similar Messages

  • Can adobe acrobat XI pro resize pdf files?

    Looking for a software program that allows you to resize pdf files.  Can Acrobat XI Pro do this?

    There may be a preflight script for what you want. The other way is not generally recommended based on the loss of markup and the modification of graphic resolution and such, but you can print the PDF to a new size with shrink to fit selected. As I said, it is not recommended, but might meet your need. You can also do some adjustment with the crop tool, but it depends on what your goal is.
    If you are talking about the file size, that is a different issue and the Save As Other > Reduce File Size or Optimize PDF are the typical approaches.

  • How to download the script data into pdf file

    how to download the script data into pdf file
    i have one option to download the script data to pdf file --->rstxpdft4 program.
    i have one doubt how to use this proogram.or any function module to download the script data to pdf file.
    Thanks and regards,
    Sri.

    Hi      Sri Sai,
    I know one method to convert the sapscript to pdf file :
    first generate a Spool Request for the required Sapscript
    then goto transaction SP01 and copy the generated Spool Request number
    now execute the SAP report RSTXPDFT4
    here enter the copied Spool request number and the target directory into the parameters
    execute the report
    required pdf file will be generated into the target directory
    i hope it will help you out
    Please refer this simple program:
    http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
    Reward points if found helpful....
    Cheers,
    Eshwar.

  • How can I perform the conversion of pdf files in Cyrillic script to Word files in Cyrillic script. The pdf file is too small for me to read right now. Julyan Watts

    How can I perform the conversion of .pdf files in Cyrillic script to Word files in Cyrillic script. The .pdf file is too small for me to read without a magnifying glass, and the document is more than one thousand pages.

    This answer was not helpful. First of all, I could not find "tech specs"
    anywhere on the Acrobat 11 homepage. And secondly I purchased this software
    for the specific purpose of converting .pdf files to Word. It was only
    after I had completed the purchase that I learnt that Acrobat does not
    permit the conversion of .pdf files in Cyrillic to Word files  in Cyrillic.
    I feel that Acrobat should have provided this crucial information before I
    allowed my credit card to be debited. That is why I  am now asking for my
    money back. But thanks for your attempt to solve my problem, even if it was
    not successful.
    Julyan Watts

  • Script for Place PDF file into a InDesign file

    Hi everyone, i need to import a PDF file into a InDesign document and in order to do this i used scripts found over  the net (e.g. Zanelli's script ecc.) but i tried this solution:
    function(){
        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
        var myDocument, myPage;
        if(app.documents.length != 0){
            myDocument = app.activeDocument;
        else{
            alert("No document opened");
            exit();
         if (app.selection[0] == undefined) {
            alert("Select box");
            exit();
         } else {
                var myPDFFile = File.openDialog("Select PDF:");
                if((myPDFFile != "")&&(myPDFFile != null)){
                    myDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
                    myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
                    myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;   
                    var myData = new Array;
                    myData[0] = app.selection[0].parentPage;
                    myData[1] = app.selection[0].geometricBounds;
                    myData[2] = app.selection[0];
                    myPlacePDF(myDocument, myData, myPDFFile);
        //FUNCTIONS
        function myPlacePDF(myDocument, myData, myPDFFile){
            var myPDFPage;
            var myPage = myData[0];
            var myGeometricBounds = myData[1].toString().split(",");
            app.pdfPlacePreferences.pdfCrop = PDFCrop.cropMedia;
            var myCounter = 1;
            var myBreak = false;
            while(myBreak == false){
                if(myCounter > 1){
                    myPage = myDocument.pages.add(LocationOptions.after, myPage);
                 app.pdfPlacePreferences.pageNumber = myCounter;
                 myRectangle = myPage.rectangles.add(undefined, undefined, undefined, {geometricBounds:[myGeometricBounds[0],myGeometricBounds[1],myGeometricBounds[2],myGeometricBounds[3]]});
                 myRectangle.clearFrameFittingOptions();  
                 myRectangle.frameFittingOptions.fittingOnEmptyFrame = EmptyFrameFittingOptions.PROPORTIONALLY;
                 myRectangle.frameFittingOptions.autoFit = true;
                 myRectangle.frameFittingOptions.fittingAlignment = AnchorPoint.CENTER_ANCHOR;
                 myPDFPage = myRectangle.place(File(myPDFFile), false)[0];           
                 if(myCounter == 1){
                    var myFirstPage = myPDFPage.pdfAttributes.pageNumber;
                else{
                    if(myPDFPage.pdfAttributes.pageNumber == myFirstPage){
                        myPage.remove();
                        myBreak = true;
                myCounter = myCounter + 1;
             myData[2].remove();  
    what i would is, before the script place every single page of PDF file in the document, determine if the same page of the Pdf file is vertical or horizontal, to make the right section for the page.
    Is it possible?
    Thank you

    Moved to scripting forum...

  • Script to Split PDF files on Bookmarks

    I'm totally new to Java scripting.  What I'm looking for is a script I can run from batch processing with professional that will look at a collection files in s directory and split ech one of them on their bookmarks into smaller files.
    The bookmarks are all based on the page so it is possible to use the bookmark object's "execute" method to execute the bookmark action and pickup the page number.
    I read that last part somewhere. If someone can give me a reference to a thread or just some code to get me started that would help. Thanks,
    Josh

    5 years later... hopefully this helps someone out there.
    I couldn't find much information online about this myself, but hammered away until it worked. My code is for a slightly different purpose, but you should easily be able to adjust it for your needs.
    My sources:
    Adobe IAC Developer Guide
    Adobe IAC API Reference
    Adobe JS API Reference
    Adobe Acrobat and VBA – An Introduction | Karl Heinz Kremer's Ramblings
    UtterAccess Discussion Forums > Splitting Pdf Files
    Private Sub extractBookmark()
    Dim AcroApp As AcroApp, AVDoc As AcroAVDoc, PDDoc As AcroPDDoc, PDBookmark As AcroPDBookmark, AVPageView As AcroAVPageView
    Dim newPDF As AcroPDDoc, mergePDF As AcroPDDoc
    Dim jso As Object, BookMarkRoot As Object
    Dim masterPath As String, testName As String, i As Variant, bookmark As Variant
    Dim startN As Integer, endN As Integer, nPages As Integer, totalP As Integer
    Set AcroApp = CreateObject("AcroExch.App")
    Set AVDoc = CreateObject("AcroExch.AVDoc")
    Set PDDoc = CreateObject("AcroExch.PDDoc")
    Set PDBookmark = CreateObject("AcroExch.PDBookmark")
    masterPath = ActiveWorkbook.Path & "\MasterDocument.pdf"     'Path of the PDF containing the bookmarks to be extracted
    AVDoc.Open masterPath, vbNull
    Set AVPageView = AVDoc.GetAVPageView
    Set PDDoc = AVDoc.GetPDDoc
    Set jso = PDDoc.GetJSObject
    Set BookMarkRoot = jso.BookMarkRoot
    bookmark = jso.BookMarkRoot.Children
    totalP = PDDoc.GetNumPages
    'Loop through the 10 bookmarks in MasterDocument.pdf and get the starting page # of each. This # has to be changed to the # of bookmarks in your pdf. Or write something to count the bookmarks and use that variable. "productName" is a global variable for my specific project... You'll need to revise this for your purpose.
    For i = 0 To 9
        If bookmark(i).Name = productName Then
            PDBookmark.GetByTitle PDDoc, bookmark(i).Name
            PDBookmark.Perform AVDoc
            AcroApp.Exit
            startN = AVPageView.GetPageNum
            If i < 9 Then
                PDBookmark.GetByTitle PDDoc, bookmark(i + 1).Name
                PDBookmark.Perform AVDoc
                AcroApp.Exit
                endN = AVPageView.GetPageNum
                nPages = endN - startN
            Else
                nPages = totalP - startN
            End If
        End If
    Next
    PDDoc.Close
    'This part will also need to be modified. I am inserting the bookmarks into an already made PDF (global variable for me "fName"). You'll want to create a new pdf.
    Set newPDF = CreateObject("AcroExch.PDDoc")
    Set mergePDF = CreateObject("AcroExch.PDDoc")
    newPDF.Open fName & ".pdf"     'This line needs changing for your purpose. Probably could be.... newPDF.Create
    mergePDF.Open masterPath
    newPDF.InsertPages 0, mergePDF, startN, nPages, 0
    newPDF.Save PDSaveFull, fName & ".pdf"
    newPDF.Close
    mergePDF.Close
    End Sub

  • Script for Portfolio PDF files

    Hi,
    I have a portfolio with several PDF XFA forms inside.
    I want to set up a button so that when the user clicks it the PDF will
    open in a new window (outside of the portfolio); Need help here!
    lock some of the fields; Have this done with .access = "protected";
    save the PDF locally; Done using app.execMenuItem("SaveAs")
    I am having difficulty in scripting a solution like the standard button at the top right of the portfolio window: "Open .pdf file in a new window"
    Any ideas?
    Thanks,
    Niall

    This forum is for scripting questions rather than script requests.
    Please start by reading the following:
    Posting guidelines
    Handy tips for posting to this forum
    How to ask questions in a technical forum
    Rubber duck problem solving
    How to write a bad forum post
    Help Vampires: A Spotter's Guide
    -- Bill Stewart [Bill_Stewart]

  • Powershell Script to list pdf files in a directory

    Hey Scripting guy, I read few of your forum solutions for the scripts and was really enthralled to embrace this powershell scripting, thanks for the motivation.
    I am still a learner and want to learn more, I had to do a script on generating an excel report which consisted of number of files of files in PDF format for each directory and sub-directory in the path.
    I used the,
    get-childitem $Path -recurse | where {$_.Extension -match "pdf"}
    command, all I wanted to know is how to count the number of PDF files in each sub directory, please help me out,
    Thanks in advance

    Ok, let's have some fun :)
    function Count-FilesRecursive{
    Param(
    [parameter(Mandatory = $true, Position = 0)]
    [string]$Path,
    [parameter(Mandatory = $true, Position = 1)]
    [string]$Filter
    $SB_recursive = {
    [System.IO.Directory]::GetDirectories($args[0])|ForEach-Object {
    Try{
    $i = ([System.IO.Directory]::GetFiles($_,$Filter)).Count
    Catch [UnauthorizedAccessException] {
    $i = 0
    "{0,-10} {1}" -f $i, $_
    Try{
    $SB_recursive.Invoke($_)
    Catch [UnauthorizedAccessException] {}
    "{0,-10} {1}" -f "Number of files", "Path"
    "{0,-10} {1}" -f "---------------", "----"
    $SB_recursive.Invoke($Path)
    Count-FilesRecursive -Path C:\users -Filter '*.pdf'

  • Batch script to print PDF files to press quality

    Hello, I'm looking for a way to print PDF files to the Adobe PDF driver with "Press Quality" setting.   Ideally I could also save any file attachments first and then reattach them after printing to new files.
    I've been experimenting with the batch sequence feature but I am not getting very far.   Are there any sample scripts that do something similar to this?   I appreciate any guidance you can offer.
    Thanks
    LLL

    No, I do not have access to the original files that went into making the source PDFs.
    I've looked at PDF Optimizer but it does not shrink the file size nearly as much as printing the file through the Adobe PDF print driver with "Press Quality" setting.   I suspect this has to do with font consolidation.   PDF Optimizer seems to let you unembed fonts from the file but that's not what I'm looking for.  I need to have all fonts embedded.
    I appreciate the feedback.  Anyone else have ideas here on the original issue?  Thanks.

  • How to send a  Script as a PDF file to an mail with out saving in local PC

    HI Gurus,
    I Know it for locla PC. i HAve  converted the spool to pdf using CONVERT_ABAPSPOOLJOB_2_PDF and mailed using 'SO_DOCUMENT_SEND_API1'.
    Give me teh alternative.
    like storing in app server

    HI Gurus,
    I Know it for locla PC. i HAve  converted the spool to pdf using CONVERT_ABAPSPOOLJOB_2_PDF and mailed using 'SO_DOCUMENT_SEND_API1'.
    Give me teh alternative.
    like storing in app server

  • Resize Adobe pdf files

    hi,
    i am looking for an Adobe product to mass resize pdf file. Which product is able to do so. Your help is appreciated.
    thanks

    1. yes its resaved as within adobe reader and apparently by doing this its reduce the size from ~40mb to 4 - 5mb
    2. if its something that can be installed on the server 2k8 r2 64x will be fine or an application that will be pointed to that location to run as a batch for all the pdf files. let me know
    thanks

  • How can I auto export a PDF File using the "Smallest File Size" preset and set the Exported File Name based on information from an Imported PDF?

    Greetings all,
    I am trying to create a script to automate a PDF export process for my company for inDesign. I’m fairly new to inDesign itself and have no previous experience with javascript, although I did take C++ in high school and have found it helpful in putting this code together.
    We have an inDesign template file and then use the Multi-page PDF importer script to import PDF files. We then have to export two version of each file that we import, then delete the imported file and all of the pages to reset the template. This has to be done for nearly 1000 pdf files each month and is quite tedious. I’m working on automating the process as much as possible. I’ve managed to piece together code that will cleanup the file much quicker and am now trying to automate the PDF exports themselves.
    The files are sent to us as “TRUGLY#####_Client” and need to be exported as “POP#####_Client_Date-Range_North/South.pdf”
    For example, TRUGLY12345_Client needs to be exported as POP12345_Client_Mar01-Mar31_North and POP12345_Client_Mar01-Mar31_South.
    There are two templates built into the template file for the north and south file that are toggled easily via layer visibility switches. I need to get a code that can ideally read the #s from the imported Trugly file as well as the Client and input those into variables to use when exporting. The date range is found in the same place in the top right of each pdf file. I am not sure if this can be read somehow or if it will have to be input manually. I can put North or South into the file name based on which template layer is visible.
    I am not sure how to go about doing this. I did find the following code for exporting to PDF with preset but it requires me to select a preset and then type the full file name. How can I set it to automatically use the “Smallest File Size” preset without prompting me to choose and then automatically input some or preferably all of the file name automatically? (If the entire filename is possible then I don’t even want a prompt to appear so it will be fully automated!)
    PDF Export Code (Originally from here: Simple PDF Export with Preset selection | IndiSnip [InDesign® Snippets]):
    var myPresets = app.pdfExportPresets.everyItem().name;
    myPresets.unshift("- Select Preset -");
    var myWin = new Window('dialog', 'PDF Export Presets');
    myWin.orientation = 'row';
    with(myWin){
        myWin.sText = add('statictext', undefined, 'Select PDF Export preset:');
        myWin.myPDFExport = add('dropdownlist',undefined,undefined,{items:myPresets});
        myWin.myPDFExport.selection = 0;
        myWin.btnOK = add('button', undefined, 'OK');
    myWin.center();
    var myWindow = myWin.show();
    if(myWindow == true && myWin.myPDFExport.selection.index != 0){
        var myPreset = app.pdfExportPresets.item(String(myWin.myPDFExport.selection));
        myFile = File(File.saveDialog("Save file with preset: " + myPreset.name,"PDF files: *.pdf"));
        if(myFile != null){
            app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFile, false, myPreset);
        }else{
            alert("No File selected");
    }else{
        alert("No PDF Preset selected");
    So far my code does the following:
    1) Runs the Multi-Page PDF Import Script
    2) Runs PDF Export Script Above
    3) Toggles the Template
    4) Runs #2 Again
    5) Deletes the imported PDF and all pages and toggles template again.
    It’s close and much better than the original process which was almost 100% manual but I’d like to remove the Preset prompt from the PDF script and have it automatically select the “Smallest File Size” preset. and then if there’s a way to have it auto-fill in the file name so no user input is required at all other than selecting each file to import. (If there’s a way to setup a batch action for the multi-import script that would be even better!)
    Thanks in advance and if there’s anything else I can provide that would help please let me know! Even a nudge in the right direction will be a big help!

    If you hold down the option key, it will typically show the location. Or you can often hit option-return on the file and it will reveal the file in the Finder, instead of opening it.
    Final option is to open it, and just option-click the filename in the toolbar of Preview and it should show you the location.
    It's probably an attachment to an email you've received. If you have Mail set to cache emails and their attachments it'll be stashed in a subdirectory of ~/Library/Mail. Which is fine.

  • Barcodes not correctly reflecting in PDF file

    Hi All,
    The requirement is we need to convert the service order in to PDF file and send through mail.
    In this process under print control,Iam having customized sap script(in which Logo and Barcode for order number is included).
    When I try to convert the Sap Script in to PDF file using standard sap program,its not reflecting the BARCODE correctly.We tried with SMART form to PDF and in this option also BARCODE is not converted correctly.
    Anybody came across like this scenario and if so pl share.
    Sureshbabu Arunachalam

    Problem with converting SAPScript barcode (or barcode developed in Old Technology in Smartform) is conversion to PDF..
    Barcode in such cases are not send as images but rather print controls.
    This can be rectified by using Smartform and use barcode in new Technology. In this case barcode is send to PDF as image while PDF conversion.
    Bar codes can also now be correctly reproduced with the PDF conversion of Smart Forms documents. Previously, a bar code was only simulated in PDF documents by the output of a black-and-white rectangle.
    Please refer following link for more details -
    http://help.sap.com/erp2005_ehp_03/helpdata/EN/66/1b45c136639542a83663072a74a21c/frameset.htm
    Regards,
    Mohaiyuddin

  • Javascript to open PDF files

    Hi,
    I am trying to open 2 PDFs in Photoshop using Applescript, but there is a huge delay before PS even attempts to open/rasterise the files.
    Beyond "open thisItem as PDF with options..." i don't know what I could do differently.
    A solution would be to use javascript. I have found a number of scripts to open PDF files and then do stuff with them, but they all rely on a folder as an input for batch processing. I have done a lot of Applescripting, but no Javascript, so I am not sure how to pass 2 filepaths to the javascript. Can anyone enlighten me?
    I have tried using the javascript from ScriptListener, but even though I change the resolution to 200, it is still opening at 300. Is this a bug, or am I missing another piece of code?
    I would be grateful for any ideas.
    Ian

    There is not normally a delay when I open the PDF usually. When the script is run, there is a delay of at least 1-2 minutes before you see Photoshop display a progress bar.
    The PDFs have been converted to process, so contain no overprints, and in many cases are mostly rasterised already. They can be quite large but open up quickly in normal conditions.
    This is a simplified version of the code:
    on open (addeditems)
    tell application "Adobe Photoshop CS3"
    repeat with thisItem in addeditems
    open thisItem as PDF with options {class:PDF open options, resolution:200}
    --do stuff
    end repeat
    end tell
    end open
    Thanks
    Ian

  • Need to learn how I can re size a big pdf file in a Mac Book air

    Need to learn how resize pdf file in a Mac Book Air

    Oh, it's certainly possible, I just don't recommend you do it.
    If you really want to do it, go to Tools - Pages - Split Document and proceed from there.

Maybe you are looking for