plasmic-pdf-viewer
v0.0.2
Published
A component for viewing PDFs for use in Plasmic
Readme
plasmic-pdf-viewer
A PDF viewer component for use in Plasmic
Contributors
- Callum Boase
- Github: CallumBoase
- Website: Enliven IT
- Email: [email protected]
- Mobile (Australia): +61409 378 253
- Ryan Mouritz
- Github: ryanmouritz
Getting help
Need help with your project? Contact one of the contributors using their contact details above.
We provide general support for this package, as well as paid coaching & development in Plasmic & Supabase.
Installation section 1: code components
This section explains how to install the code components that are included in this package.
PdfDocument: a wrapper component for rendering a PDFPdfPage: a component displaying 1 page of a PDF. Must be nested inside aPdfDocumentcomponent
The code components provide JUST the functionality of previewing a PDF. They do not provide any user interface, for example zoom controls, rotation, pagination controls etc. If you want a pre-built user interface, complete Install section 1, then move on to Installation section 2.
01 - in Plasmic web interface
- Create a new Plasmic app
- Rename your app
- Click the "Publish" button at top-right
- Add a "Push to Github" step, publishing to a new repo, nextjs, loader (recommended) method, typescript
- Click "publish" and wait for the build to complete
02 - On your machine
- Clone the repo you just created to your local machine
- In terminal, run
npm installto install plasmic & it's dependencies npm install plasmic-pdf-viewerto install this package- Open
./plasmic-init.ts. It should look like this to start with (default Plasmic comments removed for brevity)
import { initPlasmicLoader } from "@plasmicapp/loader-nextjs";
export const PLASMIC = initPlasmicLoader({
projects: [
{
id: "your-plasmic-project-id",
token: "your-plasmic-project-token",
},
],
preview: false,
});
- Modify
plasmic-init.tsto import components fromplasmic-pdf-viewer
import { initPlasmicLoader } from "@plasmicapp/loader-nextjs";
import {
PdfPage,
PdfDocument,
PdfPageMeta,
PdfDocumentMeta
} from "plasmic-pdf-viewer"
export const PLASMIC = initPlasmicLoader({
projects: [
{
id: "your-plasmic-project-id",
token: "your-plasmic-project-token",
},
],
preview: true,
});
//Register Plasmic-pdf-viewer components
PLASMIC.registerComponent(PdfPage, PdfPageMeta);
PLASMIC.registerComponent(PdfDocument, PdfDocumentMeta);
- In
./pagesdirectory add a new file called_app.tsxand add the following content. Save your file
import type { AppProps } from 'next/app';
//Import the CSS required for Plasmic PDF Viewer (from react-pdf) globally
import "react-pdf/dist/Page/AnnotationLayer.css"; // the annotation layer css ensures annotations are styled correctly overlaying the document
import "react-pdf/dist/Page/TextLayer.css"; // the text layer css ensures selectable text is styled correctly overlaying the document
function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />;
}
export default MyApp;- In terminal:
npm run devto start your Dev server
03 - in Plasmic web interface
- Configure you Custom App host to point to http://localhost:3000/plasmic-host
- When the page reloads, the registered components should be available in Add component -> Custom Components
Installation section 2: pre-built Plasmic user interface component
This section gives instructions on how to import into your project a pre-built user interface built in Plasmic that uses the Pdf Viewer code components (see Installation section 1).
We're importing from this example project (live link).
- Make sure you've already completed Installation section 1
- Open your plasmic project in Plasmic studio
- In the left sidebar, go to More (circle with 3 horizontal dots) and then
Imported Projects - Click
+ Importand copy this project ID infRdq7wprjh6Nr2UN9idWsy - If you get a popup about breakpoints, select
Keep using my existing breakpoints. - On any page in your project, click the
+component button and add thePdfViewercomponent to your page (found under "Imported Packages" ->Plasmic-pdf-viewer Plasmic component library) - Click on the new
PdfViewercomponent on your page, find it's Props and copy an example PDF into it (eg https://cdn.filestackcontent.com/wcrjf9qPTCKXV3hMXDwK). Your PDF should show on the page. - Now, go back to "More" -> "Imported Projects" and remove the package called
Plasmic-pdf-viewer Plasmic component libraryby clicking the 3 dots to the right of that package and selectingRemove imported project - Click "Confirm" in the popup
- The
PdfViewercomponent has now been copied to your project. You'll find it under the "Components" section as if you'd created it directly within your project. You're free to edit thePdfViewercomponent as you see fit.
Dev notes
- To test locally:
- In this plasmic-pdf-viewer repo:
- run
npm run build - run
npm packto create a tarball of the package (egplasmic-pdf-viewer-0.0.1.tgz) (important:npm linkdoes NOT work due to react conflicts)
- run
- In your local Plasmic nextjs project,
- run
npm install /path/to/plasmic-pdf-viewer-0.0.1.tgzto install the package - run
npm run devto start the dev server
- run
- In this plasmic-pdf-viewer repo:
- To retest a new version of local package locally
- Follow step 1 above
- In your local plasmic nextjs project:
- Stop your dev server
- run
npm uninstall plasmic-pdf-viewer - Clear nextjs cache by deleting
.nextfolder - (usually not needed): clear node cache
npm cache clean --force - run
npm install /path/to/plasmic-pdf-viewer-0.0.1.tgz - run
npm run devto start the dev server
- To publish this package to npm:
- Update the version in
package.json - Update changelog
- Push all changes to github
- Run npm publish
- In github user interface: create a new release & tag with same version number
- Update the version in
