1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| @echo off
ECHO pdf2megazine v1.0
ECHO.
IF [%1]==[] GOTO help
IF [%2]==[] GOTO help
IF [%3]==[] GOTO help
:: Get the page width and height for the header (because I do not know how to escape the
:: exclamation mark when ENABLEDELAYEDEXPANSION is active, and it's needed in the doctype)
SET WIDTH=275
IF NOT [%4]==[] SET WIDTH=%4
set height=400
IF NOT [%5]==[] SET HEIGHT=%5
:: Write XML header and lead in
ECHO ^<?xml version="1.0" encoding="utf-8"?^>> megazine.xml
ECHO ^<!DOCTYPE book SYSTEM "http://megazine.mightypirates.de/megazine.dtd"^>>> megazine.xml
ECHO ^<book pagewidth="%WIDTH%" pageheight="%HEIGHT%"^>>> megazine.xml
ECHO ^<chapter^>>> megazine.xml
:: Activate it, for modulo calculation in the loop
SETLOCAL ENABLEDELAYEDEXPANSION
:: --------------------------------------------------------------
:: The installation location of the swftools pdf to swf converter
:: CHANGE THIS TO WHERE YOUR INSTALLATION OF THE SWFTOOLS IS
SET PDF2SWF=pdf2swf.exe
:: --------------------------------------------------------------
:: Test if the swftools are installed...
IF NOT EXIST %PDF2SWF% GOTO swftools
:: Process path input and remove quotation marks
SET FROM=%1
SET FROM=%FROM:"=%
SET TO=%2
SET TO=%TO:"=%
SET PAGES=%3
SET WIDTH=275
IF NOT [%4]==[] SET WIDTH=%4
set height=400
IF NOT [%5]==[] SET HEIGHT=%5
ECHO Reading %PAGES% pages from file %FROM% and writing them to files named
ECHO %TO%1.swf through %TO%%PAGES%.swf...
:: Process all pages
FOR /L %%i IN (1,1,%pages%) DO (
ECHO Processing page %%i
%PDF2SWF% -q -t -T 8 -s zoom=100 -p %%i "%FROM%" "%TO%%%i.swf"
:: Check if it's an even or odd page and position the zoom button accordingly
SET TEST=%%i
SET /A TEST%%=2
IF "!TEST!"=="1" ECHO ^<page^>^<img src="%to%%%i.swf" width="%width%" height="%height%" hires="%to%%%i.swf" static="true" gallery="pages" iconpos="left"/^>^</page^>>> megazine.xml
IF "!TEST!"=="0" ECHO ^<page^>^<img src="%to%%%i.swf" width="%width%" height="%height%" hires="%to%%%i.swf" static="true" gallery="pages"/^>^</page^>>> megazine.xml
)
:: Write lead out to XML
ECHO ^</chapter^>>> megazine.xml
ECHO ^</book^>>> megazine.xml
ENDLOCAL
ECHO Done.
GOTO end
:swftools
ECHO [EN - English]
ECHO.
ECHO This script requires the "pdf2swf" program from swftools.
ECHO See http://www.swftools.org/pdf2swf.html
ECHO.
ECHO If you do not have them installed, please download now and install.
ECHO Then change this file (open it with Notepad), by setting where
ECHO you installed it (default is C:\swftools, if you did not use a
ECHO custom path you do not need to change this file).
ECHO Look for the line
ECHO.
ECHO SET PDF2SWF=P:\swftools\pdf2swf.exe
ECHO.
ECHO and change the path to your installation location.
ECHO.
GOTO end
:help
ECHO [EN - English]
ECHO.
ECHO How to use:
ECHO pdf2megazine.bat "path/to/source.pdf" "target/path/base_name" numberofpages
ECHO [pagewidth] [pageheight]
ECHO.
ECHO First parameter is the path to the source pdf file. Required parameter.
ECHO Second parameter is the base name of the resulting files. Page number and
ECHO extension is added automatically. Required parameter.
ECHO Third parameter is the number of pages to extract from the source pdf
ECHO document. Required parameter.
ECHO Fourth and fifth parameter are the target page width and height in pixels.
ECHO Optional parameters.
ECHO.
ECHO e.g.: pdf2megazine.bat "C:/MyPDF.pdf" "files/page" 12
ECHO.
ECHO This will produce 12 swf files in the folder <Folder with BAT>/files/ with the
ECHO names page1.swf through page12.pdf.
ECHO.
ECHO Also note that in the folder of the bat file an XML file is generated that
ECHO represents a book with the extracted pages. If you wish to use this XML file
ECHO (which is recommended) you should use relative path for the resulting files
ECHO that can be used in the XML file, because it is used directly for generation.
ECHO To achieve this, place the bat file into the folder with your megazine.swf file.
ECHO.
GOTO end
:end
pause |
Partager