save method

Saves the current state of this Graphics and identifies the saved state with a GraphicsState.

//Creates a new PDF document.
PdfDocument doc = PdfDocument();
//Create PDF graphics for the page
PdfGraphics graphics = doc.pages.add().graphics;
//Save the graphics.
PdfGraphicsState state = graphics.save();
//Set graphics translate transform.
graphics
  ..translateTransform(100, 100)
  ..drawString('Hello world!', PdfStandardFont(PdfFontFamily.helvetica, 12),
      brush: PdfBrushes.red)
  //Restore the graphics.
  ..restore(state);
//Saves the document.
List<int> bytes = doc.save();
//Dispose the document.
doc.dispose();

Implementation

PdfGraphicsState save() {
  final PdfGraphicsState state = PdfGraphicsState._(this, _helper.matrix);
  state._brush = _helper._currentBrush;
  state._pen = _helper._currentPen;
  state._font = _helper._currentFont;
  state._colorSpace = colorSpace;
  state._characterSpacing = _previousCharacterSpacing!;
  state._wordSpacing = _previousWordSpacing!;
  state._textScaling = _helper._previousTextScaling!;
  state._textRenderingMode = _previousTextRenderingMode!;
  _graphicsState.add(state);
  if (_isStateSaved) {
    _helper.streamWriter!.restoreGraphicsState();
    _isStateSaved = false;
  }
  _helper.streamWriter!.saveGraphicsState();
  return state;
}