Files
pdf-translation-interface/create-test-pdf.js
aken1023 39a4788cc4 Add PDF translation API, utilities, docs, and config
Introduces core backend and frontend infrastructure for a PDF translation interface. Adds API endpoints for translation, PDF testing, and AI provider testing; implements PDF text extraction, cost tracking, and pricing logic in the lib directory; adds reusable UI components; and provides comprehensive documentation (SDD, environment setup, Claude instructions). Updates Tailwind and global styles, and includes a sample test PDF and configuration files.
2025-10-15 23:34:44 +08:00

55 lines
1.5 KiB
JavaScript

const fs = require('fs')
const { PDFDocument, StandardFonts, rgb } = require('pdf-lib')
async function createTestPDF() {
try {
// Create a new PDF document using pdf-lib (same library we use for processing)
const pdfDoc = await PDFDocument.create()
// Add a page
const page = pdfDoc.addPage()
const { width, height } = page.getSize()
// Embed a standard font
const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
// Add text content (using only ASCII characters to ensure compatibility)
const fontSize = 16
let yPosition = height - 100
const texts = [
'PDF Text Extraction Test',
'This is a test document for PDF text extraction.',
'Line 1: Hello World',
'Line 2: Testing PDF processing',
'Line 3: Multiple line text extraction',
'This PDF was created using pdf-lib.',
'It should have extractable text content.'
]
for (const text of texts) {
page.drawText(text, {
x: 50,
y: yPosition,
size: fontSize,
font: font,
color: rgb(0, 0, 0),
})
yPosition -= fontSize + 10
}
// Save the PDF
const pdfBytes = await pdfDoc.save()
// Write to file
fs.writeFileSync('test-document.pdf', pdfBytes)
console.log('Test PDF created successfully: test-document.pdf')
console.log(`PDF size: ${pdfBytes.length} bytes`)
} catch (error) {
console.error('Error creating PDF:', error)
}
}
createTestPDF()