plasmic-pdf-viewer
v0.0.2
Published
A component for viewing PDFs for use in Plasmic
Downloads
6
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 aPdfDocument
component
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 install
to install plasmic & it's dependencies npm install plasmic-pdf-viewer
to 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.ts
to 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
./pages
directory add a new file called_app.tsx
and 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 dev
to 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
+ Import
and 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 thePdfViewer
component to your page (found under "Imported Packages" ->Plasmic-pdf-viewer Plasmic component library
) - Click on the new
PdfViewer
component 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 library
by clicking the 3 dots to the right of that package and selectingRemove imported project
- Click "Confirm" in the popup
- The
PdfViewer
component 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 thePdfViewer
component as you see fit.
Dev notes
- To test locally:
- In this plasmic-pdf-viewer repo:
- run
npm run build
- run
npm pack
to create a tarball of the package (egplasmic-pdf-viewer-0.0.1.tgz
) (important:npm link
does NOT work due to react conflicts)
- run
- In your local Plasmic nextjs project,
- run
npm install /path/to/plasmic-pdf-viewer-0.0.1.tgz
to install the package - run
npm run dev
to 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
.next
folder - (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 dev
to 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