Projects »

KiCad Web Viewer

Lightweight 17Kb Javascript library for embedding KiCad schematics and PCBs in web documentation, with zoom/pan & search

Documenting an electronics project includes the circuit schematics & PCB layout, but standard options either don’t allow zooming in and searching (static image), or PCB layers can’t be turned on/off (static image, PDF), or require having a large application installed just to view downloaded project files. KiCadWebView uses SVG export from the free electronics design tool KiCad to provide an easy option that integrates well with web documentation.

Features

Examples

The easiest option is to inline the PCB and schematic files into a web page:

Note that your web browser doesn’t support Javascript, or has Javascript disabled.
This page needs a browser with Javascript enabled in order to display KiCad SVGs.
LimitLimit#1#2MotorMotorPower8→28V/6AProgramming3.3V only-revBWiFi motors controllerwww.climbers.net+ADCGPIO13GPA5GPA6GPB6GPB5-+A4988uF#2MP1584#1FlshTXDRXDRstNCNCC3.0V out2B2A1A1B2B2A1A1BC-+A4988R8C1C6C7ESP-12FC4100R7R6R9R2R3R5R1R4C5C2C3No Copper8→28VMCP2301710KR8Motor #1100nF100nF1000uFLimit #1Motor #2Program10KR710KR610KR910KR210KR310KR510KR110KR4100nF100nF100nFLimit #2123456123456ABCDABCDDate: 2017-09-04KiCad E.D.A. kicad (5.1.6)-1Rev: BSize: A4Id: 1/1Title: WiFi-controlled stepper motors with ESP8266File: Motherboard.schSheet: /http://Climbers.netNikki SmithSee https://climbers.net/sbc/esp-wifi-stepper-motors-controller-revb/+3.3VJ1ADCJ3GPA6J4GPA5J5GPB6J6GPB5GNDR810KGNDJ2GPIO13R910K+3.3VR410KR610K~REST1ADC2CH_PD3GPIO164GPIO145GPIO126GPIO137VCC8GND9GPIO1510GPIO1020GPIO211MOSI21GPIO012SCLK22GPIO413GPIO514RXD15TXD16CS017MISO18GPIO919U2ESP-12FC71000uFC5100nFGNDC1100nFGPB01GPB12GPB23GPB34GPB45GPB56GPB67GPB78VCC9GND10INTA20GPA021SCL12GPA122SDA13GPA223GPA324A015GPA425A116GPA526A217GPA627~RESET18GPA728INTB19U4MCP23017+3.3V+3.3VGNDGNDGND+12VGNDR310KGNDC4100uF/50VR510KGNDC2100nFR710KGNDR110K1234P3Motor #1GNDGND+3.3V+12V+3.3VGND+12VVin+1Vin-2Vout+3Vout-4U1MP1584-modR210K+3.3VC6100nFC3100nF1234P4Program12P6Limit #2~ENABLEMS1MS2MS3~RESET~SLEEPSTEPDIRGNDVDD1B1A2A2BGNDVMOTU5A4988-mod #2~ENABLEMS1MS2MS3~RESET~SLEEPSTEPDIRGNDVDD1B1A2A2BGNDVMOTU3A4988-mod #112P2Limit #112P18→28V1234P5Motor #2GND+3.3V+3.3VTXDTXDRXDSTEP1FLASHRESETSTEP1STEP2FLASHRESETSTEP2RXD240mA1.5AR+C=159Hz filterR+C=159Hz filter~SLEEP10K pulldown overrides internal 100K pullup(power saving when ESP-12F is in deep sleep)~RESTHIGHLOWRESETfloatLOWGPIO15LOWLOWGPIO2HIGHHIGH35mAGPIO0HI 1.5LO 0.13.0AFLASHfloatLOWNormalProgramESP boot modes:One-off programming header3V3 I/O. Use pogo pins?3.1A170mA1.5A35mACNCCNC

However inlining means the (potentially large) SVG files are always loaded even if the user doesn’t look at them. Using static low-resolution thumbnails which link to the full SVGs gives much faster page loading:

