- 文件剪贴板复制剪切粘贴,重名自动副本 - SFTP下载到本机与外部文件拖入,目录递归 - 传输进度浮动面板,transfer-progress事件链 - Drawio预览,Excel工作线程,冻结看门狗 - cmd与bat自写batch语法高亮,psm1等映射补齐
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"u-desk/internal/api"
|
|
)
|
|
|
|
// requirePdfAPI 检查 pdfAPI 是否已初始化
|
|
func (a *App) requirePdfAPI() (*api.PdfAPI, error) {
|
|
a.mu.Lock()
|
|
defer a.mu.Unlock()
|
|
if a.pdfAPI == nil {
|
|
return nil, fmt.Errorf("PDF导出功能正在初始化中")
|
|
}
|
|
return a.pdfAPI, nil
|
|
}
|
|
|
|
// ExportPDF 导出PDF文件
|
|
func (a *App) ExportPDF(content string, title string, fileName string, fontSize int, pageWidth int, pageHeight int) (map[string]interface{}, error) {
|
|
pdfAPI, err := a.requirePdfAPI()
|
|
if err != nil {
|
|
return map[string]interface{}{
|
|
"success": false,
|
|
"message": err.Error(),
|
|
}, err
|
|
}
|
|
|
|
req := api.PdfExportRequest{
|
|
Content: content,
|
|
Title: title,
|
|
FileName: fileName,
|
|
FontSize: fontSize,
|
|
PageWidth: pageWidth,
|
|
PageHeight: pageHeight,
|
|
}
|
|
|
|
result, err := pdfAPI.ExportMarkdownToPDF(req)
|
|
if err != nil {
|
|
return map[string]interface{}{
|
|
"success": false,
|
|
"message": err.Error(),
|
|
}, err
|
|
}
|
|
|
|
return map[string]interface{}{
|
|
"success": result.Success,
|
|
"message": result.Message,
|
|
"path": result.Path,
|
|
"size": result.Size,
|
|
}, nil
|
|
}
|
|
|
|
// SelectPDFSaveDirectory 选择PDF保存目录
|
|
func (a *App) SelectPDFSaveDirectory() (string, error) {
|
|
pdfAPI, err := a.requirePdfAPI()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return pdfAPI.SelectDirectory()
|
|
}
|