SmartGWT pdf export - pdf

Has anyone successfully used SmartGWT 3.x pdf export?
My client code looks like this:
DSRequest requestProperties = new DSRequest();
requestProperties.setExportFilename("File.pdf");
requestProperties.setExportDisplay(ExportDisplay.DOWNLOAD);
requestProperties.setContentType("application/pdf");
RPCManager.exportContent(table, requestProperties);
When the code run nothing happens. Do I have to do anything server side?
I can just add that my application is successfully using the SmartGWT excel export from the list grid.

I also tried in vain to find the documentation about this. But it's not that hard. Your code seems right, have added a canvas to print and the line requestProperties.setDownloadResult(true);
final Canvas canvas = new Canvas();
canvas.setWidth(300);
canvas.setBorder("2px solid Red");
DynamicForm formPrint = new DynamicForm();
formPrint.setWidth(200);
formPrint.setHeight(100);
formPrint.setTop(20);
formPrint.setLeft(50);
formPrint.setBorder("2px solid Black");
TextItem textItem = new TextItem();
textItem.setName("NameBo");
textItem.setTitle("Title");
textItem.setValue("Value goes here...");
formPrint.setFields(textItem);
canvas.addChild(formPrint);
canvas.draw(); // to view onscreen
DSRequest requestProperties = new DSRequest();
requestProperties.setExportFilename("File");
requestProperties.setExportDisplay(ExportDisplay.DOWNLOAD);
requestProperties.setContentType("application/pdf");
requestProperties.setDownloadResult(true);
RPCManager.exportContent(canvas, requestProperties);
I then added the following jars from the smartgwtEE lib folder (in eclipse .classpath)
<classpathentry kind="var" path="SGWTEE_HOME/lib/isomorphic_contentexport.jar"/>
<classpathentry kind="var" path="SGWTEE_HOME/lib/iText-2.0.8.jar"/>
<classpathentry kind="var" path="SGWTEE_HOME/lib/jtidy-r938.jar"/>
And that's all that was to it :-)

The answer to your question is yes: countless developers have successfully used SmartGWT's PDF Export. Now gimme my points please ;)
To troubleshoot, look in your server logs for errors.

Related

Setting window icon in Avalonia

I am writing a small app for as a school project and I cannot figure out how can I change the window icon. I found the "Icon" property of Window, but I have no clue how it works, as I have found little documentation on it. When I tried to input something in the field, it threw an error, that the resource could not be found. I read something on importing resources as well, but this is my first app of this kind, so I am completely lost. Any help much appreciated, thank you
You need to add your icon as AvaloniaResource. If you are using MVVM template, everything in Assets directory should be added as one. If you aren't, then add
<ItemGroup>
<AvaloniaResource Include="Assets\**" />
</ItemGroup>
to your .csproj file.
Then put your icon into Assets directory.
After that simply writing Icon="/Assets/your-icon.ico" in your window xaml should work.
This was more what I was looking for, in setting the icon in c#.
IBitmap bitmap = new Bitmap(AvaloniaLocator.Current?.GetService<IAssetLoader>()?.Open(
new Uri($"avares://{Assembly.GetExecutingAssembly().GetName().Name}/Assets/example.png"))
);
var exampleWindow = new Window()
{
Title = "Example",
Height = 700,
Icon = new WindowIcon(bitmap)
}
in axaml
<Window xmlns="https://github.com/avaloniaui"
Icon="/Assets/example.png">
...
</Window>

Windows 8 app with FabricJS Free Drawing Support?

