I'm attempting to use an AI Script for batch converting .pdf files into .svg format. While the code runs smoothly, I've encountered an issue: the size of the resulting .SVG files is significantly larger compared to the original PDFs. For instance, a PDF file of 152 KB balloons to around 3 MB after conversion using the batch script. I've attached the script here—could someone please help identify what might be causing this discrepancy?
#target illustrator
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
// Suppress the warning about reinterpreting PDF objects
app.preferences.setBooleanPreference("PDFInterpretationOptions.suppressReinterpretPDFWarning", true);
// Define the folder containing your PDF files
var folderPath = "C:/Drawings/PDF";
// Get a reference to the folder
var folder = new Folder(folderPath);
// Get an array of all PDF files in the folder
var files = folder.getFiles("*.pdf");
// Create a log file
var logFile = new File(folderPath + "/conversion_log.txt");
logFile.open("w");
// Loop through each file
for (var i = 0; i < files.length; i++) {
try {
// Open the current PDF file
var pdfDoc = app.open(files[i]);
// Define the SVG options
var svgSaveOpts = new ExportOptionsSVG();
svgSaveOpts.embedRasterImages = false;
svgSaveOpts.embedAllFonts = false;
svgSaveOpts.preserveEditability = false;
// Define the file to save
var svgFile = new File(files[i].parent + "/" + files[i].name.replace(".pdf", ".svg"));
// Export the PDF document as SVG
pdfDoc.exportFile(svgFile, ExportType.SVG, svgSaveOpts);
// Log successful conversion
logFile.writeln("Converted: " + files[i].name);
// Close the PDF document without saving changes
pdfDoc.close(SaveOptions.DONOTSAVECHANGES);
} catch (e) {
// Log error
logFile.writeln("Error converting " + files[i].name + ": " + e);
// Display error message
alert("Error converting " + files[i].name + ": " + e);
}
}
// Close the log file
logFile.close();