How to get NReco.PdfGenerator.LT working with Linux binaries? - linux

I'm using NReco.PdfGenerator.LT to create a PDF document from a HTML page. This works fine on windows if I just point it at the wkhtmltopdf.exe executable, but this does not have the same effect on Linux.
HtmlToPdfConverter cvt = new HtmlToPdfConverter();
cvt.PdfToolPath = GetPdfToolPath();
// Windows: <current-dir>\wkhtmltopdf\win32\bin
// Linux: <current-dir>/wkhtmltopdf/linux/bin
cvt.WkHtmlToPdfExeName = GetPdfToolName();
// Windows: wkhtmltopdf.exe
// Linux: wkhtmltopdf
I just get this error:
Cannot generate PDF: Permission denied

Possible reasons of this error:
linux user who starts .net core program has no permissions to run "wkhtmltopdf". Also ensure that "wkhtmltopdf" file is marked as "executable" (x).
sometimes temp folder returned by Path.GetTempPath() is not accessible; another location for temp files may be specified with HtmlToPdfConverter.TempFilesPath property

Related

Writing file denied

I am getting an error writing a file, that is driving me crazy.
I have an C# netcore 5 application running on RH Linux.
I mounted an shared folder (windows) using: sudo mount -t cifs -o username=MyDomainUsername,password=MyDomainUsernamePassword,domain=MyDomain,dir_mode=0777,file_mode=0777 //ipv4_from_destination/Reports /fileshare/Reports
Then I run the app, using just ./WebApi --urls=http://+:8060
The read/write test executes the following steps:
Create a text file.
Write the text file.
Delete de text file.
Creates a directory
Creates a text file inside that directory
Writes the text file
Deletes the text file
Deletes the directory.
Now the problem:
The text file is created
The write operation fails.
Where goes part of the log:
Creating file: /fileshare/Reports/test.616db7d1-07fb-4599-a0cf-749e6a8b34ec.tmp...Ok
Writing file: /fileshare/Reports/test.616db7d1-07fb-4599-a0cf-749e6a8b34ec.tmp...[16:22:20 ERR] ID:87988856-a765-4474-9ed9-2f04aef35771 PATH:/api/about ERROR:System.UnauthorizedAccessException:Access to the path '/fileshare/Reports/test.616db7d1-07fb-4599-a0cf-749e6a8b34ec.tmp' is denied. TRACE: at System.IO.FileStream.WriteNative(ReadOnlySpan`1 source)
at System.IO.FileStream.FlushWriteBuffer()
at System.IO.FileStream.FlushInternalBuffer()
at System.IO.FileStream.Flush(Boolean flushToDisk)
at System.IO.FileStream.Flush()
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Flush()
at WebApi.Controllers.ApplicationController.TestFileSystem(String folder) in xxxxxxx\WebApi\Controllers\ApplicationController.cs:line 116
What I discovered so far:
I can create and delete the files and directories.
I cannot write to files.
Can someone give me an hint on this?
Solved using the cifs option nobrl

Nodejs fs.copyfile not allowed for copy a file to the destination folder

I am trying to copy a file from one location to another so I'm using this:
fs.copyFile('C:\\Users\\Me\\Documents\\myfile.zip', c:\\myfiles
console.log('file was copied successfully!');
});
I can see that the destination folder is readonly so that's why I'm getting this.
How can I change it's status on my windows pc.
I've tried this but nothing is happening and I still get the error:
fs.chmodSync('c:\\myfiles', 0o755);
How can I fix this issue?
You are using Windows, I guest C:\ is your system disk (where you install the Windows).
If you want to write a file to c:\myfiles , it require you Administrator permission (you can try by way: copy and paste a file to the folder, by hand).
Solution:
Option1: Change your folder, ex: D:\myfiles
Option2: Use windows file manager, change your folder permission (everyone read/write)

Create lnk shortcut from lua (without lfs)

I would like to write a function to create a windows .lnk file from my lua script. I found a function in the LuaFileSystem library . Is there a way to do this without the library? (The reason: I am writing the script for multiple users, would be nice if we don't have to install the library on every machine.)
I appreciate the help!
To make a shortcut (an .lnk file)
-- your .lnk file
local your_shortcut_name = "your_shortcut.lnk"
-- target (file or folder) with full path
local your_target_filespec = [[C:\Windows\notepad.exe]]
local ps = io.popen("powershell -command -", "w")
ps:write("$ws = New-Object -ComObject WScript.Shell;$s = $ws.CreateShortcut('"..your_shortcut_name.."');$s.TargetPath = '"..your_target_filespec.."';$s.Save()")
ps:close()
To make a symlink simply use os.execute"mklink ..."
Use luacom is faster than powershell
local luacom=require'luacom'
local shortcut_file_path='test_create_shortcut.lnk'
local target_file_path=arg[0]
local shellObject=luacom.CreateObject("WScript.Shell")
local shortcut=shellObject:CreateShortcut(shortcut_file_path)
shortcut.TargetPath=target_file_path
shortcut:Save()
assert(io.open(shortcut_file_path)):close()--shortcut file exist now
os.remove(shortcut_file_path)
And use FileSystemObject object (another COM), or Windows shell link file format spec for Kaitai Struct (parse binary file struct to get info on various file format) to retrieve shortcut info. Which 'lfs' can't do now.
see: Create a desktop shortcut with Windows Script Host - Windows Client | Microsoft Docs
LuaCOM User Manual (Version 1.3)

cannot open shared object file : No such file or directory

I installed postgresql-9.3 in linux server 7.1 redhat & postgis93-2.1.8
after that i created New Database and executed the Query in Query Window
"Create extension postgis"
it showing error like below
ERROR: could not load library "/opt/Postgresql/9.3/lib/postgresql/rtpostgis-2.1.so":libpng12.so.0:cannot open shared object file : No such file or directory sql state 58p01
I installed backage libpng12.so.0 correctly
file in the location og /usr/lib/
Kindly let me know where i am wrong

Unable to load so file from Java in Eclipse On Ubuntu

I have some code that tries to load a C library as follows :-
public ThreadAffinity() {
ctest = (CTest) Native.loadLibrary("ctest", CTest.class);
}
However I get the following error when trying to build the project; The error I get is as follows :-
UnsatisfiedLinkError: Unable to load library 'libctest': liblibctest.so: cannot open shared object file: No such file or directory
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:166)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:239)
at com.sun.jna.Library$Handler.<init>(Library.java:140)
at com.sun.jna.Native.loadLibrary(Native.java:393)
at com.sun.jna.Native.loadLibrary(Native.java:378)
at com.threads.ThreadAffinity.<init>(ThreadAffinity.java:11)
at com.threads.ThreadAffinity.main(ThreadAffinity.java:45)
The current working directory is the root of the project and thats where the so file is located. I also tried modifying the LD_PRELOAD variable to point to my so file; however the error persists.
It works just fine on my OSX where the dylib is located exactly where the so file is currently(project root).
What am I doing wrong?
From the exception:
UnsatisfiedLinkError: Unable to load library 'libctest': liblibctest.so: cannot open shared object file: No such file or directory
It implies you used something like:
public ThreadAffinity() {
ctest = (CTest) Native.loadLibrary("libctest", CTest.class);
}
and not:
public ThreadAffinity() {
ctest = (CTest) Native.loadLibrary("ctest", CTest.class);
}
hence you see the JNA added prefix of lib and postfix of .so added to libctest (liblibctest.so)
LD_PRELOAD is used when you want to prefer one particular version of the same shared library over another, which doesn't apply here.
Define jna.library.path to point to your project root, and JNA should be able to find it.
Also make sure your library has been built as libctest.so and wasn't inadvertently named libctest.dylib.

Resources