pdf

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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.

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
)
View Source
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

func DecodePNGDataURL(s string) ([]byte, error)

DecodePNGDataURL returns the raw PNG bytes of the data URLs RenderPage and GenerateThumbnail produce.

Types

type ConflictError added in v1.0.0

type ConflictError struct {
	Reason string `json:"conflict"`
	Path   string `json:"path"`
}

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

func (s *PDFService) SavePDF(id string, data []byte, overwrite bool) (*Document, error)

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

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) ServiceStartup added in v1.0.0

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

func (*RecentFilesService) Shutdown

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

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

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

func (s *Renderer) ClosePDF() error

ClosePDF closes the currently open PDF document and releases resources.

func (*Renderer) GenerateThumbnail added in v1.0.0

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

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

func (*Renderer) GetPageCount added in v1.0.0

func (s *Renderer) GetPageCount() int

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.

func (*Renderer) RenderPage added in v1.0.0

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

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

type SaveTarget added in v1.0.0

type SaveTarget struct {
	Path   string `json:"path"`
	Exists bool   `json:"exists"`
}

SaveTarget is a destination picked in the Save As dialog.

Jump to

Keyboard shortcuts

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