convertPdfToSvg method
Converts a PDF file to SVG format using the pdf2svg command-line tool.
Parameters:
pdfPath: The path to the source PDF fileoutputDirectory: The directory to save the SVG file in
Requires the pdf2svg tool to be installed on the system. Throws an exception if the conversion fails or pdf2svg is not available.
Implementation
Future<void> convertPdfToSvg(String pdfPath, String outputDirectory) async {
try {
final pdfFileName = path.basenameWithoutExtension(pdfPath);
final svgPath = path.join(outputDirectory, '$pdfFileName.svg');
final result = await Process.run(
'pdf2svg',
[pdfPath, svgPath],
runInShell: true,
);
if (result.exitCode != 0) {
throw Exception('PDF to SVG conversion failed: ${result.stderr}');
}
} catch (e) {
throw Exception('Error converting PDF to SVG: $e');
}
}