1
0
Fork 0

fix pagination issues, resizing issues

This commit is contained in:
Enoch Riese 2022-08-24 16:02:52 -05:00
parent a04150be49
commit 8b98e94d78
4 changed files with 15 additions and 7 deletions

View file

@ -1,6 +1,6 @@
import Page from 'site/components/wrappers/page.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 Layout from 'site/components/layouts/lab'

View file

@ -46,6 +46,8 @@ export default class PdfMaker {
/** the height of the entire svg, in points */
svgHeight
pageCount = 0
constructor({svg, settings, pages, strings}) {
this.settings = settings
this.pagesWithContent = pages.withContent;
@ -108,26 +110,28 @@ export default class PdfMaker {
/** generate the cover page for the pdf */
async generateCoverPage() {
// don't make one if it's not requested
if (!this.settings.coverPage) {
return
}
await this.generateCoverPageTitle()
const headerLevel = await this.generateCoverPageTitle()
//abitrary margin for visual space
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
// 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,
height: coverHeight,
assumePt: false,
// use aspect ratio to center it
preserveAspectRatio: 'xMidYMid meet'
});
this.pageCount++
}
async generateCoverPageTitle() {
@ -161,6 +165,8 @@ export default class PdfMaker {
this.pdf.fillColor('#888888')
this.pdf.fontSize(10)
this.pdf.text(this.strings.url, lineStart, lineLevel)
return lineLevel
}
/** generate the pages of the pdf */
@ -185,13 +191,14 @@ export default class PdfMaker {
let y = -h * this.pageHeight + startMargin
// 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
this.pdf.addPage()
}
// add the pdf to the page, offset by the page distances
await SVGtoPDF(this.pdf, this.svg, x, y, options)
this.pageCount++;
}
}
}

View file

@ -11,7 +11,7 @@ import Modal from 'shared/components/modal'
import Measurements from 'shared/components/workbench/measurements/index.js'
import LabDraft from 'shared/components/workbench/draft/index.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 GistAsYaml from 'shared/components/workbench/yaml.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
let draft = false
if (['draft', 'events', 'test', 'printingLayout'].indexOf(gist._state?.view) !== -1) {
gist.embed = true
// get the appropriate layout for the view
const layout = gist.layouts?.[gist._state.view] || gist.layout || true
// hand it separately to the design

View file

@ -33,7 +33,7 @@ const loadFromUnpkg = (design, version) => {
const pageTemplate = design => `${header}
import design from 'designs/${design}/src/index.js'
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"/>
export default Page