I want to send text from a current TextView editor buffer to PDF through export function, but I don't see any text when I open the exported PDF.
Here's my attempt in C++ code:
void MainWindow::export_note() {
auto op = Gtk::PrintOperation::create();
string file_path = work_dir + "/" + curr_path;
string file_name = curr_path.substr(curr_path.rfind("/")+1);
string file_content = editor.get_buffer()->get_text();
op->set_export_filename(file_name);
ofstream out(file_path);
out << file_content;
out.close();
auto res = op->run(Gtk::PrintOperation::Action::EXPORT);
return;
}
The only thing that works is the file_name being updated.
Related
I'm using protobuf to send/receive binary data from Cpp to Js and vice-versa and I'm using QWebChannel to communicate with the HTML client.
Question: How to deserialize binary data in cpp which is serialized and sent from Js?
Following I tried:
//Serialization: Cpp to JS - WORKING
tutorial::PhoneNumber* ph = new tutorial::PhoneNumber();
ph->set_number("555-515-135");
ph->set_type(500);
QByteArray bytes = QByteArray::fromStdString(ph->SerializeAsString());
QString args = "\"" + bytes.toBase64(QByteArray::Base64Encoding) + "\"";
QString JsFunctionCall = QString("DeserializePhoneNumber(%1);").arg(args);
m_pWebView->page()->runJavaScript(JsFunctionCall);
//Deserialization In JS - Js Code - WORKING
var obj = phone_msg.PhoneNumber.deserializeBinary(data);
console.log("PhoneNumber: " + obj.getNumber());
console.log("Type: " + obj.getType());
//Serialization in Js - WORKING
var phNum = new phone_msg.PhoneNumber;
phNum.setNumber("555-515-135");
phNum.setId(500);
var base64Str = btoa(phNum.serializeBinary());
console.log("base64Str: " + base64Str);
//Call Cpp function from Js
MainChannel.SendMsgToCpp(base64Str);
Deserialization in Cpp - NOT WORKING
bool WebRelay::ReceiveMsgFromJs(QVariant data)
{
QString str = data.toString();
QByteArray bytedata = str.toLatin1();
QByteArray base64data = QByteArray::fromBase64(bytedata);
std::string stdstr = base64data.toStdString();
tutorial::PhoneNumber cppPhNum;
//THIS IS NOT WORKING. Text and id are invalid
cppPhNum.ParseFromArray(base64data.constData(), base64data.size());
qDebug() << "Text:" << itemData.number();
qDebug() << "id:" << cppPhNum.id();
}
Found the problem.
I was getting comma-separated bytes from Js like:
10,7,74,115,73,116,101,109,49,16,45
I split the strings by ',' and created a QByteArray
QStringList strList = str.split(',');
QByteArray bytedata;
foreach(const QString & str, strList)
{
bytedata+= (str.toUInt());
}
std::string stdstr = bytedata.toStdString();
itemData.ParseFromString(stdstr);
It works.
Also in JS, I removed convertion of the binary string to base64:
var base64Str = phNum.serializeBinary();
I've been using the S3 connector for a couple of weeks now, and I want to change the way the connector names each file. I am using the HourlyBasedPartition, so the path to each file is already enough for me to find each file, and I want the filenames to be something generic for all the files, like just 'Data.json.gzip' (with the respective path from the partitioner).
For example, I want to go from this:
<prefix>/<topic>/<HourlyBasedPartition>/<topic>+<kafkaPartition>+<startOffset>.<format>
To this:
<prefix>/<topic>/<HourlyBasedPartition>/Data.<format>
The objective of this is to only make one call to S3 to download the files later, instead of having to look for the filename first and then download it.
Searching through the files from the folder called 'kafka-connect-s3', I found this file:
https://github.com/confluentinc/kafka-connect-storage-cloud/blob/master/kafka-connect-s3/src/main/java/io/confluent/connect/s3/TopicPartitionWriter.java which at the end has some of the following functions:
private RecordWriter getWriter(SinkRecord record, String encodedPartition)
throws ConnectException {
if (writers.containsKey(encodedPartition)) {
return writers.get(encodedPartition);
}
String commitFilename = getCommitFilename(encodedPartition);
log.debug(
"Creating new writer encodedPartition='{}' filename='{}'",
encodedPartition,
commitFilename
);
RecordWriter writer = writerProvider.getRecordWriter(connectorConfig, commitFilename);
writers.put(encodedPartition, writer);
return writer;
}
private String getCommitFilename(String encodedPartition) {
String commitFile;
if (commitFiles.containsKey(encodedPartition)) {
commitFile = commitFiles.get(encodedPartition);
} else {
long startOffset = startOffsets.get(encodedPartition);
String prefix = getDirectoryPrefix(encodedPartition);
commitFile = fileKeyToCommit(prefix, startOffset);
commitFiles.put(encodedPartition, commitFile);
}
return commitFile;
}
private String fileKey(String topicsPrefix, String keyPrefix, String name) {
String suffix = keyPrefix + dirDelim + name;
return StringUtils.isNotBlank(topicsPrefix)
? topicsPrefix + dirDelim + suffix
: suffix;
}
private String fileKeyToCommit(String dirPrefix, long startOffset) {
String name = tp.topic()
+ fileDelim
+ tp.partition()
+ fileDelim
+ String.format(zeroPadOffsetFormat, startOffset)
+ extension;
return fileKey(topicsDir, dirPrefix, name);
}
I don't know if this can be customised to what I want to do but seems to be somehow near/related to my intentions. Hope it helps.
(Submitted an issue to Github as well: https://github.com/confluentinc/kafka-connect-storage-cloud/issues/369)
I am trying to display a PDF file in a browser using the action below.
When this is executed the result is an entire screen that looks like the image attached. Rendered result
It looks like MediaTypeNames.Application.Pdf is being ignored.
The same result with Chrome or Firfox.
What I am missing?
[HttpGet]
public FileResult ViewFile()
{
Response.AppendHeader("Content-Disposition", "inline; filename=" + Server.UrlEncode("file.pdf") + ";");
var path = #"C:\temp\file.pdf";
FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
return new FileStreamResult(stream, MediaTypeNames.Application.Pdf);
}
You can use below below code snippet to display a PDF document in browser.
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
fileStream.Position = 0;
return new FileStreamResult(fileStream, System.Net.Mime.MediaTypeNames.Application.Pdf);
How can I pass a string as a path into here
void SaveLogFile()
{
logTxt->SaveFile(String::Concat
(System::Environment::GetFolderPath
(System::Environment::SpecialFolder::Personal),
"\\Testdoc.rtf"), RichTextBoxStreamType::RichNoOleObjs);
}
I can't figure out how to set a non SpecialFolder
From MSDN:
void SaveMyFile()
{
// Create a SaveFileDialog to request a path and file name to save to.
SaveFileDialog^ saveFile1 = gcnew SaveFileDialog;
// Initialize the SaveFileDialog to specify the RTF extention for the file.
saveFile1->DefaultExt = "*.rtf";
saveFile1->Filter = "RTF Files|*.rtf";
// Determine whether the user selected a file name from the saveFileDialog.
if ( saveFile1->ShowDialog() == System::Windows::Forms::DialogResult::OK &&
saveFile1->FileName->Length > 0 )
{
// Save the contents of the RichTextBox into the file.
richTextBox1->SaveFile( saveFile1->FileName );
}
}
See how the System::String^ is created here. Do it this way, too...
I'm implementing a custom field in Sitecore for the Content Editor, and I need to be able to open the Rich Text editor and get the data from there. I'm not really sure where to look though, nor how to go about it.
Had to decompile the Sitecore.Kernel DLL in order to figure this out.
First thing is to spin off a call from the Context.ClientPage object
So, for my situation:
switch (message.Name)
{
case "richtext:edit":
Sitecore.Context.ClientPage.Start(this, "EditText");
break;
}
You will then need to have a method in your class with the same name as defined in the above Start method. Then, you either start the rich text control if the request isn't a postback, or handle the posted data
protected void EditText(ClientPipelineArgs args)
{
Assert.ArgumentNotNull(args, "args");
if (args.IsPostBack)
{
if (args.Result == null || args.Result == "undefined")
return;
var text = args.Result;
if (text == "__#!$No value$!#__")
text = string.Empty;
Value = text;
UpdateHtml(args); //Function that executes Javascript to update embedded rich text frame
}
else
{
var richTextEditorUrl = new RichTextEditorUrl
{
Conversion = RichTextEditorUrl.HtmlConversion.DoNotConvert,
Disabled = Disabled,
FieldID = FieldID,
ID = ID,
ItemID = ItemID,
Language = ItemLanguage,
Mode = string.Empty,
Source = Source,
Url = "/sitecore/shell/Controls/Rich Text Editor/EditorPage.aspx",
Value = Value,
Version = ItemVersion
};
UrlString url = richTextEditorUrl.GetUrl();
handle = richTextEditorUrl.Handle;
ID md5Hash = MainUtil.GetMD5Hash(Source + ItemLanguage);
SheerResponse.Eval("scContent.editRichText(\"" + url + "\", \"" + md5Hash.ToShortID() + "\", " +
StringUtil.EscapeJavascriptString(GetDeviceValue(CurrentDevice)) + ")");
args.WaitForPostBack();
}