Bugzilla – Attachment 147154 Details for
Bug 121808
LibreOfficeKit saveAs options fails for PDF export filter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
My ugly lokit test application
main.cc (text/x-c++src), 3.24 KB, created by
jghadsrf
on 2018-11-29 17:10:41 UTC
(
hide
)
Description:
My ugly lokit test application
Filename:
MIME Type:
Creator:
jghadsrf
Created:
2018-11-29 17:10:41 UTC
Size:
3.24 KB
patch
obsolete
>/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ >/* > * main.cc > * Quick hack based on https://gitlab.com/ojwb/lloconv/ > */ > >#include <iostream> >#include <LibreOfficeKit/LibreOfficeKit.hxx> >#include "LibreOfficeKit/LibreOfficeKitInit.h" >#include "LibreOfficeKit/LibreOfficeKit.h" > >using namespace std; >using namespace lok; > >// Install location for my Fedora: >#define LO_PATH_FEDORA "/usr/lib64/libreoffice/program/" > >const char * program = "<program>"; > >// Find a LibreOffice installation to use. >static const char * >get_lo_path() >{ > const char * lo_path = getenv("LO_PATH"); > if (!lo_path) { > struct stat sb; >#define CHECK_DIR(P) if (!lo_path && stat(P"/versionrc", &sb) == 0 && S_ISREG(sb.st_mode)) lo_path = P > CHECK_DIR(LO_PATH_FEDORA); > > if (!lo_path) { > cerr << program << ": LibreOffice install not found\n" > "Set LO_PATH in the environment to the 'program' directory - e.g.:\n" > "LO_PATH=/opt/libreoffice/program\n" > "export LO_PATH" << endl; > _Exit(1); > } > } > return lo_path; >} > >void >url_encode_(string & res, const char * p, size_t len, const char * safe) >{ > while (len--) { > unsigned char ch = *p++; > if (isalnum(ch) || strchr(safe, ch)) { > // Unreserved by RFC3986. > res += ch; > } else { > // RFC3986 says we "should" encode as upper case hex digits. > res += '%'; > res += "0123456789ABCDEF"[ch >> 4]; > res += "0123456789ABCDEF"[ch & 0x0f]; > } > } >} > >inline void >url_encode_path(std::string & res, const std::string &str) >{ > url_encode_(res, str.data(), str.size(), "/-._~"); >} > > >void * >convert_init() >{ > Office * llo = NULL; > try { > const char * lo_path = get_lo_path(); > llo = lok_cpp_init(lo_path); > if (!llo) { > cerr << program << ": Failed to initialise LibreOfficeKit" << endl; > return NULL; > } > return static_cast<void*>(llo); > } catch (const exception & e) { > delete llo; > cerr << program << ": LibreOfficeKit threw exception (" << e.what() << ")" << endl; > return NULL; > } >} > > >void >convert_cleanup(void * h_void) >{ > Office * llo = static_cast<Office *>(h_void); > delete llo; >} > > >int >convert(void * h_void, bool url, > const char * input, const char * output, > const char * format, const char * options) >try { > if (!h_void) return 1; > Office * llo = static_cast<Office *>(h_void); > > string input_url; > if (url) { > input_url = input; > } else { > url_encode_path(input_url, input); > } > Document * lodoc = llo->documentLoad(input_url.c_str(), options); > if (!lodoc) { > const char * errmsg = llo->getError(); > cerr << program << ": LibreOfficeKit failed to load document (" << errmsg << ")" << endl; > return 1; > } > > string output_url; > url_encode_path(output_url, output); > if (!lodoc->saveAs(output_url.c_str(), format, options)) { > const char * errmsg = llo->getError(); > cerr << program << ": LibreOfficeKit failed to export (" << errmsg << ")" << endl; > delete lodoc; > return 1; > } > > delete lodoc; > > return 0; >} catch (const exception & e) { > cerr << program << ": LibreOfficeKit threw exception (" << e.what() << ")" << endl; > return 1; >} > > >int main() >{ > void *llo = convert_init(); > bool result = convert(llo, false, "test.docx", "test.pdf", "pdf", "SelectPdfVersion=1"); > std::cout << result << std::endl; > convert_cleanup(llo); > return 0; >} >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 121808
: 147154