I'm using OpenHTMLToPDF to get PDF of HTML but I got # character in my pdf instead of actual characters. I'm using DejavuSans font and I passed to code like this:
try (InputStream is = pdfTtfFile.getInputStream()) {
pdfRendererBuilder.buildPdfRenderer().getFontResolver().addFont(() -> is, "deja-sans", null, null, false);
} catch (IOException e) {
logger.warn("error while loading DejaVuSans_1.ttf font", e);
}
I also used deja-sans as font family for body tag:
body {
font-family: 'deja-sans';
}
I have to get this is in PDF: "Hello World! Fıstıkçı Şahap İlkay Günel"
But I'm getting this in PDF: "Hello World! F#st#kç# #ahap #lkay Günel"
According to sandbox, deja-sans should be fine for me but I don't know what is wrong? Why does it show # instead of my characters?
Related
I'm trying to create an endpoint and corresponding swagger endpoint_info which uploads a file via multipart. I was hoping to use the TemporaryFile to write the parts then iterate the parts from getAllParts() to dump them to my final file. I can't seem to get the endpoint_info to create the right boundary in my request. I'm getting an exception when I try to create the PartList: Error. No 'boundary' value found in headers.
ENDPOINT_INFO(upload) {
info->summary =
"Upload"
info->addResponse<Object<CommandResponseDto>>(Status::CODE_200,
"application/json");
info->addConsumes<oatpp::String>("multipart/form-data");
}
ENDPOINT("POST", "upload",
upload,
REQUEST(std::shared_ptr<IncomingRequest>, request)) {
namespace mp = oatpp::web::mime::multipart;
try {
mp::PartList multipart(request->getHeaders());
} catch (const std::exception& e) {
logger_->error("Error creating multipart object: {}", e.what());
return create_error_response(e.what());
}
mp::PartList multipart(request->getHeaders());
mp::Reader multipartReader(&multipart);
multipartReader.setDefaultPartReader(
mp::createTemporaryFilePartReader("/tmp" /* /tmp directory */));
request->transferBody(&multipartReader);
auto parts = multipart.getAllParts();
for (auto& p : parts) {
/* print part name and filename */
logger_->error("Multipart", "Part name={}, filename={}",
p->getName()->c_str(), p->getFilename()->c_str());
/* some append all files into one large file */
}
return createResponse("OK");
}
I've tried searching around the docs and using both synchronous and asynchronous endpoints.
Looking for word api which can perform mail merge type of functionality with richtext. Basically, text will be richtext/formatted text with fonts styles and WILL have
a) images
b) bullets
c) tables
Overall purpose: Create a word template with bookmarks. Get get data from DB(for those fields) and insert. Data will be html text/richtext. Autogenerate word document. python or .net api will be preferred.
Can Aspose.words work with richtext as described above? Any other recommendations for excellent word APIs?
Yes, you can achieve this using Aspose.Words. You can use IFieldMergingCallback to insert formatted text upon mail merge. For example, see the following link
https://apireference.aspose.com/words/net/aspose.words.mailmerging/ifieldmergingcallback
In case of reach text (if you mean RTF or MarkDown formats) you first need to read this content into a separate instance of Document and then use DocumentBuilder.InsertDocument method
https://apireference.aspose.com/words/net/aspose.words/documentbuilder/methods/insertdocument
The following code example shows how to use InsertHtml method in IFieldMergingCallback
[Test]
public void Test001()
{
Document doc = new Document(#"C:\Temp\in.docx");
doc.MailMerge.FieldMergingCallback = new HandleMergeFieldInsertHtml();
const string html = #"<h1>Hello world!</h1>";
doc.MailMerge.Execute(new string[] { "myField" }, new object[] { html });
doc.Save(#"C:\Temp\out.docx");
}
private class HandleMergeFieldInsertHtml : IFieldMergingCallback
{
void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)
{
FieldMergeField field = args.Field;
// Insert the text for this merge field as HTML data, using DocumentBuilder
DocumentBuilder builder = new DocumentBuilder(args.Document);
builder.MoveToMergeField(args.DocumentFieldName);
builder.Write(field.TextBefore ?? "");
builder.InsertHtml((string)args.FieldValue);
// The HTML text itself should not be inserted
// We have already inserted it as an HTML
args.Text = "";
}
void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)
{
// Do nothing
}
}
If you would like manually format the text, then you can use DocumentBuilder appropriate properties.
[Test]
public void Test001()
{
Document doc = new Document(#"C:\Temp\in.docx");
doc.MailMerge.FieldMergingCallback = new HandleMergeFieldInsertText();
const string text = #"Hello world!";
doc.MailMerge.Execute(new string[] { "myField" }, new object[] { text });
doc.Save(#"C:\Temp\out.docx");
}
private class HandleMergeFieldInsertText : IFieldMergingCallback
{
void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)
{
FieldMergeField field = args.Field;
DocumentBuilder builder = new DocumentBuilder(args.Document);
builder.MoveToMergeField(args.DocumentFieldName);
// Apply style or other formatting.
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Write(field.TextBefore ?? "");
builder.Write((string)args.FieldValue);
// The text itself should not be inserted
// We have already inserted it using DocumentBuilder.
args.Text = "";
}
void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)
{
// Do nothing
}
}
Hope this helps.
Disclosure: I work at Aspose.Words team.
I am looking for a way in the Dart programming language to redirect the
output from stdout, into a "Something", that I can call .toString() on, and get
anything printed on stdout as String. This is useful for unit tests.
Currently I wrap stdout in my Display class, and store the text for one call and verify that stdout's write is
used. See also my side note below, how it can be done in Java.
import 'dart:io';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
class Display {
IOSink output;
String lastTextPrinted;
Display(IOSink output) {
this.output = output;
}
void myPrint(String text) {
lastTextPrinted = text;
output.write(text);
}
}
main() {
test('prints hello world', () {
Display display = new Display(stdout);
display.myPrint("Hello world!");
expect("Hello world!", display.lastTextPrinted);
});
test('myPrint calls ioSinks write', () {
MockIOSink ioSink = new MockIOSink();
Display display = Display(ioSink);
display.myPrint("Hello world!");
verify(ioSink.write("Hello world!"));
});
}
class MockIOSink extends Mock implements IOSink {}
Sidenote: In Java with JUnit 4 I used something similar to this:
There System.out is a PrintStream and I can assign my own Stream to it, for instance ByteArrayOutPutStream.
The latter has a .toString method I can call to verify its content against.
#Test
public void testMyMessageToDisplay() throws Exception
{
ByteArrayOutputStream canvas = new ByteArrayOutputStream();
System.setOut(new PrintStream(canvas);
new Display().displayMyMessage("Hello world!");
Assert.assertEquals("Hello World!", canvas.toString("UTF-8"));
}
public static class Display {
public void displayMyMessage(String myMessage) {
System.out.println(myMessage);
}
}
Look at https://pub.dartlang.org/packages/test_process – it gives a lot of nice methods for verifying the output of a process
See the example in the readme:
import 'package:test/test.dart';
import 'package:test_process/test_process.dart';
void main() {
test("pub get gets dependencies", () async {
var process = await TestProcess.start("pub", ["get"]);
// Each stream matcher will consume as many lines as it matches from a
// StreamQueue, and no more, so it's safe to use them in sequence.
await expectLater(process.stdout, emits("Resolving dependencies..."));
// The emitsThrough matcher matches and consumes any number of lines, as
// long as they end with one matching the argument.
await expectLater(process.stdout, emitsThrough("Got dependencies!"));
await process.shouldExit(0);
});
}
I am new to Solr and SolrJ. I am trying to use for a desktop application and I have files(text files) to index and search. I wanted to use highlight feature and display the fragments with highlight,but I don't get them to display in yellow background as you highlight a text, please let me know how to display the text in yellow background.
here is my code snippet:
public void TestHighLight(SolrQuery query) throws
SolrServerException, IOException {
query.setQuery("*");
query.set("hl", "true");
query.set("hl.snippets", "5");
query.set("q", "text:Pune");
query.set("hl.fl", "*");
QueryResponse queryResponse = client.query(query);
SolrDocumentList docs = queryResponse.getResults();
Iterator iter = docs.iterator();
for (int i = 0; i < docs.size(); i++) {
iter = docs.get(i).getFieldNames().iterator();
String fldVal = (String) docs.get(i).getFieldValue("id");
String docID = (String) docs.get(i).get("id");
while (iter.hasNext()) {
String highlighText = getHighlightedText(queryResponse,
"text", docID);
System.out.println(" tHighlightedText is " + highlighText );
}
}
}
The output looks like this:how do I color it ?
[ for Java Developer at Pune
Thanks a lot !
Set the pre and post parameters of the highlighter. Specifies the “tag” to use before a highlighted term. This can be any string, but is most often an HTML or XML tag.
e.g:
solrQueryHandler.setHighlightSimplePre("<font color="yellow">");
solrQueryHandler.setHighlightSimplePost("/font");
But note that this will work only for the Original Highlighter
I am using tinymce editor for inserting contents to mysql.
I have changed wordpress gallery editor plugin according to my system.
If there is gallery code in content. I convert this code to a symbolic photo, so that user understand there is a gallery , in stead of seeing a code. Like wordpress does.
If there is only 1 gallery in content, i convert this code to image successfully, but if there is more than 1 gallery it fails.
How can i convert all {gallery} code into a symbolic image before saving to db and convert these photos back to {gallery} code again while inserting or updating into mysql.
I am so bad on regular expression.
I think do_gallery RegExp has mistake. How should i change this.
initalising editor like:
ed.onBeforeSetContent.add(function(ed, o) {
ed.dom.loadCSS(url + "/css/gallery.css");
o.content = t._do_gallery(o.content);
});
ed.onPostProcess.add(function(ed, o) {
if (o.get)
o.content = t._get_gallery(o.content);
});
My "do and get gallery" codes like that:
_do_gallery : function(co) {
return co.replace(/\{gallery([^\]]*)\}/g, function(a,b){
var image = '<img src="gallery.gif" class="wpGallery mceItem" title="gallery'+tinymce.DOM.encode(b)+'" />';
console.log(image);
return image;
});
},
_get_gallery : function(co) {
function getAttr(s, n) {
n = new RegExp(n + '="([^"]+)"', 'g').exec(s);
return n ? tinymce.DOM.decode(n[1]) : '';
};
return co.replace(/(?:<p{^>}*>)*(<img[^>]+>)(?:<\/p>)*/g, function(a,im) {
var cls = getAttr(im, 'class');
if ( cls.indexOf('wpGallery') != -1 )
return '<p>{'+tinymce.trim(getAttr(im, 'title'))+'}</p>';
return a;
});
}
If Content is:
<p>Blah</p>
<p>{gallery Name="gallery1" id="82" galeryID="15" sizeId="6" galery_type="list"}</p>
<p>test</p>
this is ok
<img src="gallery.gif" class="wpGallery mceItem" title="gallery Name="tekne1" id="82" galeryID="15" sizeId="6" galery_type="liste"" />
But, if content is:
<p>Blah</p>
<p>{gallery Name="gallery1" id="82" galeryID="15" sizeId="6" galery_type="list"}</p>
<p>test</p>
<p>{gallery Name="gallery2" id="88" galeryID="11" sizeId="1" galery_type="slide"}</p>
<p>test2</p>
it logs
<img src="gallery.gif" class="wpGallery mceItem" title="gallery Name="gallery1" id="82" galeryID="15" sizeId="6" galery_type="list"}</p> <p>test</p> <p>{gallery Name="gallery2" id="88" galeryID="11" sizeId="1" galery_type="slide"" />
I hope i could explain my problem
Thank you.
I suspect that your original regex is a typo, looks like a missing Shift when you hit the ]. Try this:
/\{gallery([^\}]*)\}/g
Then the ([^\}]*) part will (greedily) eat up any sequence of characters that aren't }; your original one would consume any sequence of character that didn't include a ] and the result is that you'd grab everything between the first { and the last } rather than just grabbing the text between pairs of braces.