I'm trying to implement free drawing in my windows 8 app but I keep getting this error:
"0x800a01bd - JavaScript runtime error: Object doesn't support this action
File: fabric.js, Line: 12857, Column: 7"
Adding images to the canvas etc. all works as it does in the demos but in VS when I hovered over "fabric" in this code, fabric.Shadow is not shown as an option in the list:
setShadow: function(options) {
return this.set('shadow', new fabric.Shadow(options));
},
Does anyone know why this isn't working for me? I created a build of the api from www.fabricjs.com and included all modules. I've copied the code from the free drawing demo (http://fabricjs.com/freedrawing/) but no joy. I also tried removing any reference to creating a shadow as I don't plan on using that functionality but it still crashes. Thank you
Thank you! It's working for me now. I did have to change the JavaScript provided by the demo to make it work though. Just as a reference to anyone who may want to use it with Windows 8 in future, the jquery code needs to be made more strict for it to update the selectors.
Provided code:
var $ = function(id){return document.getElementById(id)};
var drawingModeEl = $('drawing-mode'),
drawingOptionsEl = $('drawing-mode-options'),
drawingColorEl = $('drawing-color'),
drawingShadowColorEl = $('drawing-shadow-color'),
drawingLineWidthEl = $('drawing-line-width'),
drawingShadowWidth = $('drawing-shadow-width'),
drawingShadowOffset = $('drawing-shadow-offset'),
clearEl = $('clear-canvas');
I did away with the above and just used the standard jquery selector $('#drawing-mode') each time I needed it. Then the events were provided as:
drawingModeEl.onclick = function() {}
drawingColorEl.onchange = function() {}
so I changed the above to:
$('#drawing-mode').on('click', function () {});
$('#drawing-color').change(function (){});
Now everything works as it does in the demo. Love this API, thank you!

Switching to a window with no name

Using the Codeception testing framework and Selenium 2 module to test a website, I end up following a hyperlink that opens a new window with no name. As a result the switchToWindow() function will not work because it is trying to switch to the parent window (which I'm currently on). Without being able to switch to the new window I cannot perform any testing on it.
<a class="external" target="_blank" href="http://mylocalurl/the/page/im/opening">
View Live
</a>
Using both Chrome and Firefox debugging tools I can confirm the new window doesn't have a name, and I cannot give it one because I cannot edit the HTML page I am working on. Ideally I would have changed the HTML to use javascript onclick="window.open('http://mylocalurl/the/page/im/opening', 'myPopupWindow') however this is not possible in my case.
I've looked around on the Selenium forums without any clear method to tackle this problem, and Codeception doesn't appear to have much functionality around this.
After searching around on the Selenium forum and some helpful prods from #Mark Rowlands, I got it to work using raw Selenium.
// before codeception v2.1.1, just typehint on \Webdriver
$I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
$handles=$webdriver->window_handles();
$last_window = end($handles);
$webdriver->focusWindow($last_window);
});
Returning back to the parent window was easy because I could just use Codeception's switchToWindow method:
$I->switchToWindow();
Building on the accepted answer, in Codeception 2.2.9 I was able to add this code to the Acceptance Helper and it seems to work.
/**
* #throws \Codeception\Exception\ModuleException
*/
public function switchToNewWindow()
{
$webdriver = $this->getModule('WebDriver')->webDriver;
$handles = $webdriver->getWindowHandles();
$lastWindow = end($handles);
$webdriver->switchTo()->window($lastWindow);
}
Then in the test class I can do this:
$I->click('#somelink');
$I->switchToNewWindow();
// Some assertions...
$I->switchToWindow(); // this switches back to the previous window
I had a heck of a time trying to figure out how to do this by just searching google, so I hope it helps someone else.
Try this,
String parentWindowHandle = browser.getWindowHandle(); // save the current window handle.
WebDriver popup = null;
Iterator<String> windowIterator = browser.getWindowHandles();
while(windowIterator.hasNext()) {
String windowHandle = windowIterator.next();
popup = browser.switchTo().window(windowHandle);
}
make sure to return on parent window using,
browser.close(); // close the popup.
browser.switchTo().window(parentWindowHandle); // Switch back to parent window.
I hope will help you.
Using Codeception 2.2+ it looks like this:
$I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
$handles = $webdriver->getWindowHandles();
$lastWindow = end($handles);
$webdriver->switchTo()->window($lastWindow);
});

How to get an image from mshtml.htmlimg to hard disk

Without using API?
I know there are several way.
I am using mshtml library by the way, which is better than webbrowser control. I am effectively automating internet explorer straight.
Basically I prefer a way to take the image straight without having to know the URL of the htmlimg and download it.
I know I can take URL from the image element and downloading it with webclient. The image changes depending on cookies and IP. So that wouldn't do.
I want the exact images displayed by the htmlimg element to be the one stored.
Basically as if someone is taking a local screenshot of what shows up on screen.
There's an old solution for this here:
http://p2p.wrox.com/c/42780-mshtml-how-get-images.html#post169674
These days though you probably want to check out the Html Agility Pack:
http://htmlagilitypack.codeplex.com/
The documentation isn't exactly great however; so this code snippet may help:
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(html);
// You can also load a web page by utilising WebClient and loading in the stream - use one of the htmlDoc.Load() overloads
var body = htmlDoc.DocumentNode.Descendants("body").FirstOrDefault();
foreach (var img in body.Descendants("img"))
{
var fileUrl = img.Attributes["src"].Value;
var localFile = #"c:\localpath\tofile.jpg";
// Download the image using WebClient:
using (WebClient client = new WebClient())
{
client.DownloadFile("fileUrl", localFile);
}
}

ROR + Reopen a new tab in same window using RUBY code

In my project, I want to re-open a new tab using ruby code. When user clicks at attachment link, then that pdf should be open in new tab of same window. I tried a lot but I am not getting the way to solve it. Please guide me.
I am not sure if this is possible using Ruby since it deals with the UI part. It is indeed very much possible using HTML and Jquery.
You could simply set the target attribute as blank in the hyperlink redirecting to the PDF and it will open the file in a new tab. Something similar to this :
<a href="http://www.mysite.com/files/xyz.pdf" target="_blank">
If you want to use JQuery for this, you can try something like this :
$(document).ready(function() {
$("a").click(function() {
link_host = this.href.split("/")[2];
document_host = document.location.href.split("/")[2];
if (link_host != document_host) {
window.open(this.href);
return false;
}
});
});