A tool to convert React TSX components to PDF files with proper formatting.
- Node.js (v14 or higher)
- npm or yarn
- Anthropic Claude API key (for component generation)
npm installSet up your environment variable for the Claude API key:
# Create a .env file in the root directory
echo "ANTHROPIC_API_KEY=your_api_key_here" > .envThe easiest way to use this tool is with the all-in-one command:
npm startThis command will:
- Set up the input directory
- Set up and start the development server
- Build and start the UI server
- Display a list of available components
- Keep the servers running until you press Ctrl+C
The tool now includes a web-based user interface for easier use:
- Start the tool with
npm start - Open your browser and navigate to http://localhost:3000
- Use the UI to:
- Select a component to export
- Configure export options (aspect ratio, paper size, orientation, etc.)
- Export the component to PDF
- View and download previously exported PDF files
- Generate new components with Claude AI
The UI provides a simple and intuitive way to export your TSX components without having to use the command line.
The Export tab allows you to:
- Upload new TSX components directly through the UI
- Select a component from the input directory
- Set the output file name
- Configure export options
- Export the component to PDF
The Output Files tab allows you to:
- View a list of all exported PDF files
- See file details (size, creation date)
- View PDFs directly in the browser
- Download PDFs to your computer
The Generate with Claude tab allows you to:
- Create TSX components by describing what you want
- Preview generated components
- Save components to the input directory
- Export generated components directly to PDF
- Describe the component you want to create
- Click "Generate Component"
- Review the generated code
- Save the component or make edits
- Export to PDF using the Export tab
Example prompts:
- "Create a dashboard with charts showing user activity"
- "Make a pricing comparison table with three tiers"
- "Design a timeline component showing project milestones"
If you prefer to run each step manually, follow these instructions:
Place your TSX component files in the input directory. The tool supports both PascalCase and kebab-case file naming:
MyComponent.tsx(PascalCase)my-component.tsx(kebab-case)
If your components import other components or have dependencies:
-
For shared components: Place them in the
input/componentsdirectory// Example: input/MyComponent.tsx can import from input/components import SharedButton from './components/SharedButton';
-
For direct imports: You can import components directly from the input directory
// Example: input/Dashboard.tsx can import from input/Chart.tsx import Chart from './Chart';
-
For external libraries: Common libraries like React and lucide-react are already included. If you need additional libraries, you can modify the
setup-dev-server.jsfile to include them in thepackageJsonobject.
Run the setup script to create a development server that will serve your TSX components:
./setup-dev-server.jsThen start the server:
cd RenderingServer
npm install
npm run devThe server will be available at http://localhost:5174 and will automatically serve all components in the input directory.
Once your server is running, you can use this tool to convert TSX files to PDF:
npm run convert input/your-component.tsx [output.pdf]Options:
--aspect-ratio: Aspect ratio for the slides (e.g., '16:9', default: '16:9')--paper-size: PDF paper size ('A4' or 'Letter', default: 'A4')--orientation: PDF orientation ('portrait' or 'landscape', default: 'landscape')--margin: Margin in pixels (default: 0)--auto-size: Automatically adjust PDF size to fit content (default: true)--no-auto-size: Disable automatic sizing and use fixed dimensions--debug: Debug mode, keeps temporary files (default: false)
Example:
npm run convert input/complex-flowchart.tsx --paper-size=Letter --margin=20- The tool takes a TSX file as input
- It extracts the component name from the file name (converting kebab-case to PascalCase if needed)
- It navigates to
http://localhost:5174/ComponentNameusing Puppeteer - It captures the rendered component as a PDF, automatically sizing the PDF to fit the content
- If multiple TSX files are provided, it merges them into a single PDF
The Claude integration works as follows:
- The user provides a description of the component they want to create
- The description is sent to Claude using the API key from the environment variable
- Claude generates TSX code for the component using the claude-3-7-sonnet-latest model
- The code is saved as a temporary file in the input directory
- The component is rendered in the RenderingServer
- The user can preview the component, make edits, and save it permanently
- The component can then be exported to PDF like any other component
input/- Place your TSX components here for exportoutput/- Exported PDFs are saved hereConverterFrontend/- Frontend UI source codeConverterService/- Backend source codeRenderingServer/- Development server for rendering TSX components
The input directory contains sample TSX files that you can use to test the tool:
example-slide.tsx: A simple slide with a title and textcomplex-flowchart.tsx: A more complex component with a flowchartthinking-llm-visualization.tsx: A visualization of how thinking LLMs work
MIT