0.2.1 ⢠Published 4 months ago
ck-create-pdf v0.2.1
React PDF Preview
A powerful development tool for previewing and developing PDF templates with @react-pdf/renderer in real-time. Perfect for Next.js projects that need to generate beautiful, dynamic PDFs.
Features
- š Side-by-side code and PDF preview
- šØ Pre-built professional templates
- š Hot reload support
- š Easy integration with Next.js projects
Installation
npm install react-pdf-preview --save-dev
Quick Start
1. Create New Templates
Initialize your project with example templates:
pdf-preview create
This will:
- Create a
templates
directory in your project - Add example templates (invoice, certificate, report, resume)
- Install required dependencies
You can specify a custom directory:
pdf-preview create --dir ./my-templates
2. Start Development Server
Run the development server to preview your templates:
pdf-preview dev
Options:
--dir
: Specify templates directory (default: ./templates)--port
: Specify port number (default: 3000)
pdf-preview dev --dir ./my-templates --port 3001
Template Development
Basic Template Structure
import React from "react";
import { Document, Page, Text, View, StyleSheet } from "@react-pdf/renderer";
const styles = StyleSheet.create({
page: {
flexDirection: "column",
backgroundColor: "#ffffff",
padding: 40,
},
// ... more styles
});
const MyTemplate: React.FC = () => (
<Document>
<Page size="A4" style={styles.page}>
{/* Your content here */}
</Page>
</Document>
);
export default MyTemplate;
Using Templates in Your App
import { PDFViewer } from "@react-pdf/renderer";
import MyTemplate from "../templates/my-template";
function App() {
return (
<PDFViewer>
<MyTemplate />
</PDFViewer>
);
}
Included Templates
The create
command provides four professional templates to help you get started:
Invoice Template
- Professional invoice layout
- Dynamic table structure
- Automatic calculations
- Clean, business-ready design
Certificate Template
- Achievement certificate layout
- Centered design
- Signature section
- Professional typography
Report Template
- Business report layout
- Multiple sections
- Executive summary
- Financial metrics
- Key achievements
Resume Template
- Modern CV layout
- Skills section with tags
- Professional experience timeline
- Education section
- Contact information
Project Structure
react-pdf-preview/
āāā src/
ā āāā app/ # Next.js app directory
ā āāā components/ # React components
ā ā āāā code-view.tsx # Code editor component
ā ā āāā pdf-viewer.tsx # PDF preview component
ā ā āāā view-switcher.tsx # View mode switcher
ā āāā cli/ # CLI tool implementation
ā āāā commands/ # CLI commands
ā āāā utils/ # Utility functions
āāā templates/ # PDF templates
āāā public/ # Static assets
āāā package.json
Development
To contribute or modify the tool:
- Clone the repository
- Install dependencies:
npm install
- Build the CLI:
npm run build:cli
- Link for local development:
npm link
Configuration
Tailwind CSS
The preview interface uses Tailwind CSS. You can customize the styling by modifying:
tailwind.config.ts
postcss.config.js
src/app/globals.css
Next.js
The tool is built on Next.js. Configuration can be found in:
next.config.js
tsconfig.json
Requirements
- Node.js 16.x or higher
- Next.js project
- TypeScript (recommended)
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.