pdf

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinDPI              = 10.0
	MaxDPI              = 600.0
	PDFOpenTimeout      = 120 * time.Second
	PDFRenderTimeout    = 300 * time.Second
	MaxPDFFileSizeBytes = 1 * 1024 * 1024 * 1024 // 1GB maximum file size
)
View Source
const (
	DefaultMaxRecentFiles = 20
)

Variables

This section is empty.

Functions

func RestoreMuPDFWarnings

func RestoreMuPDFWarnings()

RestoreMuPDFWarnings restores MuPDF warnings output

func SuppressMuPDFWarnings

func SuppressMuPDFWarnings()

SuppressMuPDFWarnings redirects MuPDF warnings to /dev/null

Types

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 handles all PDF operations including opening, rendering, and metadata extraction. It uses go-fitz for PDF rendering and maintains thread-safe access to the current document.

func NewPDFService

func NewPDFService(configService *config.Service) *PDFService

NewPDFService creates a new PDF service instance.

func (*PDFService) ClosePDF

func (s *PDFService) ClosePDF() error

ClosePDF closes the currently open PDF document and releases resources.

func (*PDFService) GenerateThumbnail

func (s *PDFService) GenerateThumbnail(filePath string, maxWidth int) (string, error)

GenerateThumbnail generates a 16:9 cropped thumbnail of the first page as base64 PNG.

func (*PDFService) GetMetadata

func (s *PDFService) GetMetadata() (*PDFMetadata, error)

GetMetadata returns title, author, and other metadata for the open PDF.

func (*PDFService) GetPageCount

func (s *PDFService) GetPageCount() int

GetPageCount returns the total number of pages in the open PDF.

func (*PDFService) GetPageDimensions

func (s *PDFService) GetPageDimensions(pageNum int) (*PageDimensions, error)

GetPageDimensions returns the width and height of a page in PDF points.

func (*PDFService) OpenPDF

func (s *PDFService) OpenPDF() (*PDFMetadata, error)

OpenPDF shows a file dialog, opens the selected PDF, and returns its metadata.

func (*PDFService) OpenPDFByPath

func (s *PDFService) OpenPDFByPath(filePath string) (*PDFMetadata, error)

OpenPDFByPath opens a PDF file from the given path and returns its metadata.

func (*PDFService) RenderPage

func (s *PDFService) RenderPage(pageNum int, dpi float64) (*PageInfo, error)

RenderPage renders the specified page at the given DPI and returns base64-encoded PNG data.

func (*PDFService) Startup

func (s *PDFService) Startup(ctx context.Context)

Startup stores the app context and configures MuPDF. Called by Wails on app start.

type PageDimensions

type PageDimensions struct {
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

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) Shutdown

func (s *RecentFilesService) Shutdown(timeout time.Duration) error

Shutdown waits for pending saves to complete with the given timeout.

func (*RecentFilesService) Startup

func (s *RecentFilesService) Startup(ctx context.Context)

Startup loads persisted recent files. Called by Wails on app start.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL