Opening a PDF through a servlet

I have been trying to open a PDF document using a servlet for quite a while now and I am making no progress.
I have gotten the file to pass through to the browser at least 3 different ways, however, when I access the servlet using IE I get an error. The interesting thing is that when I refresh the page, the PDF file opens just fine.
Is there any trick to doing this? I can use the redirect directly to the PDF file:
res.sendRedirect("http://localhost:9080/test.pdf");The problem there is that I need the users to bookmark the servlet, not the PDF. In fact I do not even want the user to know where the PDF is.
Any help is greatly appreciated.

Dear Mark,
Perhaps this will help you:
public void doService (HttpServletRequest request, HttpServletResponse response)
response.setContentType("application/pdf");
String contentDisposition = "attachment; filename=\"test.pdf\"";
response.setHeader ("Content-Disposition", contentDisposition);
javax.servlet.ServletOutputStream sos = response.getOutputStream();
java.io.File file = new java.io.File("test.pdf");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
byte[] data = new byte[1000];
while (fis.read(data) != -1)
sos.write(data);
sos.close();
I have not tested the code, but I think you got the idea.
Greetings Michael

Similar Messages

  • I have a pdf file attached to email inbox for ipad3.  I also have an neu.Annotate  app for pdf.  Can anyone tell me how to open my pdf through neu.Annotate and save the file?

    How do I save the pdf on ipad3?  How can I view the fiel from neu.Annotate so that I could do the editing from the app?

    If the PDF isn't already downloaded in the email then you should be able to do so by tapping on it.
    If the PDF is open within the body of the email then press and hold it and after a second or so you should get a 'Open In' pop-up; otherwise (e.g. the PDF opens into a separate screen) then tap the PDF and you should get an icon top right of a box with an arrow coming out of it - tap that and you'll get the 'Open In' option

  • Can't open pdfs through ie8/9 crashes upon opening

    adobe reader plugin crashes when trying open pdfs through internet explorer 8 or 9 i have windows vista 32 bit home premium i need to get assignments for class but can't with the plugin crashing all the time when opening the file to view it adobe plugin works fine on my laptop but not on my desktop  can anyone help me fix this

    i tried other browsers all give the same error when opening a pdf right now i can't even open the pdf through the schools moodle system where the pdfs are uploaded i tried firefox and google chrome no luck in opening or downloading

  • Use servlet to open a PDF at a specific page

    Is it possible to create a servlet to open a PDF file at a specific page?
    The equivalent of myPdf.pdf#page=12 but through a servelt using header of the response may be?

    This is easier solved outside of Acrobat. For example, if your clients download the PDF from a website, add a form with the text and an "I agree" button before you provide them the link to the file. Or if you send it to them by email, first send them an email to which they need to reply before getting the PDF.

  • Opening a pdf file through form 10g

    Dear all,
    I have requirement to open a pdf file through my form application.
    Ho will i do this?
    What is the procedure to do this??
    Please help me.
    Regards

    Can you tell me where the pdf can be found. Through a webserver or inside the database or is the pdf somewhere else?
    If the pdf is available through an url you could use web.show_document which can open the url/pdf document in a new browser window.
    If the pdf is inside the database you could download the pdf to the client using webutil and then open the pdf document using a host command.
    If the pdf is inside the database or by a url you can also use a forms bean. I've used forms bean bean to unload a pdf from the database and show it inside the forms application. Most important when using a forms bean is that the bean component can show all the fonts which are used inside the pdf. There are some free solutions which can not show i.e. bar codes. The are also some paid components which will do the trick.
    Regards,
    Mark

  • Error while opening report in pdf through OAF.

    This is my first report through OAF and I followed a couple threads discussed on this but I am unable to debug this problem
    Requirement - User clicks the image and is prompted to open/save pdf result file.It doesnt take any user parameters
    Error is : I get prompted to open/save the pdf file . I click on Open or Save it and then Open, it gives me the following error :
    'could not open because it either is not a supported file or because the file has been damaged(for example , it was sent as an email attachement and wasnt correctly decoded)'
    Steps taken so far :
    1. Created VO with query select a,b,c from Table A
    2. Created a simple xml page, with a torch image : Set Action Type and Event property of the Torch Image Item to FireAction and GenerateReport
    3. Wrote the code in CO and AM to get the data in XMLNode.
    4. I did SOPs , copypasted the xml in notepad saved it as xml, loaded in MSWord and created a template.Viewing pdf generates a pdf here on this data
    5. With "XML Publisher Administrator" Responsibility, I created Data Definition and Template Definition.
    6. I deployed all the files on server and ran the report. It prompts me to open the pdf but it seems corrupted. In Jserv.log, xml gets printed through SOPs.
    One thing I noticed is: <?xml version="1.0"?> is missing from xml.
    please assist me , what am I missing here ?
    Thanks a lot.
    My CO code :
    public class EmpCO extends OAControllerImpl
    public static final String RCS_ID="$Header$";
    public static final boolean RCS_ID_RECORDED =
    VersionInfo.recordClassVersion(RCS_ID, "%packagename%");
    private static final String APP_NAME = "AK";
    private static final String TEMPLATE_CODE = "Emp_Template";
    private static final int BUFFER_SIZE = 32000;
    public void processRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processRequest(pageContext, webBean);
    OAApplicationModuleImpl am= (OAApplicationModuleImpl)pageContext.getApplicationModule(webBean);
    am.invokeMethod("initEmpVO");
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processFormRequest(pageContext, webBean);
    OAApplicationModuleImpl am= (OAApplicationModuleImpl)pageContext.getApplicationModule(webBean);
    String event = pageContext.getParameter("event");
    if("GenerateReport".equals(event))
    System.out.println("user clicked the pencil");
    // Get the HttpServletResponse object from the PageContext. The report output is written to HttpServletResponse.
    DataObject sessionDictionary = (DataObject)pageContext.getNamedDataObject("_SessionParameters");
    HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");
    try {
    ServletOutputStream os = response.getOutputStream();
    // Set the Output Report File Name and Content Type
    String contentDisposition = "attachment;filename=EmpReport.pdf";
    response.setHeader("Content-Disposition",contentDisposition);
    response.setContentType("application/pdf");
    // Get the Data XML File as the XMLNode
    XMLNode xmlNode = (XMLNode) am.invokeMethod("getEmpDataXML");
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    xmlNode.print(outputStream);
    System.out.println(" xml data");
    System.out.println(outputStream.toString()); //outputs the xml correctly
    ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    System.out.println("1**");
    ByteArrayOutputStream pdfFile = new ByteArrayOutputStream();
    System.out.println("2**");
    //Generate the PDF Report.
    TemplateHelper.processTemplate(
    ((OADBTransactionImpl)am.getOADBTransaction()).getAppsContext(),// AppsContext
    "AK",// Application short name of the template
    TEMPLATE_CODE,// Template code of the template
    "en", //language code of the template
    "US",//Country Code
    inputStream, //// XML data for the template
    TemplateHelper.OUTPUT_TYPE_PDF,//Output type of processed document
    null, //Properties
    pdfFile); //OutputStream where the processed data goes
    System.out.println("3**"); //doesnt print and goes in catch block
    // Write the PDF Report to the HttpServletResponse object and flush.
    byte[] b = pdfFile.toByteArray();
    System.out.println("4**");
    response.setContentLength(b.length);
    System.out.println("5**");
    os.write(b, 0, b.length);
    System.out.println("6**");
    os.flush();
    System.out.println("7**");
    os.close();
    System.out.println("8**");
    catch(Exception e)
    System.out.println("9**");
    response.setContentType("text/html");
    throw new OAException(e.getMessage(), OAException.ERROR);
    System.out.println("10**");
    pageContext.setDocumentRendered(false);
    System.out.println("11**");
    ///////////////------it prints only 1**, 2** and goes in catch block to print 9**
    AM Code :
    public void initEmpVO()
    EmpVOImpl vo = getEmpVO1();
    if(vo == null)
    {       MessageToken errTokens[] = { new MessageToken("OBJECT_NAME", "EmpVO1")   };
    throw new OAException("AK", "FWK_TBX_OBJECT_NOT_FOUND", errTokens);
    } else
    {        vo.executeQuery();      }
    public XMLNode getEmpDataXML()
    OAViewObject vo = (OAViewObject)findViewObject("EmpVO1");
    XMLNode xmlNode = (XMLNode) vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS);
    return xmlNode;
    }

    Hi,
    Basically the reason for this is that your "PDF file" is not populated with the correct pdf structure that Adobe recognizes (i.e. save the file and look at it in notepad, you'll see it's probably in html or a java stack trace). 2 reason's this happens
    1.You do not have the necessary library files attached to your project i.e. for XMLPublisher you will need $JAVA_TOP/oracle/apps/fnd/* and $JAVA_TOP/oracle/apps/xdo/*. Zip these up and add them to your libraries section of your project.
    2. Your XML Publisher properties are not configured correctly. (usually causes a blank file) To change this go to (E-Business Suite>XML Publisher Administrator>Administration>General>Temporary Directory). Depending on what your doing you will need to point this to either a server location or a local location. i.e. when uploading defintion/template and previewing it requires a server-side location to generate a temporary file for the preview, when running a jdeveloper project it will look for a local directory to generate the temporary file. If it cannot find the directory it will throw an error to System.out, and send the HttpServletResponse container a 0bytes file. For local development on a windows box I suggest setting the "Temporary Directory" to something like "C:\oracle" and ensure that folder exists.
    Hope this helps
    Brad

  • Problem in converting XML to PDF through Servlet

    Hi friends,
    I've a button in a page which should open a pdf from an existing xml. I've used the fop mechanism and servlet to do that. I've to deploy that in an unix/solaris environment. When i'm trying to do that it's giving me an exception at the place where it's trying to convert the file(transformer.transform(src,res)) It's as below..
    Thu Oct 20 14:43:47 IST 2005:<E> <ServletContext-General> Servlet failed with Exception
    java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
    at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
    at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:54)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:115)
    at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:53)
    at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1006)
    at org.apache.fop.svg.PDFGraphics2D.<init>(PDFGraphics2D.java:1401)
    at org.apache.fop.render.pdf.PDFRenderer.renderSVGDocument(PDFRenderer.java:638)
    Some one told me that there are some problems with unix env and graphics. If anyone had ever seen this problem before, pls reply. Thanks in advance.

    Hi Anil,
    Please mail across your outbound agreement export, ecs, XSD and XML which you are using for testing to my id (in my profile)
    Regards,
    Anuj

  • Disable Save, copy option of PDF through servlet

    Hi,
    I have a servet which displays the pdf files which is stored in a server. That is happening perfectly. But now i need to disable the pdf save copy all those options is that is possible through my servlet. i can control right click and ctrl c using java script but i don't know how i can handle the save as copy option. Any idea ???
    Regards
    Rasa

    rasa wrote:
    I too hate :-)
    But it is a client reqment.
    I am not using itext or pdfwriter calss. as i told i am just reading the file and just showing the user through a servlet. But still let me try the options which you have givenThe base Java libraries can't do what you want. As Saish indicated either the Adobe or iText libraries will be needed. Adobe doesn't sell their libraries separately - you'd have to purchase their giant application server to use it.

  • Open PDF through forms in apps

    I have a requirement where in I need to open a pdf document on click of a button. This document is a static doc for guideline/help purpose (for users accessing the form from apps). I want to know the best way to handle this. I can store the document in a table in the database but I do not know how to open/invoke it through froms in apps environment.
    we are using forms 10g and are in R12.
    Thanks in advance.

    See your /forms/server/forms.con file. You can see that some virtual directories are defined, for instance /forms/html
    AliasMatch ^/forms/html/(..*) "C:\DevSuiteHome_1/tools/web/html/$1"The physical directory is located on the Application Server.
    For a single test, you could put your PDF in the physical directory, then display the document within Forms via the Web.Show_Document() built-in
    Web.Show_Document('/forms/html/mydoc.pdf','_blank')You can also create new virtual directories in this file to handle your docs, for instance :
    AliasMatch ^/forms/pdf/(..*) "C:\DevSuiteHome_1/tools/pdf/$1"Francois

  • How to open the pdf document from KM  through Link to URL UI element

    Hi All,
    I have Link to URL UI element  in webdynpro java layout - on click of the link we need to open the pdf document from KM respository.
    KM Document location : irj/go/km/docs/documents/RHPortal//USA/A/Test/Employee_details.pdf.
    Once this is transported to Test and Production portals , we need to retrieve the KM document from the respective portal location through the Link to URL UI element .
    Thanks,
    Portaluser100

    Hi,
    If you set the link to your document in a Context attribute by using a relative path this should work just fine.
    Example:
    wdContext.currentContextElement().setUrl("/irj/go/km/docs/documents/RHPortal//USA/A/Test/Employee_details.pdf");
    Bind that attribute to the reference property of the LinkToURL element.
    Cheers,
    Leo

  • Hi I have just tried to convert a pdf through Adobe Export PDF, it appears to process it, but when I open the word file it just has the lines on it, and no words.

    hi I have just tried to convert a pdf through Adobe Export PDF, it appears to process it, but when I open the word file it just has the lines on it, and no words.

    Hi nickel13,
    What is the problem you are facing?
    Is this happening with a single PDF file?
    Regards,
    Florence

  • Problem with opening of PDF file, generated through smartform

    Recently, I have developed a new program where, the output of smartform will generate a PDF file, and then that PDF file will be mailed to concern persons,
    I have sucessuly done this in development server, and further testing I have transported this to Quality, in Quality i am able to generated a pdf file and able to send it to mail box of concern person, but when concern person tries to open the PDF file, it gives the error stating 'There was an error in opening the document, The file is damaged and could not be repaired'
    But same, I can able to read from development server.
    When I asked the Basis person, they are not aware about it, and , I have make it sure that, I have transported all request to Quality and nothing is pending in development.
    Can you please give me some idea to sort out this issue.
    Thanks in advance
    Rani

    Hi,
    I have same requirement.
    I need to cnvert smartform->pdf->send mail.
    The mail is send but the attachment is corrupted.
    Can you tell me what code you have written so its working in developement?

  • When I open a PDF directly in acrobat pro 11 it provides the review pane at the right hand side on clicking on Comment button. But when I open it through browser the review  pane is missing.

    The review pane is missing at the right hand side when I open a PDF in browser. I am using acrobat pro 11 and it is not even providing the option to prevent the PDF to open in browser.
    Also, the review pane appears when I launch the PDF in acrobat directly.
    Please could you help resolving this issue?

    How is Acrobat 8 not fully Windows 7 compatible?  I see discussions on this Adobe Community saying how Acrobat 8 does work on Windows 7 and with 64-bit.  It appears that if Acrobat 8 is updated to the latest version, then this should fix AA8-Win7 issues.  And I am at the latest AA8 version, 8.3.1. 
    And how are Acrobat 8 and Reader XI are not compatible?  I have always had Acrobat and Reader installed on the same PC, without ever having any issues.  And Adobe allows the installation of one after the other.  So apparently Adobe allows them both to exist together.  If they are incompatible, then why would Adobe allow them to exist together? 
    Anyway, I did uninstall the FileOpen Plug-in and the Reader XI, then reinstalled the FileOpen Plug-in.  So now Reader is not installed and only Acrobat 8 is installed.  I then tried to load the PDF file, but I still get the Acrobat 8 error described above. 

  • Open,save,view pdf through form

    Hi!
    1)I have to open a pdf using open dialog box(get_file_name)
    2)then saved it to a "new" location without openinig dialog box
    3)then view that file from the "new" location.
    currently i am using api but "one" dll should be in orant\bin to run this form at every PC.
    Host opens dos screen so it is not a good solution.
    is there any other oracle built-in to accomplish this task
    thanx

    Host opens dos screen so it is not a good solution.Please try the following code.
    DECLARE
    cmd varchar2(4000);
    s varchar2(4000);
    BEGIN
    cmd := 'copy /b c:\forms9iDemos9_0_0_1.zip c:\new_file.zip';
    TOOL_ENV.GETVAR( 'COMSPEC', s );
    Host( s || ' /c '||cmd, NO_SCREEN );
    END;

  • I can open a pdf from email on a laptop, not on the desktop. The desktop tells me invalid file format. I have went through the list from support.

    Had a virus on the desktop, then had a reformat, now I can not open adobe pdf in firefox from yahoo email. I have reinstalled Acrobat reader, same problem.I can open it in internet explorer. I can open it on the laptop.

    Hi Gary,
    I have seen this issue occur with users who have this registry setting missing or have improper permissions.
    When you double click the attachment to launch the pdf it is saved and opened from the temporary folder unless saved specifically to a location.
    If you dont have the below mentioned registry key or improper permissions then attachments fail to open.
    Please  heck if the following reg key exists:
    HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Security
    or
    HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\14.0\Outlook\Security
    Value Name: OutlookSecureTempFolder
    If the value exists, and if the value contains a valid path, Outlook 2010 uses that location for its temporary files.
    If the registry value does not exist, or if the value points to an invalid location, Outlook 2010, Outlook 2007, or Outlook 2003 creates a new subdirectory under the Temporary Internet Files directory and then puts the temporary file in the new subdirectory. The name of the new subdirectory is unknown and is randomly generated, depending on your version of Outlook.
    Please check the following key:
    HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Security
    Note the location for: OutlookSecureTempFolder key
    Check if the same folder exists in the following location and if not create a corresponding folder in the location on C:\Users\<User account name>\Appdata\Local\Software\Microsoft\Windows\......
    Regards,
    Rave

Maybe you are looking for

  • How do I capture footage from camera to an external drive using a macbook

    i'm trying to use my external drive to store my project because otherwise i don't have enough memory. however, there is i think only one firewire port on my macbook. if i connect the camera directly to the external drive it doesn't seem like fce can

  • The firefox button and the panorama view button are both missing in FF4 RC1

    I updated to FF4 RC1 two days ago and noticed that the panorama view button was missing and the firefox button, which is supposed to replace the File, Edit, View etc. menus had not done so. So basically, I'm still stuck with the FF3 style menu button

  • Transferring Podcasts from Mac to PC

    My iPod is in the shop, so I'd like to transfer all my podcasts from my Mac (where the iPod is usually docked) to my PC (where I do most of my daily work). The computers are networked, so there shouldn't be a problem copying the files, should there?

  • Après restauration de mon PC, pb d'accès aux vidéos et films

    après restauration de mon PC, et réinstallation d'itunes, je ne peux plus accéder à mes films et vidéos achetés précédemment sur Itunes, que ce soit sur mon PC      ou sur mon Ipad. Les musiques présentes sur mon ordi restent accessibles.

  • Updating software on my Mac 2008

    I have a Mac (purchased new in 2008) and am trying to update my software to version 10.8 (I have version 10.6)  It states that the update cannot be completed on my computer.....Is there any way I can install the software update on my computer?