When charts and diagrams inside a PDF are reused on the web, the usual approach is to render them to PNG first — a bitmap blurs when scaled up, and a different resolution means taking a new screenshot. Web illustrations, vector icons, and print layouts that need to scale to any size really call for SVG.
This article uses Spire.PDF for JavaScript to convert PDF to SVG. It loads and saves PDF documents in the browser on top of WebAssembly, and the whole conversion runs locally: files are read and written through a virtual file system (VFS), with no backend involved. Output has two forms — the whole document merged into one SVG, or one SVG per page.
This article covers two core features:
For installation and project configuration, refer to Integrate Spire.PDF for JavaScript in a React Project. The examples below assume Spire.PDF is already installed and the WebAssembly module is initialized.
Convert the Whole PDF to a Single SVG
Spire.PDF for JavaScript provides the PdfDocument.ConvertOptions.OutputToOneSvg property, which decides whether the whole document is written to one SVG or to one file per page. It defaults to false, so each page becomes its own file; set it to true and the pages are stacked vertically on a single canvas in their original order, then written out by SaveToFile with FileFormat.SVG.
The steps are as follows:
- Get the Spire.PDF WASM module and make sure it is ready.
- Load the sample PDF and the Arial font, create a
PdfDocumentobject, and load the file. - Set
PdfDocument.ConvertOptions.OutputToOneSvgtotrueso all pages go into one SVG. - Use the
PdfDocument.SaveToFile()method to save the result file. - Read the result file from the VFS and trigger a browser download.
The code to convert the whole PDF to a single SVG is as follows:
function App() {
const convertPdfToOneSvg = async () => {
// Get the Spire.PDF WASM module
const pdfModule = window.wasmModule?.spirepdf;
// Check if the module is ready
if (!pdfModule) {
alert('Spire.PDF is not ready yet');
return;
}
// Converting to SVG restores the page text, so put the Arial font into the VFS font directory first
await window.spire.FetchFileToVFS('ARIAL.TTF', '/Library/Fonts/', `${process.env.PUBLIC_URL}/font/`);
// Load the PDF to convert into the VFS
const inputFileName = 'Chapter_Document.pdf';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// Output file name: the whole document merged into one SVG
const outputFileName = 'Chapter_Document.svg';
// Load the PDF and send all pages into a single SVG
let doc = new pdfModule.PdfDocument();
doc.LoadFromFile(inputFileName);
doc.ConvertOptions.OutputToOneSvg = true;
doc.SaveToFile(outputFileName, pdfModule.FileFormat.SVG);
doc.Close();
// Read the generated file from the VFS and trigger download
const fileArray = window.dotnetRuntime.Module.FS.readFile(outputFileName);
const blob = new Blob([fileArray], { type: 'image/svg+xml' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = outputFileName;
a.click();
URL.revokeObjectURL(url);
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Convert PDF to SVG</h1>
<button onClick={convertPdfToOneSvg}>
Convert to a single SVG
</button>
</div>
);
}
export default App;
The result is a single SVG file with the five pages joined top to bottom:

Convert Each PDF Page to a Separate SVG
Spire.PDF for JavaScript also provides the PdfToSvgConverter class, which converts a document to SVG page by page. It is a second, equivalent entry point to PdfDocument, and SvgOptions carries OutputToOneSvg as well. This section keeps the default per-page output and downloads the files one by one.
The steps are as follows:
- Get the Spire.PDF WASM module and make sure it is ready.
- Load the sample PDF and the Arial font.
- Create a
PdfToSvgConverterobject, passing the path of the PDF to convert. - Use the
PdfToSvgConverter.Convert()method to convert page by page, one SVG per page. - Read each page's file from the VFS and trigger a download for each.
The code to convert each PDF page to a separate SVG is as follows:
function App() {
const convertPdfPagesToSvg = async () => {
// Get the Spire.PDF WASM module
const pdfModule = window.wasmModule?.spirepdf;
// Check if the module is ready
if (!pdfModule) {
alert('Spire.PDF is not ready yet');
return;
}
// Converting to SVG restores the page text, so put the Arial font into the VFS font directory first
await window.spire.FetchFileToVFS('ARIAL.TTF', '/Library/Fonts/', `${process.env.PUBLIC_URL}/font/`);
// Load the PDF to convert into the VFS
const inputFileName = 'Chapter_Document.pdf';
await window.spire.FetchFileToVFS(inputFileName, '', `${process.env.PUBLIC_URL}/data/`);
// Output file name prefix: pages are written as Chapter_Document_1.svg, Chapter_Document_2.svg, ...
const outputFileName = 'Chapter_Document.svg';
// Convert page by page with the converter
const converter = new pdfModule.PdfToSvgConverter(inputFileName);
converter.Convert(outputFileName);
// Read each page's file from the VFS and trigger a download for each
const fs = window.dotnetRuntime.Module.FS;
const prefix = outputFileName.replace(/\.svg$/i, '_');
const pageFiles = fs.readdir('/').filter((name) => name.startsWith(prefix) && name.endsWith('.svg'));
for (const pageFile of pageFiles) {
const blob = new Blob([fs.readFile(pageFile)], { type: 'image/svg+xml' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = pageFile;
a.click();
URL.revokeObjectURL(url);
}
};
return (
<div style={{ textAlign: 'center', height: '300px' }}>
<h1>Convert PDF to SVG</h1>
<button onClick={convertPdfPagesToSvg}>
Convert page by page
</button>
</div>
);
}
export default App;
Each page becomes its own SVG file, named with the page number:

Set the SVG Size
The converter also exposes the SvgOptions.ScaleX and ScaleY properties, which scale the output size by a factor; both default to 1. Setting them to 2 doubles the size. The SVG content is vector, so — unlike a bitmap — it stays sharp when scaled.
// Scale the output size up by 2x
const converter = new pdfModule.PdfToSvgConverter('Chapter_Document.pdf');
converter.SvgOptions.ScaleX = 2;
converter.SvgOptions.ScaleY = 2;
converter.Convert('Chapter_Document.svg');
Frequently Asked Questions
Why do I get a bunch of xxx_1.svg, xxx_2.svg files instead of one .svg
Cause: When PdfDocument.SaveToFile converts to SVG it writes page by page, and ConvertOptions.OutputToOneSvg defaults to false, so the file name becomes "prefix_page.svg". A single-page PDF hides the difference; with more pages it shows up.
Solution: To get a single file, turn the property on before saving:
doc.ConvertOptions.OutputToOneSvg = true;
doc.SaveToFile('Chapter_Document.svg', pdfModule.FileFormat.SVG);
With PdfToSvgConverter, the matching switch is converter.SvgOptions.OutputToOneSvg — the two entry points use an equivalent switch and produce identical output.
How do I fix the error Cannot found font(Arial) installed on the system.
Cause: Converting to SVG restores page text as <text> elements, and the converter looks the font up by name in /Library/Fonts/ of the virtual file system. If that directory is empty, it throws this error.
Solution: Put the font into the VFS before LoadFromFile:
await window.spire.FetchFileToVFS('ARIAL.TTF', '/Library/Fonts/', `${process.env.PUBLIC_URL}/font/`);
Arial and Arial Unicode MS are two different files; supplying only the latter still raises the same error.
Is the text in the converted SVG still selectable
Cause: <text> and stroked paths are different things. The converter keeps page text as <text> elements and turns only graphics and lines into vector paths (<path>), so the text stays selectable and searchable.
Solution: No extra settings. Open the generated SVG in an editor and you will see <text> nodes; zoom it in a browser and neither the text nor the lines blur.
What if I only want to convert a few pages
Cause: SaveToFile also has an overload that takes a page range, working on the same per-page files that are saved in the VFS.
Solution: Pass the start and end page indexes; the index is 0-based and inclusive:
// Write only pages 1 and 2, producing first_two_pages_1.svg and first_two_pages_2.svg
doc.SaveToFile('first_two_pages.svg', 0, 1, pdfModule.FileFormat.SVG);
Get a Free License
If you would like to remove the evaluation message from the result document or lift feature restrictions, please contact sales for a 30-day temporary license.