Why does ConvertAPI gives me error in drupal7 - api

I m using ConvertAPI for convert doc to jpg . It works correct in PHP. But When I put same code In drupal 7 it Gives me error below
ConvertApi\Error\Api: File link is set incorrectly. URL or File Id must be set.
My code is :
require 'vendor/autoload.php';
use \ConvertApi\ConvertApi;
ConvertApi::setApiSecret('your-api-secret');
$result = ConvertApi::convert('jpg', ['File' => 'uploads/Wheels1231231a1_1.docx']);
save to file
$result->getFile()->save('uploads/file1.jpg');

Related

Errors in October CMS installation via cPanel

I just installed October CMS on my hosting platform via cPanel's Softaculous utility. I do not believe installation method has anything to do with my errors but mentioning it just in case I am wrong.
October CMS Version: 1.0.458
Sever PHP Version: 7.3.3
After installing in the designated directory it is showing "HTTP 500" generic error so I checked the error log. Following error was being shown
"[28-Sep-2019 11:09:04 Etc/GMT] PHP Parse error: syntax error, unexpected '[', expecting ')' in /home/XYZ/public_html/XYZ/vendor/october/rain/src/Support/helpers.php on line 149"
There is absolutely no online resource which describes occurance of such an error and possible solution. So I opened the helper.php to look at line 149. The code on this line was,
$query = str_replace(['%', '?'], ['%%', '%s'], $query);
Now there is nothing seemingly wrong with this line but I thought may be the "str_replace" function is not able to understand the array arguments. So I removed the array arguments and wrote it two times like
$query = str_replace('%', '%%', $query);
$query = str_replace('?', '%s', $query);
Now the error on this line disappears but a new error appears on another line as follows
PHP Parse error: syntax error, unexpected '[' in /home/XYZ/public_html/XYZ/vendor/october/rain/src/Support/helpers.php on line 238
The code on this line is
function trans($id = null, $parameters = [], $domain = 'messages', $locale = null)
Now here I am not sure if removing brackets would make everything alright. Why should such strange errors appears? Can someone help?
Are you 100% sure the PHP version you're using is 7.3.3?
The short array syntax of using [ ... ] instead of array( ... ) was introduced in PHP 5.4 and the errors you are getting are the errors that will happen if you are using an older version of PHP. I'm not sure how cPanel Softaculous works, but perhaps somehow it set you up to use a different version of PHP then you expect.
I would try running phpinfo() to double check your PHP setup.

pdfminer3k - pdf2txt.py error

I want to convert my pdf files to txt files and used pdfminer3k module & pdf2txt.py, however, I got an error.
pdf2txt.py -o file.txt -t tag file.pdf
This is my code at cmd screen.
Traceback (most recent call last):
File "C:\Python36\lib\site.py", line 67, in
import os
File "C:\Python36\lib\os.py", line 409
yield from walk(new_path, topdown, onerror, followlinks)
^
SyntaxError: invalid syntax
This is an error message that I got.
Could you help me to fix this problem??
Added for reference: Great resourse:
http://www.degeneratestate.org/posts/2016/Jun/15/extracting-tabular-data-from-pdfs/
The -t flag is the type of output. The options are text, tag, xml, and html.
Tag refers to generating a tag for xml. Replace tag with text in your command and try it.
The order of optional input also matters.
You also must invoke python, your command line does'nt know what import means, yet some of your environment seems to be setup. My example is for windows cmd from Anaconda3\Scripts directory. If your in juptyer notebook or a console, you should be able to run import pdf2txt with the .py
To setup your environment you need to append the os.path.append(yourpdfdirectory) otherwise file.pdf will not be found.
Try python pdf2txt.py -t text -o file.txt file.pdf
Or if you are brave...this is how to do programmatically. The trouble with xml is if you want to get the text, each character from xml tree is returned in an arbitrary order. You can get it to work but you need to build the string character by character which is not that hard, its just logically time consuming.
fp = open(filesin,'rb')
parser = PDFParser(fp)
doc = PDFDocument()
parser.set_document(doc)
doc.set_parser(parser)
doc.initialize('')
rsrcmgr = PDFResourceManager(caching=False)
laparams = LAParams(all_texts=True)
laparams.boxes_flow = -0.2
laparams.paragraph_indent = 0.2
laparams.detect_vertical = False
#laparams.heuristic_word_margin = 0.03
laparams.word_margin = 0.2
laparams.line_margin = 0.3
outfp = open(filesin+".out.tag" ,'wb')
device = PDFPageAggregator(rsrcmgr, laparams=laparams)
interpreter = PDFPageInterpreter(rsrcmgr, device)
#process_pdf(rsrcmgr, device, pdfparse, pagenos,caching=c, check_extractable=True)
for p,page in enumerate(doc.get_pages()):
if p == 0: #temporary for page 1
interpreter.process_page(page)
layout = device.get_result()
alltextinbox = ''
#This is a rich environment so categorization of this object hierarchy is needed
for c,lt_obj in enumerate(layout):
#print(type(lt_obj),"This is type ",c,"th object on the ",p,"th page")
if isinstance(lt_obj,LTTextBoxHorizontal) or isinstance(lt_obj,LTTextBox) or isinstance(lt_obj,LTTextLine):
print("Type ,",type(lt_obj)," and text ..",lt_obj.get_text())
obj_textbox_line.update({lt_obj:lt_obj.get_text()})
elif p != 0:
pass
fp.close()
#print(obj_textbox_line)
#call the column finder here
#check_matching("example", "example1")
#text_doc_df = pd.DataFrame(obj_textbox_line,columns=['text'])
#print (text_doc_df)
pass
I'm working on a generic row/column matcher. If you don't want to bother, you can buy this software already for like 150 bucks for a pro converter.

