I want to open a pdf file from a button of my GWT application. Actually to access that file I've to query the server that returns the file encoded in base64 from a JSON request.
It's possible to open that file then?
To show a pdf "file" (it's not a file, but a byte stream in http reply) you need to rely on browsers own capability to render pdf data. To do this you must either open a URL in a new window or in in an iframe. The second is probably a better option when using GWT. Docs of the GWT Frame.
// url of the pdf (must have application/pdf content-type)
Frame frame = new Frame("url");
// add the frame wherever you want
RootPanel.get().add(frame);
In order for the browser to correctly display pdf page (by invoking the pdf plugin), the url that serves the pdf data must have a header that says Content-Type: application/pdf. Check that your response has this header.
Related
I tried pdf, txt and png file url, only pdf url can't be open with browser if click the url, but trigger download.
I google this but only got how to fix, like instead with google doc or use pdf.js, or other html code.
What is the reason? the website ? Forgive me that i have no idea of website architecture.
When you get a file from a website, it has a content type sent along with it. Depending on the content type, the browser may choose to display it. For example, content type "application/pdf" might be shown in a browser, but "application/octet-stream" will be downloaded.
The raw URL on GitHub has content type "application/octet-stream" (a binary file) so that it will be downloaded.
The only way around this, since you can't change GitHub's code that sets the content type, is to get the data from JavaScript and parse it there -- by using pdf.js or something similar.
I have a PDF which has a submit button which will submit the PDF fields as an html form to my web API. The submit part works, however it is sending the request payload in a format I have never seen before
Also the request doesn't show the content-type being sent. I supposed it was being sent as application/octet-stream so I added this custom MediaTypeFormatter I found and it still didn't work.
I am filling the PDF fields using iTextSharp and the sending it to the client. The client creates a BLOB URL to display it in an iframe. I noticed that the problem is due to this, because when opening the PDF by itself and filling the data manually and then submitting it works fine, so the problem has to be either when I fill the form fields or when I create the BLOB URL in the client.
That's an Adobe format called FDF (Forms Data Format) but that's just one option for the submit format. You can also submit the data as the equivalent of an HTML GET using the settings shown in the images below.
If your API can accept data from HTML forms, it should work from Acrobat as well.
How do I code the "CreateSubmitForm" command so that it generates a button that will submit an edited PDF back as HTTP POST?
First things first: submitting an edited PDF is only possible if the end user has Adobe Acrobat or if the PDF is Reader-enabled. In all other cases, you can only post the data (as a query string, as an FDF file, or as an XFDF file), you can not post the complete PDF from Adobe Reader.
By default, the submit button will be sent to the server as a HTTP POST. If you want HTTP GET, you need to set a flag. In other words: just create the button and you'll have an HTTP POST.
Important: the POST is performed from the PDF viewer, so it is very important to understand that you can not put any HTML in your Response. The PDF viewer will show an exception if you do. The PDF viewer expects either nothing (status code 204: No Content) or a stream of PDF (or correctly formatted FDF). All other content types will be rejected.
Note: although the question is tagged as an iTextSharp question, this answer is not limited to iTextSharp. It's just the way things are with PDF and Adobe Reader.
Assume the situation, i have an UIWebView and signed in into my gmail account, i have received an e-mail with an attached pdf file. Now am clicking on the attachment link the webview will open the pdf file there itself.
At this time if am trying to read the html contents it returns NULL.
Please help me by giving an idea. Now how could i read/parse that pdf content already loaded in webview and store the data into NSString.
if you have the URL for the PDF file then directly load the URL in the WebView otherwise you have to use the NSURLRequest to download the file and then load the file from the local directory of the application. I shall be glad to provide you with the code of loading the PDF file from the local directory however I suggest you to google it.
with GWT 2.4, i'm developing a web ordering system wherein user can select items and put it in the cart then check it out after providing the quantity of each item. then, when user clicks PDF button, a pdf report will be generated based on the items found on the CellTable then the open with/save file dialog will appear.
How can do this one with GWT?
You have to make a request containing the data from client to server.
On the server side you handle the request, parse the data and generate the PDF file and then you send the response containing the PDF file and in the header you should set:
("Content-Disposition","attachment; filename="yourFileName.pdf");
when you click on PDF button the Asyncmethod call.You have to passed all details in async method to Serviceimplementaion class where your method going to implement.
After that you can use it itextPdf library for generate PDF.
You can use below link for create PDF file.
http://www.vogella.de/articles/JavaPDF/article.html