How to arrange the table from left to right in fpdf multicell? - fpdf

How to arrange the table from left to right in fpdf multicell?
This is my code
$pdf->MultiCell(12.5 ,4,'',1);
$pdf->Cell(12.5 ,7,'',1,0,'C');
$pdf->Cell(20 ,7,'',1,0,'C');
$pdf->Cell(60 ,7,'',1,0,'L');
$pdf->Cell(25 ,7,'',1,0,'C');
$pdf->Cell(25 ,7,'',1,0,'C');
$pdf->Cell(25 ,7,'',1,0,'C');
$pdf->Cell(70 ,7,'',1,0,'C');
$pdf->Cell(27 ,7,'',1,1,'C');
// }
enter image description here
And this is the output when i use this code.
$pdf->MultiCell(12.5 ,4,'Hello World',1);
$pdf->MultiCell(12.5 ,4,'Hello World',1);
$pdf->Cell(12.5 ,7,'',1,0,'C');
$pdf->Cell(20 ,7,'',1,0,'C');
$pdf->Cell(60 ,7,'',1,0,'L');
$pdf->Cell(25 ,7,'',1,0,'C');
$pdf->Cell(25 ,7,'',1,0,'C');
$pdf->Cell(25 ,7,'',1,0,'C');
$pdf->Cell(70 ,7,'',1,0,'C');
$pdf->Cell(27 ,7,'',1,1,'C');
// }
$pdf->Cell(277 ,5,'',0,1,'C');
enter image description here

Related

How to use ChosenInlineResultHandler in python telegram bot to handle the send query result?

Here is my code.
def start(update, context):
buttons = [InlineKeyboardButton("Invite User", switch_inline_query="test")]
update.message.reply_text("Please choose: ", reply_markup=InlineKeyboardMarkup(buttons))
def button(update, context):
query = update.callback_query
print(query)
def main():
updater = Updater(token, use_context=True)
updater.dispatcher.add_handler(ChosenInlineResultHandler(button))
And I set the bot inline feedback 100%, but in that case I can not send the message to the selected chat.
I'd like to send the button with the switch inline query, but I can not.
Here is my new code:
import logging
import os
from unittest import result
from telegram import ReplyKeyboardMarkup, InlineQueryResultArticle, KeyboardButton, InlineKeyboardButton, InlineKeyboardMarkup, WebAppInfo, Update, LoginUrl
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, ContextTypes, CallbackQueryHandler, ChosenInlineResultHandler, InlineQueryHandler
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
invite_state = False
def start(update, context):
"""Send a message when the command /start is issued."""
buttons = [
[InlineKeyboardButton(
text="Random Image",
switch_inline_query="test"
),
InlineKeyboardButton(
"Random Person",
callback_data="2"
)],
]
update.message.reply_text("Please choose:", reply_markup=InlineKeyboardMarkup(buttons))
def button (update, context):
query = update.inline_query.query
results = [
InlineQueryResultArticle(
id=str(uuid4()),
title="Caps",
input_message_content=InputTextMessageContent(query.upper()),
)
]
update.inline_query.answer(results)
def main(receiver_id):
updater = Updater(os.environ['TELEGRAM_BOT_TOKEN'] , use_context=True)
updater.bot.send_message(chat_id=receiver_id, text="welcome")
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
dp.add_handler(InlineQueryHandler(button))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
But I got error message "Can not find chat" in button function.
I totally solved this problem by using InlineQueryHandler.
So I send the answer with InlineQueryResultArticle and reply_markup with InlineButtons.
Here is the code.
def button (update, context):
query = update.inline_query.query
buttons = [[InlineKeyboardButton("Invitation", login_url=LoginUrl(url=websiteUrl))]]
results = [
InlineQueryResultArticle(
id=str("123456787654321"),
title="Send invitation",
input_message_content=InputTextMessageContent(query),
reply_markup=InlineKeyboardMarkup(buttons)
)
]
update.inline_query.answer(results)
Updater.dispatcher.add_handler(InlineQueryHandler(button))

Jmeter Groovy JavaMail API multipart add content to sample result

