fix pagination issues, resizing issues
This commit is contained in:
parent
a04150be49
commit
8b98e94d78
4 changed files with 15 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
||||||
import Page from 'site/components/wrappers/page.js'
|
import Page from 'site/components/wrappers/page.js'
|
||||||
import useApp from 'site/hooks/useApp.js'
|
import useApp from 'site/hooks/useApp.js'
|
||||||
import WorkbenchWrapper from 'shared/components/wrappers/workbench'
|
import WorkbenchWrapper from 'shared/components/wrappers/workbench.js'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import Layout from 'site/components/layouts/lab'
|
import Layout from 'site/components/layouts/lab'
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,8 @@ export default class PdfMaker {
|
||||||
/** the height of the entire svg, in points */
|
/** the height of the entire svg, in points */
|
||||||
svgHeight
|
svgHeight
|
||||||
|
|
||||||
|
pageCount = 0
|
||||||
|
|
||||||
constructor({svg, settings, pages, strings}) {
|
constructor({svg, settings, pages, strings}) {
|
||||||
this.settings = settings
|
this.settings = settings
|
||||||
this.pagesWithContent = pages.withContent;
|
this.pagesWithContent = pages.withContent;
|
||||||
|
@ -108,26 +110,28 @@ export default class PdfMaker {
|
||||||
|
|
||||||
/** generate the cover page for the pdf */
|
/** generate the cover page for the pdf */
|
||||||
async generateCoverPage() {
|
async generateCoverPage() {
|
||||||
|
|
||||||
// don't make one if it's not requested
|
// don't make one if it's not requested
|
||||||
if (!this.settings.coverPage) {
|
if (!this.settings.coverPage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.generateCoverPageTitle()
|
const headerLevel = await this.generateCoverPageTitle()
|
||||||
|
|
||||||
//abitrary margin for visual space
|
//abitrary margin for visual space
|
||||||
let coverMargin = 85
|
let coverMargin = 85
|
||||||
let coverHeight = this.pdf.page.height - coverMargin * 2
|
let coverHeight = this.pdf.page.height - coverMargin * 2 - headerLevel
|
||||||
let coverWidth = this.pdf.page.width - coverMargin * 2
|
let coverWidth = this.pdf.page.width - coverMargin * 2
|
||||||
|
|
||||||
// add the entire pdf to the page, so that it fills the available space as best it can
|
// add the entire pdf to the page, so that it fills the available space as best it can
|
||||||
await SVGtoPDF(this.pdf, this.svg, coverMargin, coverMargin * 1.5, {
|
await SVGtoPDF(this.pdf, this.svg, coverMargin, headerLevel + coverMargin, {
|
||||||
width: coverWidth,
|
width: coverWidth,
|
||||||
height: coverHeight,
|
height: coverHeight,
|
||||||
assumePt: false,
|
assumePt: false,
|
||||||
// use aspect ratio to center it
|
// use aspect ratio to center it
|
||||||
preserveAspectRatio: 'xMidYMid meet'
|
preserveAspectRatio: 'xMidYMid meet'
|
||||||
});
|
});
|
||||||
|
this.pageCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateCoverPageTitle() {
|
async generateCoverPageTitle() {
|
||||||
|
@ -161,6 +165,8 @@ export default class PdfMaker {
|
||||||
this.pdf.fillColor('#888888')
|
this.pdf.fillColor('#888888')
|
||||||
this.pdf.fontSize(10)
|
this.pdf.fontSize(10)
|
||||||
this.pdf.text(this.strings.url, lineStart, lineLevel)
|
this.pdf.text(this.strings.url, lineStart, lineLevel)
|
||||||
|
|
||||||
|
return lineLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
/** generate the pages of the pdf */
|
/** generate the pages of the pdf */
|
||||||
|
@ -185,13 +191,14 @@ export default class PdfMaker {
|
||||||
let y = -h * this.pageHeight + startMargin
|
let y = -h * this.pageHeight + startMargin
|
||||||
|
|
||||||
// if there was no cover page, the first page already exists
|
// if there was no cover page, the first page already exists
|
||||||
if (this.settings.coverPage || h+w > 0) {
|
if (this.pageCount > 0) {
|
||||||
// otherwise make a new page
|
// otherwise make a new page
|
||||||
this.pdf.addPage()
|
this.pdf.addPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the pdf to the page, offset by the page distances
|
// add the pdf to the page, offset by the page distances
|
||||||
await SVGtoPDF(this.pdf, this.svg, x, y, options)
|
await SVGtoPDF(this.pdf, this.svg, x, y, options)
|
||||||
|
this.pageCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import Modal from 'shared/components/modal'
|
||||||
import Measurements from 'shared/components/workbench/measurements/index.js'
|
import Measurements from 'shared/components/workbench/measurements/index.js'
|
||||||
import LabDraft from 'shared/components/workbench/draft/index.js'
|
import LabDraft from 'shared/components/workbench/draft/index.js'
|
||||||
import LabSample from 'shared/components/workbench/sample.js'
|
import LabSample from 'shared/components/workbench/sample.js'
|
||||||
import ExportDraft from 'shared/components/workbench/exporting/index'
|
import ExportDraft from 'shared/components/workbench/exporting/index.js'
|
||||||
import GistAsJson from 'shared/components/workbench/json.js'
|
import GistAsJson from 'shared/components/workbench/json.js'
|
||||||
import GistAsYaml from 'shared/components/workbench/yaml.js'
|
import GistAsYaml from 'shared/components/workbench/yaml.js'
|
||||||
import DraftEvents from 'shared/components/workbench/events.js'
|
import DraftEvents from 'shared/components/workbench/events.js'
|
||||||
|
@ -113,6 +113,7 @@ const WorkbenchWrapper = ({ app, design, preload=false, from=false, layout=false
|
||||||
// Generate the draft here so we can pass it down to both the view and the options menu
|
// Generate the draft here so we can pass it down to both the view and the options menu
|
||||||
let draft = false
|
let draft = false
|
||||||
if (['draft', 'events', 'test', 'printingLayout'].indexOf(gist._state?.view) !== -1) {
|
if (['draft', 'events', 'test', 'printingLayout'].indexOf(gist._state?.view) !== -1) {
|
||||||
|
gist.embed = true
|
||||||
// get the appropriate layout for the view
|
// get the appropriate layout for the view
|
||||||
const layout = gist.layouts?.[gist._state.view] || gist.layout || true
|
const layout = gist.layouts?.[gist._state.view] || gist.layout || true
|
||||||
// hand it separately to the design
|
// hand it separately to the design
|
||||||
|
|
|
@ -33,7 +33,7 @@ const loadFromUnpkg = (design, version) => {
|
||||||
const pageTemplate = design => `${header}
|
const pageTemplate = design => `${header}
|
||||||
import design from 'designs/${design}/src/index.js'
|
import design from 'designs/${design}/src/index.js'
|
||||||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
||||||
import PageTemplate from 'site/page-templates/workbench'
|
import PageTemplate from 'site/page-templates/workbench.js'
|
||||||
|
|
||||||
const Page = (props) => <PageTemplate {...props} design={design} version="next"/>
|
const Page = (props) => <PageTemplate {...props} design={design} version="next"/>
|
||||||
export default Page
|
export default Page
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue