mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-08-30 12:12:40 +08:00
This commit is contained in:
@@ -79,7 +79,7 @@ func safeCall(fn func([]js.Value) (any, error), args []js.Value) (data any, err
|
||||
// 入参: args 浏览器参数
|
||||
// 返回: any 文档信息, error 错误信息
|
||||
func openDocument(args []js.Value) (any, error) {
|
||||
if len(args) < 3 {
|
||||
if len(args) < 4 {
|
||||
return nil, fmt.Errorf("missing open arguments")
|
||||
}
|
||||
data, err := bytesFromJS(args[0])
|
||||
@@ -91,11 +91,12 @@ func openDocument(args []js.Value) (any, error) {
|
||||
return nil, err
|
||||
}
|
||||
renderAnnotations := args[2].Bool()
|
||||
dpi := args[3].Float()
|
||||
if currentSession != nil {
|
||||
_ = currentSession.Close()
|
||||
currentSession = nil
|
||||
}
|
||||
session, err := Open(data, OpenOptions{Fonts: fonts, RenderAnnotations: renderAnnotations})
|
||||
session, err := Open(data, OpenOptions{Fonts: fonts, DPI: dpi, RenderAnnotations: renderAnnotations})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
// OpenOptions 打开OFD文档选项
|
||||
type OpenOptions struct {
|
||||
Fonts []FontFile
|
||||
DPI float64
|
||||
RenderAnnotations bool
|
||||
}
|
||||
|
||||
@@ -186,6 +187,9 @@ func Open(data []byte, opts OpenOptions) (*Session, error) {
|
||||
return nil, err
|
||||
}
|
||||
var rendererOptions []ofdgo.RendererOption
|
||||
if opts.DPI > 0 {
|
||||
rendererOptions = append(rendererOptions, ofdgo.WithDPI(opts.DPI))
|
||||
}
|
||||
if len(opts.Fonts) > 0 {
|
||||
fontFS := ofdgo.NewFontFS(opts.Fonts)
|
||||
if fontFS.Len() == 0 {
|
||||
|
||||
Reference in New Issue
Block a user