Looking at answers posted in Reading Emails based on recipient email id in Jmeter using groovy I actually managed to use the recipient search term.
Using the below in a JSR223 Sampler
import javax.mail.Multipart
import javax.mail.internet.MimeMultipart
import javax.mail.Message
import javax.mail.search.RecipientStringTerm
Properties properties = new Properties()
properties.put('mail.imap.host', 'your mail server host') // i.e. imap.gmail.com
properties.put('mail.imap.port', your mail server port) // i.e. 993
properties.setProperty('mail.imap.socketFactory.class', 'javax.net.ssl.SSLSocketFactory')
properties.setProperty('mail.imap.socketFactory.fallback', 'false')
properties.setProperty('mail.imap.socketFactory.port', 'your_mail_server_port') // i.e. 993
def session = javax.mail.Session.getDefaultInstance(properties)
def store = session.getStore('imap')
store.connect('your username (usually email address)', 'your_password')
def inbox = store.getFolder('INBOX')
inbox.open(javax.mail.Folder.READ_ONLY)
def onlyToGivenUser = inbox.search(new RecipientStringTerm(Message.RecipientType.TO,'your_recipient_address')) // i.e. test+1#gmail.com
onlyFromGivenUser.each { message ->
if (message.getContent() instanceof Multipart) {
StringBuilder content = new StringBuilder()
def multipart = (Multipart) message.getContent()
multipart.eachWithIndex { Multipart entry, int i ->
def part = entry.getBodyPart(i)
if (part.isMimeType('text/plain')) {
content.append(part.getContent().toString())
}
}
SampleResult.setResponseData(content.toString(), 'UTF-8')
} else {
SampleResult.setResponseData(message.getContent().toString(), 'UTF-8')
}
}
This works perfectly, but fails when email is ContentType: multipart/MIXED as it does not drill down to multipart/RELATED, multipart/ALTERNATIVE and then to TEXT/PLAIN or TEXT/HTML, on which I like to do a regex on to extract a link from the body.
Guessing some counter on i is needed and an "if else", or something like mentioned here, but unsure how to convert to fit in the above script...
Any help would be much appreciated.
I stepped away from javax.mail.Multipart and javax.mail.internet.MimeMultipart and have implemented the below code in a While Controller
import javax.mail.Message
import javax.mail.search.RecipientStringTerm
Properties properties = new Properties();
properties.put('mail.imap.host', 'your mail server host') // i.e. imap.gmail.com
properties.put('mail.imap.port', your mail server port) // i.e. 993
properties.setProperty('mail.imap.socketFactory.class', 'javax.net.ssl.SSLSocketFactory')
properties.setProperty('mail.imap.socketFactory.fallback', 'false')
properties.setProperty('mail.imap.socketFactory.port', 'your_mail_server_port') // i.e. 993
def session = javax.mail.Session.getDefaultInstance(properties)
def store = session.getStore('imap')
store.connect('your username (usually email address)', 'your_password')
def inbox = store.getFolder('INBOX');
inbox.open(javax.mail.Folder.READ_ONLY);
def onlyToGivenUser = inbox.search(new RecipientStringTerm(Message.RecipientType.TO,'your_recipient_address')); // i.e. test+1#gmail.com
try {
onlyToGivenUser.each { message ->
ByteArrayOutputStream emailRaw = new ByteArrayOutputStream();
message.writeTo(emailRaw);
SampleResult.setResponseData(emailRaw.toString(), 'UTF-8');
}
} catch (Exception ex) {
log.warn("Something went wrong", ex);
throw ex;
}
Hope this helps someone one day.

Flutter how to connect a socket?

Flutter how to connect to a socket, which I write a Python script as a server, this server side is like this:
import socket
import time
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("192.168.0.113", 9999))# 注意bind的这里,IP地址和端口号都要与前面的程序中一样
sock.listen(2)# 监听端口
# 等待数据源端连接
src, src_addr = sock.accept()
print "Source Connected by", src_addr
# 等待目标端连接
dst, dst_addr = sock.accept()
print "Destination Connected by", dst_addr
while True:
msg = src.recv(1024 *1024)
if not msg:
break
try:
dst.sendall(msg)
except Exception as ex:
dst, dst_addr = sock.accept()
print "Destination Connected Again by", dst_addr
except KeyboardInterrupt:
print "Interrupted"
break
src.close()
dst.close()
I wanna using Flutter to write a very simple client to show the image send from this python server via socket, how to achieve this?
I don't know about raw sockets but if you can use WebSockets in Python you could use the web_socket_channel package:
import 'package:web_socket_channel/io.dart';
import 'package:web_socket_channel/status.dart' as status;
main() async {
var channel = await IOWebSocketChannel.connect("ws://localhost:1234");
channel.stream.listen((message) {
channel.sink.add("received!");
channel.close(status.goingAway);
}, onDone: () => print("Stream closed"));
}
There's more info on using this here:
https://flutter.io/cookbook/networking/web-sockets/

Finagle - upgrade ClientBuilder() to New APIs version

I have a project with Scala Play - Finagle and ElasticSearch
I am using a Finagle client with the old version of the API, like this:
val client = ClientBuilder()
.codec(Http)
.hosts("localhost:10000,localhost:10001,localhost:10003")
.hostConnectionLimit(1)
.build()
Here is my code:
https://gist.github.com/hectorgool/f217d16e2c15b122d7a7
and works fine, but now i want to upgrade my code to a new APIs version, like this:
val client = Http.newService("localhost:10000,localhost:10001")
The new version of my code is here:
https://github.com/hectorgool/es-client/blob/master/app/lib/FinagleClient.scala
But, now my project does not compile, I have an error with this line(111):
111: val client = clientFactory.apply()()
I don't know how to fix it
Solved
I change this:
val clientFactory: ServiceFactory[HttpRequest, HttpResponse] = ClientBuilder()
.codec(Http())
.hosts(hosts)
.tcpConnectTimeout(1.second)
.hostConnectionLimit(1)
.buildFactory()
for this:
val clientFactory: Service[HttpRequest, HttpResponse] = Http.newService(hosts)
I sumprime this:
val client = clientFactory.apply()()
And i change this:
httpResponse.onSuccess{
response =>
Logger.debug("Received response: " + response)
client.close()
}.onFailure{ err: Throwable =>
Logger.error(err.toString)
client.close()
}
for this:
httpResponse.onSuccess{
response =>
Logger.debug("Received response: " + response)
}.onFailure{ err: Throwable =>
Logger.error(err.toString)
}
the cause of the problem is:
client.close()
because closing the connections

How can we send data to a websocket client side function?

In play-scala websocket using Iteratee how can we send data to a websocket client side function? How can we specify the function in scala before doing the channel push?
My current websocket server code is as follows :
lazy val (out, channel) = Concurrent.broadcast[String] def connect = WebSocket.using[String] { request => val in = Iteratee.foreach[String] {
msg => println(msg)
channel push("I received your message: " + msg)
}
(in,out)
}
My current client code is as follow:
var ws = new WebSocket("ws://localhost:9000/connect.ws");
ws.onopen = function(){
console.log("Socket has been opened! ");
};
ws.onmessage = function(message) {
console.log(JSON.parse(message.data))
};
Every time I send a message using “channel push”, “ws.onmessage” is getting triggered. How can I emit/trigger the custom event in client side from server side?
Thank you very much in advance.