I trying to use the dart.js call googlemap but receive "Breaking on exception: ReferenceError: ReceivePortSync is not defined". Anyone know about this exception?
import 'dart:html';
import 'dart:js';
import 'package:js/js.dart' as js;
import 'package:google_maps/google_maps.dart';
void main() {
bindMap();
}
void bindMap(){
js.scoped((){
final mapOptions = new MapOptions()
..zoom = 8
..center = new LatLng(-34.397, 150.644)
..mapTypeId = MapTypeId.ROADMAP
;
final map = new GMap(query("#map_canvas"), mapOptions);
});
}
You have to add <script src="packages/browser/interop.js"></script> in your html file and add browser package in dependencies.
On your code, you can :
avoid js.scoped that is not needed since few versions of js.
remove import 'dart:js'; that is not needed.
Finally you can have a look at the simple map example to have an up-to-date example.
Related
But where do you change the font size of the method
HtmlConverter.convertToElements?
Why do I get this result with this code result code after execute ?
because the text between the tags does not change size ?
I also tried these solutions using the various methods (but the size does not change) :
https://stackoverflow.com/a/59044415/18323778
itext7 set font and size of HtmlConverter elements (In this question it is explained how to use the css too I am interested in changing only 2 properties of the element)
Run this code:
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDictionary;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfName;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.Style;
import com.itextpdf.layout.element.IElement;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.font.FontProvider;
import com.itextpdf.layout.properties.Property;
import com.itextpdf.layout.properties.UnitValue;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;
/**
*
* #author UC9001309
*/
public class TestConvertHtml2pdf {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
PdfWriter pdfWriter = new PdfWriter("C:\\Temp\\" + new SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date()) + ".pdf");
PdfDocument pdfDocument = new PdfDocument(pdfWriter);
Document document = new Document(pdfDocument);
FontProvider provider = new DefaultFontProvider(true, false, false);
ConverterProperties cvProp = new ConverterProperties();
cvProp.setFontProvider(provider);
cvProp.setImmediateFlush(true);
List<IElement> lst = HtmlConverter.convertToElements("Testo <b><u><i>prova</i></u></b> con tag",cvProp);
lst.get(0).setProperty(Property.FONT_SIZE,UnitValue.createPointValue(Float.parseFloat("20")));
Paragraph p = (Paragraph) lst.get(0);
p.setProperty(Property.FONT_SIZE,UnitValue.createPointValue(Float.parseFloat("20")));
document.add(p);
document.close();
}
}
i tried various methods but still don't get results, does anyone know how to fix ?
Thanks for your help .
The goal is to create a method in Itext 7 to pass as parameters a string with html tag and font and font size, get it translated by the html parser to apply bold, italics, uderline without setting them with Itex commands as paragraph. selBold ec ..
Because my colleagues get tired of programming.
After several attempts I solved this (I create a main to try):
package testconverthtml2pdf;
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.IElement;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.font.FontProvider;
import com.itextpdf.layout.properties.UnitValue;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;
/**
*
* #author UC9001309
*/
public class TestConvertHtml2pdf {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
// Future parameters of the method change it to test !!!
float vardim = 10.5f;
String tipofont =StandardFonts.COURIER.toString().toLowerCase();
String strInput = "Testo <b><u><i>prova</i></u></b> con tag";
// -------------------------------------------------------------
PdfWriter pdfWriter = new PdfWriter("C:\\Temp\\" + new SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date()) + ".pdf");
PdfDocument pdfDocument = new PdfDocument(pdfWriter);
Document document = new Document(pdfDocument);
FontProvider provider = new DefaultFontProvider(true, false, false);
ConverterProperties cvProp = new ConverterProperties();
cvProp.setFontProvider(provider);
cvProp.setImmediateFlush(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("<p style='font-family:"+tipofont +";font-size:"+UnitValue.createPointValue(vardim)+"'>") ;
stringBuilder.append(strInput) ;
stringBuilder.append("</p>") ;
System.out.println(stringBuilder);
List<IElement> lst = HtmlConverter.convertToElements(stringBuilder.toString(),cvProp);
Paragraph p = (Paragraph) lst.get(0);
document.add(p);
document.close();
}
}
To set Font and Font-Size to the input string I add a with a Style attribute inside for Font and Font-Size taken from parameter.
stringBuilder.append("<p style='font-family:"+tipofont +";font-size:"+UnitValue.createPointValue(vardim)+"'>") ;
tipofont -----> Font parameter
vardim -----> Font size parameter
I have to thank André Lemos who in his comment (lost because instead of modifying the question I deleted and recreated) gave me a solution because the bold was not created because the font type that had bold as its attribute was missing. I loaded Currier but not Currier-Bold.
If this solution can help anyone, it is available to the community.
i'm using nestjs for project i have no issue using "#nestjs/config" before version 1.1.2 but when i created new one while copy paste from my old source code into my new one especially in main.ts it gives me error Argument of type 'string' is not assignable to parameter of type 'never'. when i passed string LISTENING_PORT into get function of configService but it worked in my old project what's the problem and how to solve this problem? thanks in advance.
here's my sample code
import { ConfigService } from '#nestjs/config';
import { NestFactory } from '#nestjs/core';
import { AppModule } from './app.module';
import * as helmet from 'helmet';
import { CustomExceptionFilter } from './exceptions/custom-exception.filter';
import { CustomValidationPipe } from './pipes/custom-validation.pipe';
import { SwaggerModule, DocumentBuilder } from '#nestjs/swagger';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors();
app.use(helmet());
app.useGlobalPipes(new CustomValidationPipe());
const configService = app.get(ConfigService);
app.useGlobalFilters(new CustomExceptionFilter(configService));
const listeningPort = configService.get('LISTENING_PORT');
const config = new DocumentBuilder()
.setTitle('API Documentation')
.setDescription('API description')
.setVersion('0.1')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
await app.listen(listeningPort);
}
bootstrap();
Fixed on #nestjs/config version 1.1.3
I am on Windows 8. I have a JavaFX app that creates a simple window with a webview control and loads the local file "test.html". "test.html" contains javascript (a simple "alert("hello");<(script>").
However, the javascript is ignored.
What rendering engine does webview in JavaFX use?
I have Firefox and IE installed. The latter executes JS contained in local files only if the users accepts to do so. So my assumption is that webview uses IE due to some configuration of my OS. Is this possible?
Thanks for your help.
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import netscape.javascript.JSObject;
public class Hello extends Application {
#Override
public void start(final Stage stage) {
stage.setWidth(400);
stage.setHeight(500);
Scene scene = new Scene(new Group());
WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(browser);
String filepath = this.getClass().getResource("test.html").toExternalForm();
webEngine.load(filepath);
scene.setRoot(scrollPane);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The JavaFX WebView does not visually show a popup when you use the alert() function in javascript. Instead it raises an event in java that you can handle like this:
myWebView.getEngine().setOnAlert((WebEvent<String> wEvent) -> {
System.out.println("JS alert() message: " + wEvent.getData() );
});
When i try to use future.sync from class future like
import 'package:async/async.dart';
import 'dart:async';
void main() {
var fur3 = new Future<int>(() => 45);
int z = Future.sync(fur3);
print(z);
}
i've got the error message
Breaking on exception: object of type NoSuchMethodError
Do i use future.sync in the wrong way?
My second question is
import 'package:async/async.dart';
void main() {
var fur1 = new Future<int>(() => 45);
fur1.then((value) {
return value;
}).catchError((err) => print('catchError1: ${err}'));
}
why when i try to import async library from package, i've got compiler message
Breaking on exception: object of type TypeError
Undefined class 'Future'
what am i do here wrong?
You don't pass a future into Future.sync() but a closure to be executed immediately.
Future z = Future.sync(() => print('bla'));
async is an internal package. You import it using
import 'dart:async';
Internal packages don't need to be added to pubspec.yaml dependencies because they are always available. The different import statement is related to that.
I'm working on setting up a server-client test app in dart.
Right now the server/client connection is working fine. One of the things I want to do though is add and remove custom elements from the page at various times. Right now I have the code:
import 'dart:async';
import 'dart:convert';
import 'dart:html';
import 'Signin/sign_in.dart';
import 'package:polymer/polymer.dart';
class Client {
static const Duration RECONNECT_DELAY = const Duration(milliseconds: 500);
WebSocket webSocket;
DivElement viewRoot;
Client() {
// Signin is a custom element defined...
Signin sign = new Signin();
viewRoot = $['hold-everything'];
viewRoot.children.add(sign);
connect();
}
....
}
sign_in.dart
class Signin extends PolymerElement {
Signin.created() : super.created();
InputElement username;
DivElement usernameParent;
DivElement passwordParent;
LabelElement usrWarn;
LabelElement passWarn;
LabelElement submissionWarn;
...
}
When I load the page I get the following error:
[16:08:24.480] : NoSuchMethodError : method not found: 'Symbol("constructor Signin")'
Receiver: ""
Arguments: [] # http://localhost:8080/client.dart.js:1042
And in client.dart I have the following warning over
Signin sign = new Signin();
The class 'Signin' does not have a default constructor