How do I export into pdf in phantomjs with this link.

I have read about phantomjs and rasterizejs as well. But my link is this:
http://localhost:5601/#/dashboard/External?_g=(time:(from:'2014-12-31T16:00:00.000Z',mode:absolute,to:'2015-01-01T16:00:00.000Z'))&_a=(filters:!(),panels:!((col:10,id:'Count-of-Source-IPs-(External)',row:1,size_x:3,size_y:3,type:visualization),(col:4,id:'Protocols-(External)',row:4,size_x:3,size_y:2,type:visualization),(col:7,id:'Top-5-Source-IPs-with-Protocols-and-Source-Port-(External)',row:4,size_x:6,size_y:6,type:visualization),(col:1,id:'Top-5-Source-IPs-(External)',row:4,size_x:3,size_y:2,type:visualization),(col:1,id:'Top-5-Countries-with-Protocols-(External)',row:1,size_x:6,size_y:3,type:visualization),(col:1,id:'Geographical-of-External-(Source)',row:6,size_x:6,size_y:4,type:visualization),(col:7,id:'Action-(External)',row:1,size_x:3,size_y:3,type:visualization)),query:(query_string:(analyze_wildcard:!t,query:'*')),title:External)
How do I make it such that it works with this command:
phantom.js rasterize.js "http://localhost:5601/#/dashboard/External?_g=(time:(from:'2014-12-31T16:00:00.000Z',mode:absolute,to:'2015-01-01T16:00:00.000Z'))&_a=(filters:!(),panels:!((col:10,id:'Count-of-Source-IPs-(External)',row:1,size_x:3,size_y:3,type:visualization),(col:4,id:'Protocols-(External)',row:4,size_x:3,size_y:2,type:visualization),(col:7,id:'Top-5-Source-IPs-with-Protocols-and-Source-Port-(External)',row:4,size_x:6,size_y:6,type:visualization),(col:1,id:'Top-5-Source-IPs-(External)',row:4,size_x:3,size_y:2,type:visualization),(col:1,id:'Top-5-Countries-with-Protocols-(External)',row:1,size_x:6,size_y:3,type:visualization),(col:1,id:'Geographical-of-External-(Source)',row:6,size_x:6,size_y:4,type:visualization),(col:7,id:'Action-(External)',row:1,size_x:3,size_y:3,type:visualization)),query:(query_string:(analyze_wildcard:!t,query:'*')),title:External)" external.pdf
I have been getting syntax error because of that.
The problem is probably that the command is too long for your terminal and some of it is cut off.
You can either directly put it into the script or read it from stdin. For that you need to edit rasterize.js.
First you need to reduce the x in all system.args[x] where x is above 1 by 1. If you've done that, then you can call the script as
phantom.js rasterize.js external.pdf
or
cat file.url | phantom.js rasterize.js external.pdf
in the second case.
Put URL into script
Change
address = system.args[1];
to
address = "http://localhost....";
Read from pipe
You can put your long URL into some file and pass that file to stdin of the PhantomJS script.
Change
address = system.args[1];
to
address = system.stdin.read();

