Created
January 2, 2024 23:52
-
-
Save slaviboy/1f0195e5b54489c6b9477449c1de5928 to your computer and use it in GitHub Desktop.
Convert 'pdf' files into 'drawables'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set the directory path | |
$parentDirectory = "C:\Users\Slaviboy\Desktop\Images.xcassets\Flags" | |
# Get a list of all directories inside the parent directory | |
$directories = Get-ChildItem -Path $parentDirectory -Directory | |
# Loop through each directory | |
foreach ($directory in $directories) { | |
# Display the current directory being processed | |
Write-Host "Processing directory: $($directory.FullName)" | |
# Get a list of PDF files inside the current directory | |
$pdfFiles = Get-ChildItem -Path $directory.FullName -Filter *.pdf | |
# Loop through each PDF file and convert it to SVG | |
foreach ($pdfFile in $pdfFiles) { | |
# Extract the name from the first part of the directory before the dot | |
$directoryName = $directory.Name -split '\.' | Select-Object -First 1 | |
$outputName = "ic_$directoryName.svg" | |
# Create the output directory in the parent directory | |
$outputDirectory = Join-Path -Path $directory.Parent.FullName -ChildPath "output" | |
if (-not (Test-Path -Path $outputDirectory)) { | |
New-Item -ItemType Directory -Path $outputDirectory | Out-Null | |
} | |
# Construct the output SVG file path | |
$svgFile = Join-Path -Path $outputDirectory -ChildPath $outputName | |
# Display the conversion information | |
Write-Host "Converting $($pdfFile.FullName) to $($svgFile)" | |
# Execute the pdf2svg command | |
& C:\Users\Slaviboy\Desktop\pdf2svg-windows-master\dist-64bits\pdf2svg.exe $pdfFile.FullName $svgFile | |
} | |
# Display a separator for better readability | |
Write-Host "`n------------------------`n" | |
} | |
Write-Host "Script execution complete." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) Download repo: | |
> https://github.com/jalios/pdf2svg-windows | |
2) Make sure to place the pdf flags in dir: | |
> "C:\Users\Slaviboy\Desktop\Images.xcassets\Flags" | |
3) Run PowerShell command: | |
> convert_pdf_to_svg.ps1 | |
4) All flags will be converted into svg files, inside the "..\Flags\output\" directory | |
5) Convert SVG into drawables at once, using Android Studio: | |
> Tools → Resource Manager | |
> Select the Drawable tab | |
> Click the (+) button in the top left corner | |
> Select Import Drawables | |
6) Reformat all xml files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment