Code Monkey home page Code Monkey logo

Comments (5)

nathankerr avatar nathankerr commented on August 12, 2024

The example code was meant to be copy-pasted (and then potentially modified).

I am working on a more flexible API that will reduce appendPDF to:

func appendPDF(newPDFfilename string, filenames []string) {
    merged := pdf.New()

    for _, filename := range filenames {
        file, err := pdf.Load(filename)
        if err != nil {
            log.Fatalln(err)
        }

        merged.Catalog.Pages = append(merged.Catalog.Pages, file.Catalog.Pages...)

        err = file.Close()
        if err != nil {
            log.Fatalln(err)
        }
    }

    err := merged.Save(newPDFfilename)
    if err != nil {
        log.Fatalln(err)
    }
}

from pdf.

ottob avatar ottob commented on August 12, 2024

Thanks for creating this project.

Have you made any progress on the new API?

from pdf.

ottob avatar ottob commented on August 12, 2024

I tried to merge two files now and got this error:

$ ./merge -o merge.pdf 34567_1234.pdf Palak_Paneer.pdf 
writing to merge.pdf
panic: %

goroutine 1 [running]:
github.com/nathankerr/pdf.parseObject(0x46f026, 0xd5, 0xd5, 0x0, 0x0, 0x3, 0x0, 0x0)
    /Users/ottob/go/src/github.com/nathankerr/pdf/parse.go:62 +0xd64
github.com/nathankerr/pdf.parseDictionary(0x46f010, 0xeb, 0xeb, 0x0, 0x0, 0x10, 0x0, 0x0)
    /Users/ottob/go/src/github.com/nathankerr/pdf/parse.go:294 +0x8da
github.com/nathankerr/pdf.parseObject(0x46f00e, 0xed, 0xed, 0x0, 0x0, 0xf4, 0x0, 0x0)
    /Users/ottob/go/src/github.com/nathankerr/pdf/parse.go:65 +0x237
github.com/nathankerr/pdf.(*File).parseReferences(0xc820078090, 0xeecf, 0xa, 0x40, 0x0, 0x0)
    /Users/ottob/go/src/github.com/nathankerr/pdf/reference.go:190 +0x1bc8
github.com/nathankerr/pdf.(*File).loadReferences(0xc820078090, 0x0, 0x0)
    /Users/ottob/go/src/github.com/nathankerr/pdf/reference.go:65 +0x748
github.com/nathankerr/pdf.Open(0x7fff5fbffaad, 0xe, 0x2, 0x0, 0x0)
    /Users/ottob/go/src/github.com/nathankerr/pdf/file.go:81 +0x739
main.appendPDF(0x7fff5fbffaa3, 0x9, 0xc82000a120, 0x2, 0x2)
    /Users/ottob/Downloads/merge.go:36 +0x247
main.main()
    /Users/ottob/Downloads/merge.go:23 +0x30d

PDF files I tried to merge:
http://s000.tinyupload.com/index.php?file_id=00126334294857764186

from pdf.

tgulacsi avatar tgulacsi commented on August 12, 2024

Hi!

I've eliminated the panics, but still can't parse the ReportLab-generated pdf - see https://github.com/tgulacsi/pdf/commit/0e1a696e1990c6f16c1d789faff92e17849f3615

from pdf.

ottob avatar ottob commented on August 12, 2024

Thanks for looking at it. But I have switched to using https://github.com/mstamy2/PyPDF2 instead, so no need to spend any more effort on it.

from pdf.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.