XSL::Apache FOP java server connection

Got a project with Apache FOP, have to make a server based application which will use Apache FOP and pick XML+XSLT files, convert it to XSL:FO and then output an PDF file.
Everything works fine until it comes to XSL:FO=>PDF, Im getting a error in my console which tells me:
"could not connect to java server at line 15"
I'm a newbie programmer, and this might be a simple task to complete but I just can't figure it out how to run this bloody java server ... so my code might be working. Any help would be great. (FYI Im working on Windows)
Here is the Perl Code:
use XML::LibXSLT;
use XML::LibXML;
use XML::ApacheFOP;
my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();
my $source = $parser->parse_file('books.xml');
my $style_doc = $parser->parse_file('books.xsl');
my $stylesheet = $xslt->parse_stylesheet($style_doc);
my $results = $stylesheet->transform($source);
my $Fop = XML::ApacheFOP->new();
$Fop->fop( xml => "books.xml", xsl => "books.xsl", outfile => "temp.pdf" )
or die "cannot create pdf: " . $Fop->errstr;
Would be glad to get some help.
Cheers.
You need to run JavaServer by this command
/path/to/java -classpath \
/path/to/JavaServer.jar\
:/usr/local/xml-fop/build/fop-0.20.5-RFC3066-patched.jar\
:/usr/local/xml-fop/lib/avalon-framework-cvs-20020806.jar\
:/usr/local/xml-fop/lib/batik.jar\
:/usr/local/xml-fop/lib/xalan-2.4.1.jar\
:/usr/local/xml-fop/lib/xercesImpl-2.2.1.jar \
com.zzo.javaserver.JavaServer
This works for me but with fop 0.20 with fop-0.20.5-RFC3066-patched.jar

How to upload files?

I just wanted to know how to configure FCKEditor to upload files and images to the server where the website is hosted.
The relevant part for it's config file(i think) looks like this:
FCKConfig.LinkUpload = true ;
FCKConfig.LinkUploadURL = FCKConfig.BasePath + 'filemanager/connectors/' + _QuickUploadLanguage + '/upload.' + _QuickUploadExtension ;
FCKConfig.LinkUploadAllowedExtensions = ".(7z|aiff|asf|avi|bmp|csv|doc|fla|flv|gif|gz|gzip|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|ods|odt|pdf|png|ppt|pxd|qt|ram|rar|rm|rmi|rmvb|rtf|sdc|sitd|swf|sxc|sxw|tar|tgz|tif|tiff|txt|vsd|wav|wma|wmv|xls|xml|zip)$" ; // empty for all
FCKConfig.LinkUploadDeniedExtensions = "" ; // empty for no one
FCKConfig.ImageUpload = true ;
FCKConfig.ImageUploadURL = FCKConfig.BasePath + 'filemanager/connectors/' + _QuickUploadLanguage + '/upload.' + _QuickUploadExtension + '?Type=Image' ;
FCKConfig.ImageUploadAllowedExtensions = ".(jpg|gif|jpeg|png|bmp)$" ; // empty for all
FCKConfig.ImageUploadDeniedExtensions = "" ; // empty for no one
Could it be a folder permission problem? Is this part of the config.js alright?
You don't state what language you are using. The fileupload functionality in FCKeditor has ASP, .NET, Coldfusion and PHP uploaders, amongst others. It would help if you said what server (IIS/Linux?) and serverside language you are using.
With limited information its a long shot but there's settings in fckconfig.js for configuring your file browser (around line 276) Make sure you have the right language selected:
var _FileBrowserLanguage = 'php' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'php' ; // asp | aspx | cfm | lasso | perl | php | py
You'll also have to set write permissions on the folder structure you are uploading to (which might be the cause of the "invalid request" error, but process to edit file permissions is different depending if you are using windows or linux.
Its not well documented, but its also possible to debug the file manager settings by going to the following URLs in a browser:
/fckeditor/editor/filemanager/connectors/test.html
and
/fckeditor/editor/filemanager/connectors/uploadtest.html
The upload test scripts are very useful and can help diagnose many problems - you can see errors easier for a start. Give them a try and you should have a better idea what the problem is.
It's solved, thanks anyway. I just had to add the "Files" type to some variable at the config.aspx file. It only had "Images", so that's why I couldn't upload files