Printing ListView items fetched from a JSON datasource in a Windows 8 (HTML + JS) app - windows-8

I have a Windows 8 app built using HTML & JavaScript. It has a ListView showing a dynamic list of places generated from a JSON data source.
I'm using Print Contract code from a MSDN sample (that shows how to print a page with static content) to implement printing functionality to this app. Only half of the list in the ListView shows up when printed.
How can I print the full list from the ListView & make it spread across multiple pages when the content is large?

The trick here is in providing a document to the MSApp.getHtmlPrintDocumentSource method that correctly represents what you want printed, which isn't necessarily the same as what's displayed on the page.
The sample you reference simply passes the current document object to getHtmlPrintDocumentSource, and is the easiest way to print, but as you've noticed, may not give you exactly the results you want.
A simple way to customize the output, as noted in chapter 15 of Kraig Brockschmidt's excellent (and free) ebook on HTML and JavaScript Windows Store apps, is to add a media query for the print media type, and use CSS to modify the output of the page, like so:
#media print {
.win-backbutton {
display: none;
}
.watermark {
display: none;
}
.titlearea {
font-size: xx-large;
}
}
This will not, however, likely solve the problem you're facing. In your case, what will probably work best is to create a separate page that provides output which is more print-friendly.
As an example, based on scenario 4 in the print contract sample, if I place an HTML page called print.html in the root of my app, I can reference it using the following code (note the ms-appx:/// scheme, which refers to content in my app package):
// set the alternate content
var alternateLink = document.createElement("link");
alternateLink.setAttribute("id", "alternateContent");
alternateLink.setAttribute("rel", "alternate");
alternateLink.setAttribute("href", "ms-appx:///print.html");
alternateLink.setAttribute("media", "print");
document.getElementsByTagName("head")[0].appendChild(alternateLink);
Now, when the devices charm is invoked, my alternate content page is supplied as the source for printing, rather than the current page. You can have your alternate page load the content from the JSON source and render it in a printer-friendly fashion, which may be different from how the content is displayed on the page.
For more info on Windows Store app development, register for Generation App.

Related

What is the best to use to describe styles for application content?

I have been creating application in React Native. The goal of the application is to have content that can be changed without updating the app. I understand that the two best solutions are either Firebase or some other API call at every application start to get new content. Now I would just like to know if there are any recommended way to style content beside my three current solutions:
Styling content with markdown and then parsing it in application
Styling content with html and then parsing it in application
Or having a standard content object so that all the content is packed the same way and then showing right text/media on correct place with correct style
I am open to any other styling solutions for content and would like to know what is the best way. I also already have a server responding to API call that returns new content, the biggest problem is styling.

Customizing image uploading in TinyMCE

I have an ASP.NET Web API web service which I want to use for file uploading. The way I do this is that the client posts a JSON object to the service at http://myserver.com/api/images/upload .
The object would contain a base64 string representation of the image, plus some metadata, e.g:
{ companyId: 12345, image: "someBase64encodedStringRepresentingTheImage" }
I would like to use TinyMCE on the client side, but I can't figure out how to customize it such that images are uploaded to the server in that format. (Actually, it doesn't seem like TinyMCE comes with an image uploader at all)
TinyMCE 4.2+ actually has its own built in process for handling the upload of images that you place in the editor:
https://www.tinymce.com/docs/advanced/handle-async-image-uploads/
The basic process is that TinyMCE will create a separate HTTP POST for each image that you insert into the editor. It will send that image to a URL of your choosing (via HTTP POST) based on the setting of the images_upload_url option in your init.
The image handler at the URL referenced in the images_upload_url (which you have to create) has to do whatever needs to be done to "store" the image in your application. That could mean something like:
Store the item in a folder on your web server
Store the item in a database
Store the item in an asset management system
...regardless of where you choose to store the image your image handler needs to return a single line of JSON telling TinyMCE the new location of the image. As referenced in the TinyMCE documentation this might look like:
{ location : '/uploaded/image/path/image.png' }
TinyMCE will then update the image's src attribute to the value you return. If you use the images_upload_base_path setting in the init that will be prepended to the returned location.
The net here is that TinyMCE knows when an embedded image exists in your content but it can't possibly know what to do with that image in the context of your application so that job (the "image handler") is something you must create.
There is an option for you to write your own image handler if the default one is not sufficient:
https://www.tinymce.com/docs/configure/file-image-upload/#images_upload_handler
I would recommend trying to use the uploader that comes with TinyMCE so you don't have to write and maintain your own code going forward (always easier) but if the built in code is not appropriate you can indeed replace it with your own function.

