I have a Spring Controller that converts PDFs into images (one for each page) and I need to display the images in a JSP.
Initially I thought of sending the images back as Base64 encoded strings, but I read a few posts advising against. So I tried to store the images as a temp file and send back to the JSP just the path to the files, but turns out it's not public.
As a temporary solution I am pointing the images' src to another REST method that retrieves the image and prints the content, however I would like to reduce the number of calls and have a single method that prints/returns all the images.
Basically you are working with 2 files (PDF and image), you receive PDF from one location and convert into to image and display the image in the JSP, there is mechanism called CDN, now a days cloud providers offers free image hosting with limited features such as AWS, Azure, GCP. For instance, check the below from AWS, and you can refer the path in your JSP.
This could be public with control panel settings.
https://aws.amazon.com/s3/
The best way is to return a page part (in some form) having a links for every page image).
In your controller load the PDF and retrieve the number of pages
Return the HTML with links to every page, invoking a next service
When asked for a page, create the page image if not already created
Return the page image
The presentation of those links, could be with < 1 2 3 ... > or whatever.
This probably requires some administration (PDF, images). It is likely there are some basic Spring examples.
You could optimize the process by job in the background / asynchrone preloading of the next page.
Related
Here i'm scaling image and saving in minImage (Buffred Image format)now how can i print that image as
BufferedImage minImage = ImageSale(buffered, minImageWidth, minImageHeight, TYPE_INT_RGB);
out.println("<img src=\""+minImage+"\">");
How to print image as thumb,please help me to resolve this issue.
You seem to have an issue with understanding the difference between a client and a server and what information they have available to each other, as well as the information that is maintained by HTML.
HTML is a plain text document, technically, it can't contain binary information (such as image data) and you really don't want to try and do this any way, as the HTML page itself should download relatively quickly.
The client HTML will need a reference to the image on the file server (or within the web servers context). This is typically done by saving the file to the server in a location which is accessible by the browser.
If you don't want to save the images to disk, then you will need to create some kind of "memory cache" which contains the key to the image, so that when the browser requests the image from the server you can look it up from the cache and return a stream of the image to the client browser.
This would require you to seed the URL with some kind of identifier that could be mapped to the cache
In java, when we establish a connection to a given URL and then open a stream to read from it, what happens when the content of the website changes halfway through reading?
For instance, our cursor was pointing to at line 1000, which was supposed contain a chapter title, but now the page has something completely different at line 1000, or perhaps the content is no longer as big as 1000 lines?
What happens if a given website updates its content every 1-2 secs, with e.g. stock changes, which might include only stocks that ticked in the last 1 sec (content grows and shrinks)?
The behaviour of what actually happens depends entirely on the web server itself and is outside the control of the client.
Most web servers will send and entire, complete document all at once, as if it were a "snapshot" in time of some particular document state.
IMHO the http server will send the content available when the client asks for a resource.
Example:
The clients asks for the index.html page GET /index.html
The server sends the entire page in one session.
The client parses the page and finds that it points to a css file, so it asks for the file.. etc..
So you can't get the first part of a HTML page then a second part of another version, as the server serves the entire page at once.
Dynamic pages have usually static layout and the data is updated using ajax.
I'm working on some reports on a Java web application. One of the requirements I have is to be able to export the report data as PDF. The reports are made up of several elements, mostly HTML tables and SVG charts courtesy of Highcharts.
Highcharts has a built-in function that exports their graphics to PDF, but I need a document that contains the other HTML data as well, so there's no other choice but to write my own code. Since the Highcharts graphics are created on the client-side, I need to submit their SVG output to the server in order to be able to include the images on the PDF document.
My first, perhaps naive, approach, was to have a form with a hidden input such as:
<form id="fileExport" method="POST" action="servlet/FileExportServlet">
<input type="hidden" id="svgParam" name="svgParam" />
</form>
And then I would set the hidden input's value to the graphic's svg code like this:
$("div#getPDF").live("click", function()
{
//the chart svg data is inside a div with class highcharts-container
//I copy the svg to the hidden input that I will submit
$("#svgParam").val($(".highcharts-container").html());
//submit the form with the hidden input
$("#fileExport").submit();
});
The problem I'm facing, is that apparently the SVG data is too large for the hidden input's value, so when it reaches the server it is truncated. I'm submitting the form in this fashion because I don't wan't to refresh the page in order to have the download start.
I was thinking that perhaps I could encode the SVG element as a Data URI, but I suppose that it wouldn't prevent truncation either, although it would produce a shorter string most of the time.
Does anyone know a way to transfer the SVG data back to the server? (Preferably allowing some other parameters as well)
Thanks
If your form is using the POST action, data will not get truncated.
Having said that, using a text camp to send binary data is unsettling. I would try either:
a) Sending it as a file attachment (but then probably your user would need to set the field value).
b) Sending it directly to your server (for example, using CURL), separately from your HTML
c) At the very least, keep using the hidden field but at least using encode64 with the data.
I have some content displayed using computed fields inside a repeat in my xpage.
I now need to be able to send out a newsletter (by email) every week with the content of this repeat. The content can be both plain text and html
My site is also translated into different languages so I need the code to be able to specify the language and return the content in that language.
I am thinking about creating a scheduled lotusscript or java agent that somehow read the content of the repeat. is this possible? if so, some sample code to get me started would be great
edit: the content is only available to logged in users
thanks
Thomas
Use a java agent, and instead of going to the content natively, do a web page open and open the page as if in a browser, then process the result. (you could make a special version of the web page that hides all extraneous content as well if you wanted)
How is the data for the repeat evaluated? Can it be translated in to a lotusscript database.search?
If so then it would be best to forget about the actual xPage and concentrate on working out how to get the same data via LotusScript and then write your scheduled agent to loop through the document collection and generate the email that way.
Looking to the Xpage would generate a lot of extra work, you need to be authenticated as the user ( if the data in the repeat is different from one user to the next ) to get the exact same data that this particular user would see and then you have to parse the page to extract the data.
If you have a complicated enough newsletter that you want to do an Xpage and not build the html yourself in the agent, what you could do is build a single xpage that changes what's rendered based on a special query string, then in your agent get the html from a URLConnection and pass the html into the body of your email.
You could build the URL based on a view that shows documents with today's date.
I would solve this by giving the user a teaser on what to read and give them a link to the full content.
You should check out Weihang Chens (my colleague) article about rendering an xPage as Mime and sending it as a mail.
http://www.bleedyellow.com/blogs/weihang/entry/render_a_xpages_programmtically_and_send_it_as_a_mail?lang=en_us
We got this working in house and it is very convenient.
He describes 3 different approaches to the problem.
Flex front-end using AMF to Java back.
Trying to read, in real-time, a file that is being written to. For example, a log.
I'm using Java's RandomAccessFile class to read the "new" lines of the file and send them back to the UI as a byte array along with the byte offset to start reading from next time.
Using an mx:List to display all lines of the text file.
The problem I'm running into, is Flex, or Flash Player, running out of memory on mildly large files, >25MB.
Is there any preferred method of displaying large amounts of text data in Flex that I'm missing? Or does Flex/Flash just handle this poorly and I'm basically screwed?
Thanks.
If 25MB is only mildly large then I'd say you probably need to page the data into the component, and simple store just a couple of pages in memory at a time. I'd probably pick something like TextArea over List, but creating seamless scrolling for a TextArea could be difficult if you don't have all the data which sounds like what you'll have to do. So stick with List for now, and figure out how many lines you want to make a page. And implement your backend as a method like:
// service call interface
public Page getPage( int lineStart, int lines );
// response object from the service call
public class Page {
private var _totalLines:int;
private var _lineStart:int;
private var _lineEnd:int;
[ArrayElementType("String")]
private lines:ArrayCollection;
}
Then you can load a page and store X number of pages in memory, but use the totalLines in the file to know how big your model is so the scrollbar can render properly. You'll just need to build a paging dataprovider that loads pages not yet loaded, and ditches pages if they aren't displayed or pages that are furthest from what's being displayed.
Right now I'm working on component that will be able to show up to 100Mb of text fast. You can just replace your mx:TextArea with LongTextArea:
<longText:LongTextArea text="{...}"/>
Download LongTextArea SWC.