Here is the process I used. The main tool I used was Inkscape, which was able to easily convert text.
- used the actions of Adobe Acrobat Pro with JavaScript to split PDF sheets.
- run Inkscape Portable 0.48.5 from Windows Cmd to convert to SVG
- made some manual changes for a specific SVG XML attribute that I'm having problems with using Windows Cmd and Windows PowerShell
Single pages: Adobe Acrobat Pro with JavaScript
Using Adobe Acrobat Pro actions (formerly batch processing) creates a custom action for splitting PDF pages into separate files. In addition, you can share PDF files with GhostScript
Acrobat JavaScript action to split pages
var re = /.*\/|\.pdf$/ig; var filename = this.path.replace(re,""); { for ( var i = 0; i < this.numPages; i++ ) this.extractPages ({ nStart: i, nEnd: i, cPath : filename + "_s" + ("000000" + (i+1)).slice (-3) + ".pdf" }); };
Convert PDF to SVG: Inkscape Package with Windows CMD Commands
Using Windows Cmd, a batch file was created to cycle all PDF files in a folder and convert them to SVG
Batch file for converting PDF to SVG in current folder
:: ===== SETUP ===== @echo off CLS echo Starting SVG conversion... echo. :: setup working directory (if different) REM set "_work_dir=%~dp0" set "_work_dir=%CD%" :: setup counter set "count=1" :: setup file search and save string set "_work_x1=pdf" set "_work_x2=svg" set "_work_file_str=*.%_work_x1%" :: setup inkscape commands set "_inkscape_path=D:\InkscapePortable\App\Inkscape\" set "_inkscape_cmd=%_inkscape_path%inkscape.exe" :: ===== FIND FILES IN WORKING DIRECTORY ===== :: Output from DIR last element is single carriage return character. :: Carriage return characters are directly removed after percent expansion, :: but not with delayed expansion. pushd "%_work_dir%" FOR /f "tokens=*" %%A IN ('DIR /A:-D /O:N /B %_work_file_str%') DO ( CALL :subroutine "%%A" ) popd :: ===== CONVERT PDF TO SVG WITH INKSCAPE ===== :subroutine echo. IF NOT [%1]==[] ( echo %count%:%1 set /A count+=1 start "" /D "%_work_dir%" /W "%_inkscape_cmd%" --without-gui --file="%~n1.%_work_x1%" --export-dpi=300 --export-plain-svg="%~n1.%_work_x2%" ) ELSE ( echo End of output ) echo. GOTO :eof :: ===== INKSCAPE REFERENCE ===== :: print inkscape help REM "%_inkscape_cmd%" --help > "%~dp0\inkscape_help.txt" REM "%_inkscape_cmd%" --verb-list > "%~dp0\inkscape_verb_list.txt"
Cleanup Attributes: Windows Cmd and PowerShell
I understand that it is not recommended to manually iterate over the strength of SVG or XML tags or attributes due to possible changes, and instead use the XML parser. However, I had a simple problem where the stroke width in one drawing was very small, and on the other, the font family was not correctly identified, so I basically modified the previous version of the Windows Cmd script to do a simple search and replace. The only changes were in defining the search string and changing the invocation of the PowerShell command. The PowerShell command searches, replaces, and saves the modified file with the suffix added. I found some other links that could be better used for parsing or modifying the resulting SVG files if you need to do some other minor cleanup.
Manual modifications to find and replace SVG XML data
:: setup file search and save string set "_work_x1=svg" set "_work_x2=svg" set "_work_s2=_mod" set "_work_file_str=*.%_work_x1%"
powershell -Command "(Get-Content '%~n1.%_work_x1%') | ForEach-Object {$_ -replace 'stroke-width:0.06', 'stroke-width:1'} | ForEach-Object {$_ -replace 'font-family:Times Roman','font-family:Times New Roman'} | Set-Content '%~n1%_work_s2%.%_work_x2%'"
Hope this can help someone
References
Adobe Acrobat Pro actions and JavaScript links for individual pages
GhostScript links to individual pages
Inkscape command-line links for converting PDF to SVG
- convert pdf to svg
- Convert PDF to clean SVG?
Windows batch file cmd script links
XML Tag / Attribute Replacement Study
ClearBlueSky85 May 29 '15 at 20:18 2015-05-29 20:18
source share