Get the HTML output data from a wicket component

I'm currently writing a web widget, and I would like to fill the content of this widget with some HTML data generated by a wicket component on my server.
To do that, the server will output the HTML data via JSONP. So far so good.
However I need to get this HTML data. How can I get on the server the HTML output from some wicket component?
I dont know if this can be applied to your configuration, but I am using a view lines of code to retrieve rendered html which I wrote some time ago for building html based emails to be able to use wicket components in it
protected final String renderPage(Component page) {
final Response oldResponse = RequestCycle.get().getResponse();
BufferedWebResponse tempResponse = new BufferedWebResponse((WebResponse) RequestCycle.get().getOriginalResponse());
try {
RequestCycle.get().setResponse(tempResponse);
page.render();
}
finally {
RequestCycle.get().setResponse(oldResponse);
}
return tempResponse.toString();
}
As this rendering is made within an actual webapplication cycle but independently from the actual requestcycle, it is recommended to preserve the original requestcycle. The page will be rendered in your temporary webresponse from which you can retrieve the rendered html output.
Hope this may be what you are looking for
You might find everything you need in this Wicket Wiki article and the linked source code: Use wicket as template engine
Although I must admit that I never tried that, just read it and remembered for further reference...

Adding Multiple web pages to UIWebview in a Page-Based app

I am working on making a paged app that will load a separate HTML page on each page. I am using the already given example that Apple has provided and rigged it to make the label dissapear and a few other things. Most tutorials I have seen do not cover this idea at all.
I need to be able to make an array of webpages and using one UIWebview display those pages, obviously one HTML file per page. What will be the most efficient way to do this that is up to date with iOS5 or is there a recent tutorial I can follow? Thanks.
Depending on how much data you have you could serialize the HTML data in a single file (such as a plist) or have them as separate files in a directory.
Based on the template you are using, you would
change the view in DataViewController to a UIWebView;
then override the viewControllerAtIndex method in your ModelController and pass the path to your HTML page as the data object;
and finally load the HTML in the viewWillAppear method of your DataViewController.
VoilĂ , here is your tutorial!

how to read/parse dynamically generated web content?

I need to find a way to write a program (in any language) that will connect to a website and read dynamically generated data from the website.
Note that it's dynamically generated--it's not enough to get the source html, because the data I'm interested in is generated via javascript that references back-end code. So when i view the webpage source, I can't see the data. (For example, go to google, and do a search. Check the source code on the search results page. Very little of the data your browser is displaying is reflected in the source--most of it is dynamically generated. I need some way to access this data.)
Pick a language and environment that includes an HTML renderer (e.g. .NET and the WebBrowser control). Use the HTML renderer to get the URL and produce an HTML DOM in memory (making sure that scripting is enabled). Read the contents of the HTML DOM after the renderer has done its work.
Example (you'll need to do this inside a System.Windows.Form derived class):
WebBrowser browser = new WebBrowser();
browser.Navigate("http://www.google.com");
HtmlDocument document = browser.Document;
// extract what you want from the document
I used to have a Perl program to access Mapguide.com to get the drive direction from one location to another location. I parsed the returned page and save to database. If the source never change their format, it is OK. the problem is the source format often change, your parser also need change.
A simple thought: if we're talking about AJAX, you can rather look up the urls for the dynamic data. Then you can use the javascript on the page you're talking about to reformat this.
If you have Firefox/greasemonkey making a DOM dumper should be a simple matter.