How to use it

  1. Open your project PCB in KiCad’s Pcbnew
  2. Set each layer you want to a unique colour. eg. Edge.Cuts will merge with F.Fab if you keep them both as the Yellow 3 default
  3. Using File→Export→SVG... tick the layers you wish to include, and choose Board area only and All layers in a single file. Click Export to save as projectname-brd.svg
  4. Open your project schematic in KiCad’s Eeschema
  5. Using File→Plot... choose SVG for the Output Format, then click Plot Current Page to save as projectname.svg
  6. Compress the SVG files with the free Nano SVG Compressor. This outputs a format that the library can use, as well as making the files ~80% smaller so they load much faster
  7. Install the KiCadWebView.css and .js file on your site
  8. Add the SVG files to your web page with the following code:

page.html

<link rel='stylesheet' type='text/css' href='KiCadWebView.css' /> <script src='KiCadWebView.min.js'></script> <svg id="my_schematic" xmlns="http://www.w3.org/2000/svg" ... </svg> <svg id="my_pcb" xmlns="http://www.w3.org/2000/svg" ... </svg> <script> KiCadWebView.schematic('my_schematic'); KiCadWebView.pcb('my_pcb'); </script>

To use id= attributes you'll need to add them to the start of each SVG file, and the id must be be unique if you have multiple SVGs on the same page. Instead of passing the element id (string) you can optionally pass the element object itself, which can be useful for dynamic loading of SVG files or if no id is set:

var el = document.getElementsByTagName('svg')[0]; // first svg on page
KiCadWebView.pcb(el);

PCB layer names aren’t exported by KiCad, so the library guesses using the default KiCad names & colours. You can optionally pass a list of custom names & colours:

var custom_layers = {"Front Tracks":"rgb(132,0,0)", "Rear Tracks":"rgb(0,132,0)"};
KiCadWebView.pcb('my_pcb', custom_layers);

Using it with KiCad v6 or v7

This viewer was originally written for KiCad v5, and later versions of KiCad’s Pcbnew have bugs1 (schematic continues to work as normal):

For KiCad v7 don’t use File→Export→SVG... as this outputs SVGs that do not render correctly in web browsers. Instead use File→Plot in Pcbnew and select Plot format: SVG, Output mode: Color, Drill marks: Actual size, and tick the layers you'd like in Plot on All Layers. You only need to tick one option in Include Layers, and this will save a single SVG file when you click Plot.

KiCad v7 dialogue box

I don’t think there is a workaround for KiCad v6 users, but please let me know if you find one.
1Tested with KiCad v6.09 and v7.08

Keyboard shortcuts

The following KiCad-compatible shortcuts are supported:

F1Zoom in
Alt + F1Zoom in
F2Zoom out
Alt + F2Zoom out
F4Center the view on current mouse position
HomeReset to initial view
Shift + ArrowsPan left/right/up/down
Ctrl + FSearch for component reference/value
ReturnGo to next search result
EscapeClose search
FFlip board over (PCB)
Page UpShow top layers only (PCB)
Page DownShow bottom layers only (PCB)

Styling the results

You can easily customise the style to better fit with your web page/site. KiCadWebView uses the following CSS classes which you can extend or override with your own stylesheet:

.kicadwrapDIV tag that wraps the SVG, layers & search
.kicadpcbSVG tag used for displaying a PCB
.kicadschematicSVG tag used for displaying a schematic
.kicaduiUL tag for list of PCB layers
.kicadfindFORM with text box for providing search

By default the SVG is shown in a resizable DIV with aspect ratio 600:412 (width:height). You can optionally pass a different ratio as a number:

KiCadWebView.schematic('my_schematic', 600/480);
KiCadWebView.pcb('my_pcb', null, 600/480);

Download files

Zoom & pan functionality is provided by the SVGPanZoom library, which is bundled with KiCadWebView.js for faster loading.

Automated exports

You can partially automate the export process with a python script export-pcb.sh, included in the library zip archive above. eg, you could trigger it for a git commit. It uses the Pcbnew API to export an SVG with the standard layers/colours.

Unfortunately there isn’t a python API for KiCad schematics, so the best you can do is the hideous hack of emulating key presses to automate Eeschema in export-schematic.sh. This has only been tested on Windows and will need changes depending on your OS/desktop.

You still need to run the outputs through the Nano SVG compressor which doesn’t have an API (unless you pay for Nano Pro).

Future improvements


Fb Share this on Facebook
Nikki Smith, May 2021. Last updated October 2023