-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
543 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Button from "@mui/material/Button" | ||
import fileDownload from "js-file-download" | ||
import { ReactElement } from "react" | ||
import * as React from "react" | ||
import ReactDOMServer from "react-dom/server" | ||
import { SvgPrintContext } from "./Measure" | ||
|
||
export function ExportButtons({ | ||
what, | ||
baseFileName, | ||
}: { | ||
what: ReactElement | ||
baseFileName: string | ||
}) { | ||
const getPrintSVG = () => | ||
ReactDOMServer.renderToStaticMarkup( | ||
<SvgPrintContext.Provider value={true}>{what}</SvgPrintContext.Provider>, | ||
).replace(/\s{2,}/g, " ") | ||
const asSVG = () => { | ||
const svg = getPrintSVG() | ||
fileDownload(svg, baseFileName + ".svg") | ||
} | ||
const asTemplatePDF = async () => { | ||
const { svgToPdf } = await import( | ||
/* webpackChunkName: "svgToPdf" */ "../paperBox1/svgToPdf" | ||
) | ||
|
||
// add your content to the document here, as usual | ||
const blob = await svgToPdf({ | ||
title: baseFileName, | ||
author: "Adrian Leonhard", | ||
svg: getPrintSVG(), | ||
}) | ||
|
||
fileDownload(blob, baseFileName + ".pdf") | ||
} | ||
return ( | ||
<> | ||
<Button variant="contained" onClick={asSVG}> | ||
Download As SVG | ||
</Button> | ||
<Button variant="contained" onClick={asTemplatePDF}> | ||
Template as PDF | ||
</Button> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.