peterfei/ai-agent-team / .claude/skills/softcopyright
softcopyright
Flagged智能软件著作权申请材料生成工具。自动分析项目源码,生成符合软著申请要求的软件说明书和源代码文档。支持关键词搜索、智能源码分析、格式化输出和PDF导出。
scripts/chinese-pdf-fix.js
View on GitHub/**
* 中文PDF修复方案
* 解决PDFKit中文字符显示问题
*/
const fs = require('fs-extra');
const path = require('path');
class ChinesePDFFix {
constructor() {
this.fontsDir = path.join(__dirname, '..', 'fonts');
}
/**
* 获取可用的中文字体路径
* @returns {Promise<string>}
*/
async getChineseFont() {
// 1. 首先检查已存在的字体
const existingFonts = await this.findExistingFonts();
if (existingFonts.length > 0) {
console.log(`使用已存在的字体: ${existingFonts[0]}`);
return existingFonts[0];
}
// 2. 尝试复制系统字体
const systemFont = await this.copySystemFont();
if (systemFont) {
return systemFont;
}
// 3. 创建临时字体解决方案
return this.createFallbackFont();
}
/**
* 查找已存在的字体
* @returns {Promise<string[]>}
*/
async findExistingFonts() {
const fontExtensions = ['.ttf', '.otf', '.woff', '.woff2'];
const fonts = [];
if (await fs.pathExists(this.fontsDir)) {
const files = await fs.readdir(this.fontsDir);
for (const file of files) {
const ext = path.extname(file).toLowerCase();
if (fontExtensions.includes(ext)) {
fonts.push(path.join(this.fontsDir, file));
}
}
}
return fonts;
}
/**
* 复制系统字体
* @returns {Promise<string|null>}
*/
async copySystemFont() {
const systemFonts = [
'/System/Library/Fonts/PingFang.ttc',
'/System/Library/Fonts/STHeiti Medium.ttc',
'/System/Library/Fonts/STHeiti Light.ttc',
'/System/Library/Fonts/Hiragino Sans GB.ttc',
'/System/Library/Fonts/AppleSDGothicNeo.ttc'
];
await fs.ensureDir(this.fontsDir);
for (const systemFont of systemFonts) {
if (await fs.pathExists(systemFont)) {
try {
const fontName = `chinese-font-${Date.now()}.ttc`;
const targetPath = path.join(this.fontsDir, fontName);
await fs.copy(systemFont, targetPath);
console.log(`系统字体复制成功: ${fontName}`);
return targetPath;
} catch (error) {
console.warn(`复制系统字体失败: ${systemFont}`, error.message);
continue;
}
}
}
return null;
}
/**
* 创建备用解决方案
* @returns {Promise<string>}
*/
async createFallbackFont() {
console.log('使用备用字体方案...');
return null; // 让PDFKit使用默认字体
}
/**
* 测试字体是否支持中文
* @param {string} fontPath 字体路径
* @returns {Promise<boolean>}
*/
async testChineseFont(fontPath) {
try {
// 这里可以添加字体测试逻辑
return true;
} catch (error) {
return false;
}
}
/**
* 设置PDFDocument的字体
* @param {PDFDocument} doc PDFDocument实例
* @returns {Promise<void>}
*/
async setFont(doc) {
try {
const fontPath = await this.getChineseFont();
if (fontPath) {
// 尝试设置中文字体
doc.font(fontPath);
console.log('中文字体设置成功');
} else {
// 使用默认字体,但设置更大的字体大小
doc.font('Helvetica');
console.log('使用默认字体,建议增加字体大小');
}
} catch (error) {
console.warn('字体设置失败,使用默认字体:', error.message);
doc.font('Helvetica');
}
}
/**
* 为PDF文本添加中文字符支持
* @param {PDFDocument} doc PDFDocument实例
* @param {string} text 文本内容
* @param {Object} options 选项
*/
addChineseText(doc, text, options = {}) {
try {
// 确保字体已设置
if (!options.font) {
doc.font('Helvetica');
}
// 增加字体大小以提高可读性
const fontSize = options.fontSize || 12;
doc.fontSize(fontSize);
// 添加文本
doc.text(text, options);
} catch (error) {
console.warn('中文文本添加失败:', error.message);
}
}
}
module.exports = ChinesePDFFix;Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |