### Initialize Kepub Converter with Options Source: https://context7.com/pgaskin/kepubify/llms.txt Demonstrates how to instantiate a new converter using NewConverterWithOptions. This example shows how to combine multiple configuration options such as smart punctuation, CSS, and find/replace rules to process an EPUB file. ```go package main import ( "context" "os" "github.com/pgaskin/kepubify/v4/kepub" "github.com/pgaskin/kepubify/v4/internal/zip" ) func main() { converter := kepub.NewConverterWithOptions( kepub.ConverterOptionSmartypants(), kepub.ConverterOptionHyphenate(true), kepub.ConverterOptionAddCSS("body { font-family: Georgia; }"), kepub.ConverterOptionFindReplace("oldtext", "newtext"), kepub.ConverterOptionFullScreenFixes(), kepub.ConverterOptionCharset("auto"), ) input, err := zip.OpenReader("book.epub") if err != nil { panic(err) } defer input.Close() output, err := os.Create("book.kepub.epub") if err != nil { panic(err) } defer output.Close() if err := converter.Convert(context.Background(), output, input); err != nil { panic(err) } } ``` -------------------------------- ### Perform Full EPUB to KEPUB Conversion Source: https://context7.com/pgaskin/kepubify/llms.txt A comprehensive example of converting an EPUB file to KEPUB using custom options like Smartypants and hyphenation. It includes best practices for atomic file writing and error handling. ```go package main import ( "context" "fmt" "os" "path/filepath" "github.com/pgaskin/kepubify/v4/kepub" "github.com/pgaskin/kepubify/v4/internal/zip" ) func convertEPUB(inputPath, outputPath string) error { converter := kepub.NewConverterWithOptions( kepub.ConverterOptionSmartypants(), kepub.ConverterOptionHyphenate(true), kepub.ConverterOptionAddCSS(`body { font-family: Georgia, serif; line-height: 1.5; }`), kepub.ConverterOptionCharset("auto"), ) input, err := zip.OpenReader(inputPath) if err != nil { return fmt.Errorf("failed to open input: %w", err) } defer input.Close() tmpFile, err := os.CreateTemp(filepath.Dir(outputPath), ".kepubify.*") if err != nil { return fmt.Errorf("failed to create temp file: %w", err) } tmpPath := tmpFile.Name() defer os.Remove(tmpPath) if err := converter.Convert(context.Background(), tmpFile, input); err != nil { tmpFile.Close() return fmt.Errorf("conversion failed: %w", err) } tmpFile.Sync() tmpFile.Close() return os.Rename(tmpPath, outputPath) } ``` -------------------------------- ### Convert EPUB to KEPUB using CLI Source: https://context7.com/pgaskin/kepubify/llms.txt Demonstrates various command-line options for the kepubify tool, including output naming, directory flattening, and incremental conversion. ```bash kepubify -o mybook.kepub.epub book.epub kepubify -i book.epub kepubify --no-preserve-dirs /nested/ebooks/ kepubify --calibre book.epub kepubify -x .pdf -x .mobi /ebooks/ kepubify -u /ebooks/ -o /output/ ``` -------------------------------- ### Generate Kobo Book Covers via CLI Source: https://context7.com/pgaskin/kepubify/llms.txt Shows how to use the covergen tool to pre-generate thumbnails for Kobo eReaders, including options for resizing, grayscale conversion, and color inversion. ```bash covergen covergen /media/kobo covergen -r covergen -m lanczos2 covergen -a 1.5 covergen -g covergen -i covergen -r -g -m bicubic /media/kobo ``` -------------------------------- ### kepubify CLI - Output Options Source: https://context7.com/pgaskin/kepubify/llms.txt Control output file naming, directory structure, and Calibre compatibility. ```APIDOC ## kepubify CLI - Output Options ### Description Control output file naming, directory structure, and Calibre compatibility. ### Options - `-o ` or `--output `: Output to specific directory. ### Examples ```bash # Output to specific directory kepubify -o /converted/ book.epub ``` ``` -------------------------------- ### kepubify CLI Conversion Options Source: https://context7.com/pgaskin/kepubify/llms.txt Apply transformation options during conversion including smart punctuation, custom CSS, hyphenation, and text replacement. ```bash # Enable smart punctuation (curly quotes, proper dashes) kepubify --smarten-punctuation book.epub # Add custom CSS to the book kepubify -c "body { font-size: 1.1em; }" book.epub # Add CSS from a file kepubify -c "$(cat custom.css)" book.epub # Enable hyphenation kepubify --hyphenate book.epub # Disable hyphenation kepubify --no-hyphenate book.epub # Find and replace text (format: find|replace) kepubify -r "oldtext|newtext" book.epub # Multiple replacements kepubify -r "foo|bar" -r "baz|qux" book.epub # Apply fullscreen reading fixes for older firmware kepubify --fullscreen-reading-fixes book.epub # Auto-detect charset for encoding issues kepubify --charset auto book.epub # Combine multiple options kepubify --smarten-punctuation --hyphenate \ -c "body { margin: 1em; }" \ -r "OldName|NewName" \ book.epub ``` -------------------------------- ### Filter Files with TransformFileFilter Source: https://context7.com/pgaskin/kepubify/llms.txt Demonstrates how to use the TransformFileFilter method to identify and exclude unnecessary metadata files like macOS .DS_STORE or Windows thumbs.db from the EPUB conversion process. ```go package main import ( "fmt" "github.com/pgaskin/kepubify/v4/kepub" ) func main() { converter := kepub.NewConverter() filesToFilter := []string{ "calibre_bookmarks.txt", "iTunesMetadata.plist", "iTunesArtwork.plist", ".DS_STORE", "thumbs.db", "__MACOSX/anything.txt", } for _, f := range filesToFilter { filtered := converter.TransformFileFilter(f) fmt.Printf("%-30s -> filtered: %v\n", f, filtered) } } ``` -------------------------------- ### kepubify CLI Output Options Source: https://context7.com/pgaskin/kepubify/llms.txt Control output file naming and directory structure. ```bash # Output to specific directory kepubify -o /converted/ book.epub ``` -------------------------------- ### Convert EPUB to KEPUB (Go) Source: https://context7.com/pgaskin/kepubify/llms.txt Converts an EPUB filesystem to KEPUB format, writing the result to an io.Writer. Supports zip.Reader input and any fs.FS implementation. ```go package main import ( "context" "io/fs" "os" "github.com/pgaskin/kepubify/v4/kepub" "github.com/pgaskin/kepubify/v4/internal/zip" ) func convertFromZip() error { converter := kepub.NewConverter() // Open EPUB as zip (preserves original metadata, more efficient) input, err := zip.OpenReader("input.epub") if err != nil { return err } defer input.Close() output, err := os.Create("output.kepub.epub") if err != nil { return err } defer output.Close() // Convert with context for cancellation support ctx := context.Background() return converter.Convert(ctx, output, input) } func convertFromFS(inputFS fs.FS) error { converter := kepub.NewConverter() output, err := os.Create("output.kepub.epub") if err != nil { return err } defer output.Close() // Convert from any fs.FS implementation (e.g., embed.FS, os.DirFS) return converter.Convert(context.Background(), output, inputFS) } ``` -------------------------------- ### kepubify CLI - Conversion Options Source: https://context7.com/pgaskin/kepubify/llms.txt Apply transformation options during conversion including smart punctuation, custom CSS, hyphenation, and text replacement. ```APIDOC ## kepubify CLI - Conversion Options ### Description Apply transformation options during conversion including smart punctuation, custom CSS, hyphenation, and text replacement. ### Options - `--smarten-punctuation`: Enable smart punctuation (curly quotes, proper dashes). - `-c ""` or `--css ""`: Add custom CSS to the book. - `--hyphenate`: Enable hyphenation. - `--no-hyphenate`: Disable hyphenation. - `-r "|"` or `--replace "|"`: Find and replace text. - `--fullscreen-reading-fixes`: Apply fullscreen reading fixes for older firmware. - `--charset `: Auto-detect charset for encoding issues (e.g., `auto`, `utf-8`). ### Examples ```bash # Enable smart punctuation kepubify --smarten-punctuation book.epub # Add custom CSS to the book kepubify -c "body { font-size: 1.1em; }" book.epub # Add CSS from a file kepubify -c "$(cat custom.css)" book.epub # Enable hyphenation kepubify --hyphenate book.epub # Disable hyphenation kepubify --no-hyphenate book.epub # Find and replace text (format: find|replace) kepubify -r "oldtext|newtext" book.epub # Multiple replacements kepubify -r "foo|bar" -r "baz|qux" book.epub # Apply fullscreen reading fixes for older firmware kepubify --fullscreen-reading-fixes book.epub # Auto-detect charset for encoding issues kepubify --charset auto book.epub # Combine multiple options kepubify --smarten-punctuation --hyphenate \ -c "body { margin: 1em; }" \ -r "OldName|NewName" \ book.epub ``` ``` -------------------------------- ### Update Series Metadata via CLI Source: https://context7.com/pgaskin/kepubify/llms.txt Explains how to use the seriesmeta tool to synchronize series information from EPUB metadata to the Kobo database. ```bash seriesmeta seriesmeta /media/kobo seriesmeta -n seriesmeta -p seriesmeta -u ``` -------------------------------- ### kepubify CLI - Basic Conversion Source: https://context7.com/pgaskin/kepubify/llms.txt The `kepubify` command converts EPUB files to KEPUB format. Supports single files, multiple files, and directories. ```APIDOC ## kepubify CLI - Basic Conversion ### Description The `kepubify` command converts EPUB files to KEPUB format. Supports single files, multiple files, and directories. ### Usage `kepubify [options] ` ### Examples ```bash # Convert a single EPUB file (creates book_converted.kepub.epub) kepubify book.epub # Convert multiple files kepubify book1.epub book2.epub book3.epub # Convert all EPUBs in a directory kepubify /path/to/ebooks/ # Convert to specific output directory kepubify -o /output/dir/ book.epub # Convert in-place (no _converted suffix) kepubify -i book.epub # Skip already converted files kepubify -u /path/to/ebooks/ # Verbose output showing source and destination kepubify -v book.epub ``` ``` -------------------------------- ### Basic kepubify CLI Conversion Source: https://context7.com/pgaskin/kepubify/llms.txt The `kepubify` command converts EPUB files to KEPUB format. It supports single files, multiple files, and directories. ```bash # Convert a single EPUB file (creates book_converted.kepub.epub) kepubify book.epub # Convert multiple files kepubify book1.epub book2.epub book3.epub # Convert all EPUBs in a directory kepubify /path/to/ebooks/ # Convert to specific output directory kepubify -o /output/dir/ book.epub # Convert in-place (no _converted suffix) kepubify -i book.epub # Skip already converted files kepubify -u /path/to/ebooks/ # Verbose output showing source and destination kepubify -v book.epub ``` -------------------------------- ### Converter.Convert Source: https://context7.com/pgaskin/kepubify/llms.txt Converts an EPUB filesystem to KEPUB format, writing the result to an io.Writer. Supports both zip.Reader input (preserving metadata) and any fs.FS implementation. ```APIDOC ## Converter.Convert ### Description Converts an EPUB filesystem to KEPUB format, writing the result to an io.Writer. Supports both zip.Reader input (preserving metadata) and any fs.FS implementation. ### Method `converter.Convert(ctx context.Context, output io.Writer, input io.ReaderAt, size int64) error` or `converter.Convert(ctx context.Context, output io.Writer, input fs.FS) error` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **ctx** (context.Context) - Required - Context for cancellation support. - **output** (io.Writer) - Required - The writer to write the KEPUB output to. - **input** (io.ReaderAt or fs.FS) - Required - The EPUB input, either as a zip.Reader or any fs.FS implementation. ### Request Example ```go // Convert from zip.Reader input, err := zip.OpenReader("input.epub") // ... handle error ... defer input.Close() output, err := os.Create("output.kepub.epub") // ... handle error ... defer output.Close() ctx := context.Background() err = converter.Convert(ctx, output, input) // Convert from fs.FS err = converter.Convert(context.Background(), output, inputFS) ``` ### Response #### Success Response (200) - **error** (error) - `nil` if conversion is successful. #### Response Example `nil` on success. ``` -------------------------------- ### Inject Custom CSS Source: https://context7.com/pgaskin/kepubify/llms.txt Demonstrates how to use ConverterOptionAddCSS to inject custom styles into the EPUB content. Multiple calls can be used to add distinct style blocks. ```go package main import "github.com/pgaskin/kepubify/v4/kepub" func main() { converter := kepub.NewConverterWithOptions( kepub.ConverterOptionAddCSS(` body { font-family: "Bookerly", Georgia, serif; line-height: 1.6; } p { text-indent: 1.5em; margin: 0; } `), kepub.ConverterOptionAddCSS(` h1, h2, h3 { page-break-after: avoid; } `), ) _ = converter } ``` -------------------------------- ### Converter.Convert Source: https://context7.com/pgaskin/kepubify/llms.txt Performs a full EPUB to KEPUB conversion using configured options and input/output streams. ```APIDOC ## METHOD Convert ### Description Converts an EPUB file to KEPUB format using the configured converter settings. Supports custom CSS, smartypants, and hyphenation. ### Method Go Method Call ### Parameters #### Request Body - **ctx** (context.Context) - Required - Execution context. - **output** (io.Writer) - Required - Destination for the converted KEPUB. - **input** (zip.Reader) - Required - Source EPUB file reader. ### Request Example converter.Convert(context.Background(), outputWriter, inputReader) ### Response #### Success Response (200) - **error** (nil) - Returns nil on successful conversion. #### Error Response (500) - **error** (error) - Returns an error if the conversion process fails. ``` -------------------------------- ### Transform HTML Content for KEPUB Source: https://context7.com/pgaskin/kepubify/llms.txt Programmatically transform HTML content for KEPUB using the kepub Go library. This applies Kobo-specific styling hacks and smart punctuation. ```go package main import ( "bytes" "os" "strings" "github.com/pgaskin/kepubify/v4/kepub" ) func main() { converter := kepub.NewConverterWithOptions( kepub.ConverterOptionSmartypants(), ) htmlContent := ` Chapter 1

