Documentation
¶
Index ¶
- Constants
- func DecodePNGDataURL(s string) ([]byte, error)
- type ConflictError
- type Document
- type PDFMetadata
- type PDFService
- func (s *PDFService) ChooseSavePath(id, filename string) (*SaveTarget, error)
- func (s *PDFService) ClosePDF(id string) error
- func (s *PDFService) OpenPDF() (*Document, error)
- func (s *PDFService) OpenPDFByPath(path string) (*Document, error)
- func (s *PDFService) SavePDF(id string, data []byte, overwrite bool) (*Document, error)
- func (s *PDFService) SavePDFAs(id, path string, data []byte) (*Document, error)
- func (s *PDFService) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type PageDimensions
- type PageInfo
- type RecentFile
- type RecentFilesService
- func (s *RecentFilesService) AddRecent(filePath string, pageCount int) error
- func (s *RecentFilesService) ClearRecent() error
- func (s *RecentFilesService) GetRecent() []RecentFile
- func (s *RecentFilesService) RemoveRecent(filePath string) error
- func (s *RecentFilesService) ServiceStartup(ctx context.Context, _ application.ServiceOptions) error
- func (s *RecentFilesService) Shutdown(timeout time.Duration) error
- type Renderer
- func (s *Renderer) ClosePDF() error
- func (s *Renderer) GenerateThumbnail(filePath string, maxWidth int) (string, error)
- func (s *Renderer) GetPageCount() int
- func (s *Renderer) GetPageDimensions(pageNum int) (*PageDimensions, error)
- func (s *Renderer) OpenPDFByPath(filePath string) (*PDFMetadata, error)
- func (s *Renderer) RenderPage(pageNum int, dpi float64) (*PageInfo, error)
- type SaveTarget
Constants ¶
const ( // ConflictChanged: the file changed on disk since it was opened or last saved. ConflictChanged = "changed" // ConflictOpen: the Save As target is open in another tab. ConflictOpen = "open" )
Reasons for a ConflictError.
const ( MinDPI = 10.0 MaxDPI = 600.0 PDFOpenTimeout = 120 * time.Second PDFRenderTimeout = 300 * time.Second MaxPDFFileSizeBytes = 1 * 1024 * 1024 * 1024 // 1GB maximum file size )
const (
DefaultMaxRecentFiles = 20
)
const DocumentRoute = "/doc/"
DocumentRoute is where ServeHTTP is mounted on the Wails asset server; pdf.js loads a document from DocumentRoute + id.
Variables ¶
This section is empty.
Functions ¶
func DecodePNGDataURL ¶ added in v1.0.0
DecodePNGDataURL returns the raw PNG bytes of the data URLs RenderPage and GenerateThumbnail produce.
Types ¶
type ConflictError ¶ added in v1.0.0
ConflictError is returned instead of writing when a save would clobber changes the app doesn't hold. It reaches the frontend as the error's cause.
func (*ConflictError) Error ¶ added in v1.0.0
func (e *ConflictError) Error() string
type Document ¶ added in v1.0.0
type Document struct {
ID string `json:"id"`
Path string `json:"path"`
FileName string `json:"fileName"`
Size int64 `json:"size"`
ModTime time.Time `json:"modTime"`
// contains filtered or unexported fields
}
Document is a PDF the GUI has open. The webview reads and writes it by its random id; the only paths it can name are files the user picked in a dialog or asked to open, and for Save As only the one chosen in ChooseSavePath.
type PDFMetadata ¶
type PDFMetadata struct {
Title string `json:"title"`
Author string `json:"author"`
Subject string `json:"subject"`
Creator string `json:"creator"`
PageCount int `json:"pageCount"`
FilePath string `json:"filePath"`
}
PDFMetadata contains metadata extracted from a PDF document.
type PDFService ¶
type PDFService struct {
// contains filtered or unexported fields
}
PDFService keeps the registry of documents open in the GUI, serves their bytes to pdf.js and writes the bytes pdf.js produces back to disk.
func NewPDFService ¶
func NewPDFService() *PDFService
NewPDFService creates an empty document registry.
func (*PDFService) ChooseSavePath ¶ added in v1.0.0
func (s *PDFService) ChooseSavePath(id, filename string) (*SaveTarget, error)
ChooseSavePath shows a Save As dialog next to the document, suggesting filename (the document's own name when empty). It returns nil when the user cancels. The GTK dialog doesn't confirm overwrites, so Exists tells the caller to ask.
func (*PDFService) ClosePDF ¶
func (s *PDFService) ClosePDF(id string) error
ClosePDF forgets the document with the given id.
func (*PDFService) OpenPDF ¶
func (s *PDFService) OpenPDF() (*Document, error)
OpenPDF shows a file dialog and registers the chosen PDF. It returns nil when the user cancels.
func (*PDFService) OpenPDFByPath ¶
func (s *PDFService) OpenPDFByPath(path string) (*Document, error)
OpenPDFByPath registers the PDF at path under a new id.
func (*PDFService) SavePDF ¶ added in v1.0.0
SavePDF replaces the document's file with data. Unless overwrite is set it refuses, with a ConflictError, when the file changed on disk since it was opened or last saved.
func (*PDFService) SavePDFAs ¶ added in v1.0.0
func (s *PDFService) SavePDFAs(id, path string, data []byte) (*Document, error)
SavePDFAs writes data to path, which must be the one ChooseSavePath last returned for the document; the document then refers to the new file. It refuses, with a ConflictError, a path open under another id.
func (*PDFService) ServeHTTP ¶ added in v1.0.0
func (s *PDFService) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP streams a registered document, and saves the body of a PUT like SavePDF (?overwrite=1) or SavePDFAs (?saveAs=<path>). Raw bytes avoid the binding call's base64 JSON body and its 64 MiB cap. The asset server strips DocumentRoute, so the request path is just the id.
type PageDimensions ¶
PageDimensions represents the dimensions of a PDF page
type PageInfo ¶
type PageInfo struct {
PageNumber int `json:"pageNumber"`
Width int `json:"width"`
Height int `json:"height"`
ImageData string `json:"imageData"` // Base64 encoded PNG
}
PageInfo contains information about a rendered PDF page including dimensions and image data.
type RecentFile ¶
type RecentFile struct {
FilePath string `json:"filePath"`
FileName string `json:"fileName"`
LastOpened time.Time `json:"lastOpened"`
PageCount int `json:"pageCount"`
}
RecentFile represents a recently opened PDF file
type RecentFilesService ¶
type RecentFilesService struct {
// contains filtered or unexported fields
}
RecentFilesService tracks recently opened PDF files with persistence.
func NewRecentFilesService ¶
func NewRecentFilesService() *RecentFilesService
NewRecentFilesService creates a new recent files service
func (*RecentFilesService) AddRecent ¶
func (s *RecentFilesService) AddRecent(filePath string, pageCount int) error
AddRecent adds or moves a file to the top of the recent files list.
func (*RecentFilesService) ClearRecent ¶
func (s *RecentFilesService) ClearRecent() error
ClearRecent removes all entries from the recent files list.
func (*RecentFilesService) GetRecent ¶
func (s *RecentFilesService) GetRecent() []RecentFile
GetRecent returns recent files, automatically removing entries for deleted files.
func (*RecentFilesService) RemoveRecent ¶
func (s *RecentFilesService) RemoveRecent(filePath string) error
RemoveRecent removes a specific file from the recent files list.
func (*RecentFilesService) ServiceStartup ¶ added in v1.0.0
func (s *RecentFilesService) ServiceStartup(ctx context.Context, _ application.ServiceOptions) error
ServiceStartup loads persisted recent files. Called by Wails on app start.
type Renderer ¶ added in v1.0.0
type Renderer struct {
// contains filtered or unexported fields
}
Renderer rasterises PDF pages with MuPDF (go-fitz) for the CLI's info, pages, render and thumbnail commands. The GUI renders with pdf.js instead.
func NewRenderer ¶ added in v1.0.0
func NewRenderer() *Renderer
NewRenderer creates a MuPDF renderer with no document open.
func (*Renderer) ClosePDF ¶ added in v1.0.0
ClosePDF closes the currently open PDF document and releases resources.
func (*Renderer) GenerateThumbnail ¶ added in v1.0.0
GenerateThumbnail generates a 16:9 cropped thumbnail of the first page as base64 PNG.
func (*Renderer) GetPageCount ¶ added in v1.0.0
GetPageCount returns the total number of pages in the open PDF.
func (*Renderer) GetPageDimensions ¶ added in v1.0.0
func (s *Renderer) GetPageDimensions(pageNum int) (*PageDimensions, error)
GetPageDimensions returns the width and height of a page in PDF points. Holds an exclusive lock because MuPDF's fz_context is not safe for concurrent access — see also GetMetadata.
func (*Renderer) OpenPDFByPath ¶ added in v1.0.0
func (s *Renderer) OpenPDFByPath(filePath string) (*PDFMetadata, error)
OpenPDFByPath opens a PDF file from the given path and returns its metadata.
type SaveTarget ¶ added in v1.0.0
SaveTarget is a destination picked in the Save As dialog.