dveselov / go-libreofficekit Goto Github PK
View Code? Open in Web Editor NEWCGo bindings to LibreOfficeKit
License: MIT License
CGo bindings to LibreOfficeKit
License: MIT License
I have a problem where i push hundreds of .fodt => .pdf files through this loop and get a ~.5MiB extra memory usage per file and it is not feed (so not gc).
Moving office into the loop explodes the memory usage over time so i'm out of ides. Am i doing something wrong here or is something related to the document not freed on doc.Close()?
type Request struct {
SourceFile string
TargetFile string
TargetExt string
Filter string
done chan bool
}
var request chan *Request
func office() {
office, err := libreofficekit.NewOffice("/usr/lib/libreoffice/program")
if err != nil {
log.Fatal(err)
}
defer office.Close()
for {
select {
case r := <-request:
doc, err := office.LoadDocument(r.SourceFile)
if err != nil {
office.GetError()
r.done <- true
continue
}
defer doc.close()
if err := doc.SaveAs(r.TargetFile, r.TargetExt, r.Filter); err != nil {
r.done <- true
continue
}
r.done <- true
}
}
}
import (
"github.com/dveselov/go-libreofficekit"
"testing"
)
func TestLibreoffice(t *testing.T) {
office, _ := libreofficekit.NewOffice("C:\Program Files\LibreOffice\program\soffice.exe")
document, _ := office.LoadDocument("d:/aa.docx")
document.SaveAs("d:/aa.pdf", "pdf", "skipImages")
document.Close()
office.Close()
}
fatal error: LibreOfficeKit/LibreOfficeKitInit.h: No such file or directory
Hi,
Where can I find the full list of options like "skipImages" as seen in the following code?
document.SaveAs("kittens.pdf", "pdf", "skipImages")
E.x: If I want to embed images into the exported PDF file, which option do I should use?
Thanks
I using a mac but trying to run this inside a docker. While building the app I get the error as shown below.
# github.com/dveselov/go-libreofficekit
In file included from /go/src/github.com/dveselov/go-libreofficekit/libreofficekit.go:6:0:
/go/src/github.com/dveselov/go-libreofficekit/lokbridge.h: In function 'get_views_count':
/go/src/github.com/dveselov/go-libreofficekit/lokbridge.h:70:25: error: 'LibreOfficeKitDocumentClass {aka struct _LibreOfficeKitDocumentClass}' has no member named 'getViewsCount'; did you mean 'getViews'?
return pThis->pClass->getViewsCount(pThis);
hi dve.
How to convert the pdf support chinese ?
func main() {
office, _ := libreofficekit.NewOffice("/usr/lib/libreoffice/program/")
document, _ := office.LoadDocument("test.docx")
document.SaveAs("test.pdf", "pdf", "skipImages")
document.Close()
office.Close()
}
Thanks a lot and look forward to hearing from you soon.
Best Regards,
jjw
Using go-libreofficekit I have this error message coming up:
signal 23 received but handler not on signal stack
fatal error: non-Go code set up signal handler without SA_ONSTACK flag
runtime stack:
runtime: unexpected return pc for runtime.sigtramp called from 0x7f25a7ad1228
stack: frame={sp:0xc000078ed8, fp:0xc000078f30} stack=[0xc000070e08,0xc000079208)
To avoid it I had to recompile libreoffice with the following patch:
diff --git a/sal/osl/unx/signal.cxx b/sal/osl/unx/signal.cxx
index 79721def6c5e..0694fc3c7b26 100644
--- a/sal/osl/unx/signal.cxx
+++ b/sal/osl/unx/signal.cxx
@@ -197,7 +197,7 @@ bool onInitSignal()
struct sigaction act;
act.sa_sigaction = signalHandlerFunction;
- act.sa_flags = SA_RESTART | SA_SIGINFO;
+ act.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK;
sigfillset(&(act.sa_mask));
I will attempt to report the problem to the libreoffice project but meanwhile we have a workaround.
x-MacBook-Pro:cmd apple$ go get -u github.com/dveselov/go-libreofficekit/...
# github.com/dveselov/go-libreofficekit
In file included from ../../../../../dveselov/go-libreofficekit/libreofficekit.go:6:
../../../../../dveselov/go-libreofficekit/lokbridge.h:2:10: fatal error: 'LibreOfficeKit/LibreOfficeKitInit.h' file not found
#include "LibreOfficeKit/LibreOfficeKitInit.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
the path should be the docx path or others?
pull the docxPath will export the nil pointers:
root@800-180329-PC:/usr/local/GoWorkspace# go run packageMain.go
installation path "usr/local/GoWorkspace/" does not exist
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x488ec3]
goroutine 1 [running]:
_/usr/local/GoWorkspace/libreofficekit.(*Office).LoadDocument(0x0, 0x4bc8db, 0x9, 0x0, 0x0, 0x0)
/usr/local/GoWorkspace/libreofficekit/libreofficekit.go:78 +0x93
main.main()
/usr/local/GoWorkspace/packageMain.go:7 +0x62
exit status 2
root@800-180329-PC:/usr/local/GoWorkspace#
the docx path is :/usr/local/GoWorkspace/test.docx
root@800-180329-PC:/usr/local/GoWorkspace# ls
libreofficekit packageMain.go packageMain.sublime-workspace test.docx
thankyou!!!
hi dve.
Why I exchanging words in word but converted pdf always same at all.
But when I restart Ubuntu,the program convert the new pdf what I exchanging words.
If the Ubuntu does not restart.How to solve this problem.
func main() {
office, _ := libreofficekit.NewOffice("/usr/lib/libreoffice/program/")
document, _ := office.LoadDocument("test.docx")
document.SaveAs("test.pdf", "pdf", "skipImages")
document.Close()
office.Close()
}
Thanks a lot and look forward to hearing from you soon.
Best Regards,
jjw
Went to build this but realised the c files are missing.
Is there a link to them somewhere?
Hi ...
I tried to install this nice go pkg on my debian stable, that uses libreofficekit-dev 5.2.7
, but this error happend.
./lokbridge.h: In function 'get_views_count':
./lokbridge.h:70:25: error: 'LibreOfficeKitDocumentClass {aka struct _LibreOfficeKitDocumentClass}' has no member named 'getViewsCount'; did you mean 'getViews'?
return pThis->pClass->getViewsCount(pThis);
^~
What versions are needed of this lib in order to make this compile ?
When I use document.SaveAs with "pdf" as the extension (and a .docx as the input file), the URL links are stripped:
// SaveAs saves document at desired path in desired format with applied filter rules
// Actual (from libreoffice) error message can be read with Office.GetError
func (document *Document) SaveAs(path string, format string, filter string) error {
cPath := C.CString(path)
defer C.free(unsafe.Pointer(cPath))
cFormat := C.CString(format)
defer C.free(unsafe.Pointer(cFormat))
cFilter := C.CString(filter)
defer C.free(unsafe.Pointer(cFilter))
status := C.document_save(document.handle, cPath, cFormat, cFilter)
if status != 1 {
return fmt.Errorf("Failed to save document")
}
return nil
}
Is it possible to retain these with a filter option?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.