Chapter 1

This is the "first" paragraph -- with some text.

Another paragraph here.

` var output bytes.Buffer err := converter.TransformContent(&output, strings.NewReader(htmlContent)) if err != nil { panic(err) } os.Stdout.Write(output.Bytes()) } ``` -------------------------------- ### Transform OPF Metadata for KEPUB Source: https://context7.com/pgaskin/kepubify/llms.txt Programmatically transform OPF package documents to meet KEPUB requirements, such as adding EPUB3 cover properties and cleaning metadata. ```go package main import ( "bytes" "os" "strings" "github.com/pgaskin/kepubify/v4/kepub" ) func main() { converter := kepub.NewConverter() opfContent := ` ` var output bytes.Buffer err := converter.TransformOPF(&output, strings.NewReader(opfContent)) if err != nil { panic(err) } os.Stdout.Write(output.Bytes()) } ``` -------------------------------- ### Apply Fullscreen Reading Fixes (Go) Source: https://context7.com/pgaskin/kepubify/llms.txt This option applies CSS fixes for fullscreen reading on older Kobo firmware versions. It adjusts body margins and padding for better display. ```go package main import "github.com/pgaskin/kepubify/v4/kepub" func main() { // Apply fullscreen reading fixes for older Kobo devices converter := kepub.NewConverterWithOptions( kepub.ConverterOptionFullScreenFixes(), ) _ = converter } ``` -------------------------------- ### Configure Hyphenation Source: https://context7.com/pgaskin/kepubify/llms.txt Shows how to toggle hyphenation globally using ConverterOptionHyphenate, which applies CSS hyphenation rules to the document content. ```go package main import "github.com/pgaskin/kepubify/v4/kepub" func main() { converterWithHyphen := kepub.NewConverterWithOptions( kepub.ConverterOptionHyphenate(true), ) converterNoHyphen := kepub.NewConverterWithOptions( kepub.ConverterOptionHyphenate(false), ) _, _ = converterWithHyphen, converterNoHyphen } ``` -------------------------------- ### Perform Find and Replace Source: https://context7.com/pgaskin/kepubify/llms.txt Utilizes ConverterOptionFindReplace to perform raw string substitutions on the HTML output, useful for fixing encoding issues or removing unwanted elements. ```go package main import "github.com/pgaskin/kepubify/v4/kepub" func main() { converter := kepub.NewConverterWithOptions( kepub.ConverterOptionFindReplace("’", "'"), kepub.ConverterOptionFindReplace("â€", "—"), kepub.ConverterOptionFindReplace("OldPublisher", "NewPublisher"), kepub.ConverterOptionFindReplace(``, ""), ) _ = converter } ``` -------------------------------- ### Enable Smart Punctuation Source: https://context7.com/pgaskin/kepubify/llms.txt Uses ConverterOptionSmartypants to automatically convert straight quotes to curly quotes and hyphens to proper dashes, while respecting code and pre tags. ```go package main import "github.com/pgaskin/kepubify/v4/kepub" func main() { converter := kepub.NewConverterWithOptions( kepub.ConverterOptionSmartypants(), ) _ = converter } ``` -------------------------------- ### ConverterOptionFullScreenFixes Source: https://context7.com/pgaskin/kepubify/llms.txt Applies CSS fixes for fullscreen reading on older Kobo firmware versions (before 4.19.11911). This adjusts body margins and padding for proper display. ```APIDOC ## kepub.ConverterOptionFullScreenFixes ### Description Applies CSS fixes for fullscreen reading on older Kobo firmware versions (before 4.19.11911). This adjusts body margins and padding for proper display. ### Method `kepub.NewConverterWithOptions` with `kepub.ConverterOptionFullScreenFixes()` ### Parameters None ### Request Example ```go converter := kepub.NewConverterWithOptions( kepub.ConverterOptionFullScreenFixes(), ) ``` ### Response N/A (This is a constructor option) ``` -------------------------------- ### Control Dummy Titlepage Fix (Go) Source: https://context7.com/pgaskin/kepubify/llms.txt This option controls the dummy titlepage fix, which resolves layout issues in the first content file. It can be forced enabled or disabled. ```go package main import "github.com/pgaskin/kepubify/v4/kepub" func main() { // Force add dummy titlepage for books with layout issues converterWithTitlepage := kepub.NewConverterWithOptions( kepub.ConverterOptionDummyTitlepage(true), ) // Force disable dummy titlepage converterNoTitlepage := kepub.NewConverterWithOptions( kepub.ConverterOptionDummyTitlepage(false), ) _, _ = converterWithTitlepage, converterNoTitlepage } ``` -------------------------------- ### ConverterOptionCharset Source: https://context7.com/pgaskin/kepubify/llms.txt Overrides the HTML charset for all content documents. Use "auto" to automatically detect the charset from content, or specify a specific charset like "utf-8" or "windows-1252". ```APIDOC ## kepub.ConverterOptionCharset ### Description Overrides the HTML charset for all content documents. Use "auto" to automatically detect the charset from content, or specify a specific charset like "utf-8" or "windows-1252". ### Method `kepub.NewConverterWithOptions` with `kepub.ConverterOptionCharset(string)` ### Parameters #### Request Body - **charset** (string) - Required - The charset to use (e.g., "auto", "utf-8", "windows-1252"). ### Request Example ```go converterAuto := kepub.NewConverterWithOptions( kepub.ConverterOptionCharset("auto"), ) converterLatin := kepub.NewConverterWithOptions( kepub.ConverterOptionCharset("windows-1252"), ) ``` ### Response N/A (This is a constructor option) ``` -------------------------------- ### ConverterOptionDummyTitlepage Source: https://context7.com/pgaskin/kepubify/llms.txt Controls the dummy titlepage fix that prevents layout issues with the first content file. By default, a heuristic determines if this is needed; use this option to force enable or disable. ```APIDOC ## kepub.ConverterOptionDummyTitlepage ### Description Controls the dummy titlepage fix that prevents layout issues with the first content file. By default, a heuristic determines if this is needed; use this option to force enable or disable. ### Method `kepub.NewConverterWithOptions` with `kepub.ConverterOptionDummyTitlepage(bool)` ### Parameters #### Request Body - **enable** (bool) - Required - `true` to force enable, `false` to force disable. ### Request Example ```go converterWithTitlepage := kepub.NewConverterWithOptions( kepub.ConverterOptionDummyTitlepage(true), ) converterNoTitlepage := kepub.NewConverterWithOptions( kepub.ConverterOptionDummyTitlepage(false), ) ``` ### Response N/A (This is a constructor option) ``` -------------------------------- ### Converter.TransformFileFilter Source: https://context7.com/pgaskin/kepubify/llms.txt Determines which files should be excluded from the output EPUB, such as metadata files and system thumbnails. ```APIDOC ## METHOD TransformFileFilter ### Description Filters out unnecessary files from the EPUB archive, including Calibre bookmarks, iBooks metadata, and macOS/Windows system files. ### Method Go Method Call ### Parameters #### Path Parameters - **filename** (string) - Required - The name of the file to check for filtering. ### Request Example converter.TransformFileFilter("iTunesMetadata.plist") ### Response #### Success Response (200) - **filtered** (boolean) - Returns true if the file should be excluded, false otherwise. ``` -------------------------------- ### Override HTML Charset (Go) Source: https://context7.com/pgaskin/kepubify/llms.txt This option overrides the HTML charset for all content documents. Use 'auto' for automatic detection or specify a charset like 'utf-8'. ```go package main import "github.com/pgaskin/kepubify/v4/kepub" func main() { // Auto-detect charset (useful for books with wrong encoding declarations) converterAuto := kepub.NewConverterWithOptions( kepub.ConverterOptionCharset("auto"), ) // Force specific charset for legacy books converterLatin := kepub.NewConverterWithOptions( kepub.ConverterOptionCharset("windows-1252"), ) _, _ = converterAuto, converterLatin } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.