pdftops

package module
v0.0.0-...-d6c9d58 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: GPL-2.0 Imports: 11 Imported by: 0

README

Convert PDF to PS in cgo-less portable go, just with WASM+wazero.

It's one part of PDF-to-PDF/A conversion.

Note that the code writes to filesystem for temporary files; the local filesystem should not be full or read-only.

How to use

See example_test.go

package main

import (
    "context"
    "fmt"

    pdftops "github.com/karelbilek/pdftops-wazero"
)

func main() {
	in, err := os.ReadFile("some.pdf")
	if err != nil {
		panic(err)
	}

	out, err := pdftops.ConvertPDFToPS(context.Background(), in)
	if err != nil {
		panic(err)
	}

	err = os.WriteFile("someout.ps", out, 0o666)
	if err != nil {
		panic(err)
	}
}


(C) 2023 Karel Bilek, Jeroen Bobbeldijk (https://github.com/jerbob92)

xpdfreader (C) 1996-2022 Glyph & Cog, LLC. (from https://www.xpdfreader.com/download.html )

ghostscript fonts Copyright (c) 2001- Valek Filippov (from https://packages.ubuntu.com/focal/gsfonts)

The whole code is GPLv2.

How to build the WASM

  • git submodule update --init
  • install docker
  • cd build && ./build.sh on a Unix-like environment (WSL might work too if it has access to the Docker)
    • note - it might take a bit of time on the CMake step
  • in build/out/pdftops.wasm there is the compiled wasm file

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertPDFToPS

func ConvertPDFToPS(ctx context.Context, in []byte) ([]byte, error)
Example
package main

import (
	"context"
	"fmt"
	"os"

	pdftops "github.com/karelbilek/pdftops-wazero"
)

func main() {
	in, err := os.ReadFile("some.pdf")
	if err != nil {
		panic(err)
	}

	out, err := pdftops.ConvertPDFToPS(context.Background(), in)
	if err != nil {
		panic(err)
	}

	err = os.WriteFile("someout.ps", out, 0o666)
	if err != nil {
		panic(err)
	}

	fmt.Println("success")
}
Output:

success

Types

This section is empty.

Jump to

Keyboard shortcuts

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