MCPcopy
hub / github.com/GitbookIO/gitbook / PDFPage

Function PDFPage

packages/gitbook/src/components/PDF/PDFPage.tsx:50–180  ·  view source on GitHub ↗
(props: {
    context: GitBookSpaceContext | GitBookSiteContext;
    searchParams: { [key: string]: string };
})

Source from the content-addressed store, hash-verified

48 * Render a space as a standalone HTML page that can be printed as a PDF.
49 */
50export async function PDFPage(props: {
51 context: GitBookSpaceContext | GitBookSiteContext;
52 searchParams: { [key: string]: string };
53}) {
54 const baseContext = props.context;
55 const searchParams = new URLSearchParams(props.searchParams);
56 const pdfParams = getPDFSearchParams(searchParams);
57
58 const customization =
59 'customization' in baseContext ? baseContext.customization : defaultCustomization();
60 const language = getSpaceLanguage(baseContext);
61
62 // Compute the pages to render
63 const { pages, total } = selectPages(baseContext.revision.pages, pdfParams);
64 const pageIds = pages.map(
65 ({ page }) => [page.id, getPagePDFContainerId(page)] as [string, string]
66 );
67
68 // Build a linker that create anchor links for the pages rendered in the PDF page.
69 const linker: GitBookLinker = {
70 ...baseContext.linker,
71 toPathForPage(input) {
72 if (pages.some((p) => p.page.id === input.page.id)) {
73 return `#${getPagePDFContainerId(input.page, input.anchor)}`;
74 }
75 if (input.page.type === RevisionPageType.Group) {
76 return '#';
77 }
78
79 // Use an absolute URL to the page
80 return input.page.urls.app;
81 },
82 };
83
84 const context: GitBookSpaceContext = {
85 ...baseContext,
86 linker,
87 };
88
89 return (
90 <div className="print-mode">
91 {pdfParams.back !== 'false' ? (
92 <div className={tcls('fixed', 'left-12', 'top-12', 'print:hidden', 'z-50')}>
93 <a
94 title={tString(language, 'pdf_goback')}
95 href={
96 (pdfParams.back ? sanitizeGitBookAppURL(pdfParams.back) : null) ??
97 linker.toAbsoluteURL(linker.toPathInSpace(''))
98 }
99 className={tcls(
100 'flex',
101 'flex-row',
102 'items-center',
103 'justify-center',
104 'text-sm',
105 'text-tint',
106 'hover:text-primary',
107 'p-4',

Callers

nothing calls this directly

Calls 10

getPDFSearchParamsFunction · 0.90
defaultCustomizationFunction · 0.90
getSpaceLanguageFunction · 0.90
tclsFunction · 0.90
tStringFunction · 0.90
sanitizeGitBookAppURLFunction · 0.90
selectPagesFunction · 0.85
getPagePDFContainerIdFunction · 0.85
toAbsoluteURLMethod · 0.80
toPathInSpaceMethod · 0.80

Tested by

no test coverage detected