Hierbij de code die ik nu gebruik. Er zit nog vanalles in wat ik niet gebruik zoals Bookmarks, ik moet hem later opschonen. Via Sent To wordt deze aangeroepen; ik kan 5 PDFs tegelijk omzetten (door slecht copy-paste werk). Kan iemand mij helpen een loopje erin bouwen zodat ik geen max van 5 heb, en daarnaast zorgen dat de nieuwe PDFs in een andere map komen? Ik ben bezig geweest met de "-o" parameter, maar ik krijg het niet voor elkaar de PDFs in een nieuwe map op te slaan.
@echo off
REM ===========================================================================================
REM pdfa.cmd
REM Copyright 2017 by MCB Systems.
REM Free for personal and commercial use. No warranties. May not be sold.
REM ===========================================================================================
REM
REM Summary:
REM Renames input files to .old.pdf, and puts output file in the same folder
REM as the input file(s). Optionally displays Bookmarks panel by default.
REM
REM Parameters:
REM %1: Mandatory. PDF file to convert. Will be used for output file name.
REM %2: Optional. PDF file to convert. Will be combined into one output.
REM %4: Optional. PDF file to convert. Will be combined into one output.
REM %4: Optional. PDF file to convert. Will be combined into one output.
REM %5: Optional. PDF file to convert. Will be combined into one output.
REM
REM Alternately, set the last parameter to "-sb" (show bookmarks) to load a file that
REM sets the Initial View of the PDF to show the Bookmarks (outline) panel. This is only
REM useful if the input file already has bookmarks, and does not really make sense when
REM concatenating multiple files, as bookmarks from later files would point to incorrect
REM page numbers.
REM
REM Dependencies:
REM gswin32c.exe - Ghostscript command-line program. Update the first
REM line below "set gs_path=", with the path where gswin32c.exe
REM is found.
REM C:\GS_PDFA\PDFA_def.ps - PDF/A conversion info. Includes additional dependency on
REM ICC color profile (e.g. C:\GS_PDFA\AdobeRGB1998.icc).
REM C:\GS_PDFA\PDF_ShowBookmarksPanel.ps - Command to cause bookmarks panel to be displayed.
REM
REM ===========================================================================================
REM Change Log:
REM
REM 04/15/2013 Initial batch file.
REM
REM 05/03/2013 Fix to support spaces in file names.
REM
REM 07/02/2014 Enhance to work from Explorer Send To context menu:
REM - Strip file extension from parameters if provided. Script assumes .pdf.
REM - Change to the directory of the first file before processing.
REM - Pause if file rename fails on file 1 so user can see error in command window.
REM
REM 01/02/2015 Handle ampersands in file names (e.g. "AT&T") by quoting set statements.
REM
REM 11/22/2016 After re-installing Windows 10, I installed Ghostscritp 9.20 instead of 9.07.
REM Update gs_path just below accordingly.
REM
REM 08/15/2017 Pause if rename fails on files 2-5 so user can see error in command window.
REM
REM ===========================================================================================
REM ===========================================================================================
REM Check for the Ghostscript executable
REM ===========================================================================================
REM Change the next line to the folder that contains gswin32c.exe. End the line with a backslash (\):
set gs_path=C:\Program Files (x86)\gs\gs9.21\bin\
REM On a 32-bit version of Windows, gswin32c.exe will probably be here:
REM set gs_path=C:\Program Files\gs\gs9.20\bin\
if not exist "%gs_path%gswin32c.exe" (
echo "%gs_path%gswin32c.exe" not found. Exiting.
goto End
)
REM ===========================================================================================
REM Check for parameters
REM ===========================================================================================
if ###%1###==###### goto NoParam
goto ParamsFound
:NoParam
echo.
echo Missing parameter(s)
echo.
echo Usage: pdfa file1 [file2^|-sb] [file3^|-sb] [file4^|-sb] [file5^|-sb]
echo.
echo You do NOT need to specify the .pdf extension on the input parameters.
echo.
echo To set the Initial View of the PDF to show the Bookmarks (outline) panel,
echo set the last parameter to "-sb" (show bookmarks). The input file must
echo already contain bookmarks. Not recommended when concatenating files.
echo.
echo Usage examples:
echo.
echo 1. If you have a credit card statement with two reconciliation
echo reports to attach, use the following command:
echo.
echo pdfa CCstatement recon1 recon2
echo.
echo Output:
echo CCstatement.pdf
echo CCstatement.old.pdf
echo recon1.old.pdf
echo recon2.old.pdf
echo.
echo 2. Convert a tax return that includes bookmarks:
echo.
echo pdfa "Tax Return" -sb
echo.
echo Output:
echo Tax Return.pdf
echo Tax Return.old.pdf
echo.
echo Delete the .old files if you are satisfied with the new PDF/A document.
echo.
goto End
:ParamsFound
REM Expand params and strip surrounding quotation marks, if any.
REM Also, strip extension, if any, and leave file name only. (.pdf will be assumed below.)
REM 01/02/2015 Handle ampersands in file names (e.g. "AT&T") by quoting set statements.
REM See
http://stackoverflow.com/a/14108765/550712. Did not have to use
REM "setlocal enableDelayedExpansion" or change references to use exclamation points.
set "file1=%~n1"
set "file2=%~n2"
set "file3=%~n3"
set "file4=%~n4"
set "file5=%~n5"
REM ===========================================================================================
REM Before renaming any files, check that all specified input files exist
REM ===========================================================================================
set ShowBookmarksPanel=N
REM Go to the path of the first file. Needed when called from Explorer Send To context menu.
set File1Drive=%~d1
set File1Path=%~p1
cd /d %File1Drive%\%File1Path%
REM First parameter always exists (checked above)
if not exist "%file1%.pdf" (
echo File #1 "%file1%.pdf" not found. Exiting.
REM When called from Explorer Send To, need a "pause" to see error
pause
goto End
)
REM If the next parameter doesn't exist, skip to renaming files.
if ###%2###==###### goto RenameFiles
REM If the next parameter is "-sb" (ShowBookmarks), skip to renaming files.
if "%file2%"=="-sb" goto ShowBookmarksAndRenameFiles
if not exist "%file2%.pdf" (
echo File #2 "%file2%.pdf" not found. Exiting.
pause
goto End
)
if ###%3###==###### goto RenameFiles
if "%file3%"=="-sb" goto ShowBookmarksAndRenameFiles
if not exist "%file3%.pdf" (
echo File #3 "%file3%.pdf" not found. Exiting.
pause
goto End
)
if ###%4###==###### goto RenameFiles
if "%file4%"=="-sb" goto ShowBookmarksAndRenameFiles
if not exist "%file4%.pdf" (
echo File #4 "%file4%.pdf" not found. Exiting.
pause
goto End
)
if ###%5###==###### goto RenameFiles
if "%file5%"=="-sb" goto ShowBookmarksAndRenameFiles
if not exist "%file5%.pdf" (
echo File #5 "%file5%.pdf" not found. Exiting.
pause
goto End
)
REM ===========================================================================================
REM Rename input file(s) to .old.pdf and build a list of input files.
REM Optionally set flag to show the Bookmarks panel
REM ===========================================================================================
:ShowBookmarksAndRenameFiles
set ShowBookmarksPanel=Y
:RenameFiles
REM First parameter always exists (checked above)
echo ren "%file1%.pdf" "%file1%.old.pdf"
ren "%file1%.pdf" "%file1%.old.pdf"
if errorlevel 1 goto RenameFailed
set inputfilelist="%file1%.old.pdf"
"%gs_path%\gswin32c" ^
-dPDFA ^
-dNOOUTERSAVE ^
-sProcessColorModel=DeviceRGB ^
-sDEVICE=pdfwrite ^
-o "%file1%.pdf" ^
-dPDFACompatibilityPolicy=1 ^
"C:\GS_PDFA\PDFA_def.ps" ^
%inputfilelist%
REM If the next parameter doesn't exist, skip to converting files.
if ###%2###==###### goto ConvertFiles
REM If the next parameter is "-sb" (ShowBookmarks), skip to converting files.
if "%file2%"=="-sb" goto ConvertFiles
echo ren "%file2%.pdf" "%file2%.old.pdf"
ren "%file2%.pdf" "%file2%.old.pdf"
if errorlevel 1 goto RenameFailed
set inputfilelist="%file2%.old.pdf"
"%gs_path%\gswin32c" ^
-dPDFA ^
-dNOOUTERSAVE ^
-sProcessColorModel=DeviceRGB ^
-sDEVICE=pdfwrite ^
-o "%file2%.pdf" ^
-dPDFACompatibilityPolicy=1 ^
"C:\GS_PDFA\PDFA_def.ps" ^
%inputfilelist%
REM If the next parameter doesn't exist, skip to converting files.
if ###%3###==###### goto ConvertFiles
REM If the next parameter is "-sb" (ShowBookmarks), skip to converting files.
if "%file3%"=="-sb" goto ConvertFiles
echo ren "%file3%.pdf" "%file3%.old.pdf"
ren "%file3%.pdf" "%file3%.old.pdf"
if errorlevel 1 goto RenameFailed
set inputfilelist="%file3%.old.pdf"
"%gs_path%\gswin32c" ^
-dPDFA ^
-dNOOUTERSAVE ^
-sProcessColorModel=DeviceRGB ^
-sDEVICE=pdfwrite ^
-o "%file3%.pdf" ^
-dPDFACompatibilityPolicy=1 ^
"C:\GS_PDFA\PDFA_
REM If the next parameter doesn't exist, skip to converting files.
if ###%4###==###### goto ConvertFiles
REM If the next parameter is "-sb" (ShowBookmarks), skip to converting files.
if "%file4%"=="-sb" goto ConvertFiles
echo ren "%file4%.pdf" "%file4%.old.pdf"
ren "%file4%.pdf" "%file4%.old.pdf"
if errorlevel 1 goto RenameFailed
set inputfilelist="%file4%.old.pdf"
"%gs_path%\gswin32c" ^
-dPDFA ^
-dNOOUTERSAVE ^
-sProcessColorModel=DeviceRGB ^
-sDEVICE=pdfwrite ^
-o "%file4%.pdf" ^
-dPDFACompatibilityPolicy=1 ^
"C:\GS_PDFA\PDFA_
REM If the next parameter doesn't exist, skip to converting files.
if ###%5##==###### goto ConvertFiles
REM If the next parameter is "-sb" (ShowBookmarks), skip to converting files.
if "%file5%"=="-sb" goto ConvertFiles
echo ren "%file5%.pdf" "%file5%.old.pdf"
ren "%file5%.pdf" "%file5%.old.pdf"
if errorlevel 1 goto RenameFailed
set inputfilelist="%file5%.old.pdf"
REM set outputfilepath=%C:\temp\%
"%gs_path%\gswin32c" ^
-dPDFA ^
-dNOOUTERSAVE ^
-sProcessColorModel=DeviceRGB ^
-sDEVICE=pdfwrite ^
-o "%file5%.pdf" ^
-dPDFACompatibilityPolicy=1 ^
"C:\GS_PDFA\PDFA_def.ps" ^
%inputfilelist%
REM ===========================================================================================
REM Convert input file(s) to PDF/A.
REM ===========================================================================================
:ConvertFiles
REM If the last parameter was "-sb" (ShowBookmarks), add the appropriate file to the file list
if %ShowBookmarksPanel%==Y (
set inputfilelist=%inputfilelist% "C:\GS_PDFA\PDF_ShowBookmarksPanel.ps"
)
REM Convert to PDF/A. Use name of first input file as name of output file.
REM ===========================================================================================
REM Open converted PDF/A file with the default PDF reader.
REM ===========================================================================================
REM The leading "title" (empty here) is necessary to get START to interpret parameters correctly
REM start "" /b "%file1%.pdf"
goto End
:RenameFailed
echo Exiting without converting because renaming an input file to .old failed.
REM Pause so user can see message (in case called from Explorer Send To context menu)
pause
:End
REM pause