Strange characters instead of PDF-file

when I forward to a servlet called Test.java, my browser return a PDF file.
but when I write the method of the servlet in a bean, called WinkelWagen.java, and I write the rest of the code of the servlet in a jsp file (pdf.jsp, this jsp calls the method in the bean) I only get strange characters returned by my browser and Acrobat Reader doesn't run.
the code of the servlet Test.java:
package be.steppe.cursusdienst.pdf;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import be.steppe.cursusdienst.instellingen.Variabelen;
import be.steppe.cursusdienst.beans.WinkelWagen;
import be.steppe.cursusdienst.Product;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class Test extends HttpServlet
     public Test()
          super();
     public void doGet(HttpServletRequest req, HttpServletResponse resp)
          throws javax.servlet.ServletException, java.io.IOException
          DocumentException ex = null;
          ByteArrayOutputStream baosPDF = null;
          //HttpSession session = req.getSession(true);
          //WinkelWagen ww = (WinkelWagen) req.getAttribute("winkelWagen");
          //Vector vector = new Vector();
          //vector = ww.genereerFormLijst();
          try
               baosPDF = fix();
               StringBuffer sbFilename = new StringBuffer();
               sbFilename.append("filename_");
               sbFilename.append(System.currentTimeMillis());
               sbFilename.append(".pdf");
               resp.setHeader("Cache-Control", "max-age=30");
               resp.setContentType("application/pdf");
               StringBuffer sbContentDispValue = new StringBuffer();
               sbContentDispValue.append("inline");
               sbContentDispValue.append("; filename=");
               sbContentDispValue.append(sbFilename);
               resp.setHeader("Content-disposition",sbContentDispValue.toString());
               resp.setContentLength(baosPDF.size());
               ServletOutputStream sos;
               sos = resp.getOutputStream();
               baosPDF.writeTo(sos);
               sos.flush();
          catch (DocumentException dex)
               resp.setContentType("text/html");
               PrintWriter writer = resp.getWriter();
               writer.println(
                         this.getClass().getName()
                         + " caught an exception: "
                         + dex.getClass().getName()
                         + "<br>");
               writer.println("<pre>");
               dex.printStackTrace(writer);
               writer.println("</pre>");
          finally
               if (baosPDF != null)
                    baosPDF.reset();
     protected ByteArrayOutputStream fix() throws DocumentException {
          Document doc = new Document();
          ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
          PdfWriter docWriter = null;
          try
               docWriter = PdfWriter.getInstance(doc, baosPDF);
               doc.addAuthor(this.getClass().getName());
               doc.addCreationDate();
               doc.addProducer();
               doc.addCreator(Variabelen.getPdfAuteur());
               doc.addTitle("BESTELLING");
               doc.setPageSize(PageSize.LETTER);
               HeaderFooter footer = new HeaderFooter(
                                   new Phrase("BESTELLING     ID:           GEPLAATST DOOR:"),
                                   false);
               doc.setFooter(footer);
               doc.open();
/*                for(int i = 0 ; i < vector.size() ; i++) {
*                doc.add(new Paragraph( ((Product) vector.elementAt(i)).getProductId() ));
               doc.add(new Paragraph(
                              "This document was created on "
                              + new java.util.Date()));
          catch (DocumentException dex)
               baosPDF.reset();
               throw dex;
          finally
               if (doc != null)
                    doc.close();
               if (docWriter != null)
                    docWriter.close();
          if (baosPDF.size() < 1)
               throw new DocumentException(
                    "document has "
                    + baosPDF.size()
                    + " bytes");          
          return baosPDF;
}The code of the bean:
package be.steppe.cursusdienst.beans;
import java.util.Vector;
import be.steppe.cursusdienst.Product;
import be.steppe.cursusdienst.FormProduct;
import java.io.*;
import be.steppe.cursusdienst.instellingen.Variabelen;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class WinkelWagen implements Serializable {
  private Vector producten;
  public WinkelWagen() {
    producten = new Vector();
  public void voegProductToe(Product p) {
    producten.addElement(p);
  public Vector haalProducten() {
    return producten;
  public void verwijderProduct(int pId) {
    for(int i = 0 ; i < producten.size() ; i++) {
      if(pId == ((Product) (producten.elementAt(i))).getProductId()) {
        producten.removeElementAt(i);
        break;
  public void maakWinkelWagenLeeg() {
    producten.removeAllElements();
  public Vector genereerFormLijst() {
    int aantal = 0;
    Vector lijst = new Vector();
    boolean alInLijst;
    for(int i = 0 ; i < producten.size() ; i++) {
      aantal = 0;
      int prodId;
      alInLijst = false;
      Product p = (Product) producten.elementAt(i);
      prodId = p.getProductId();
      for(int l = 0 ; l < lijst.size() ; l++) {
        if(prodId == ((FormProduct) (lijst.elementAt(l))).getProductId()) {
          alInLijst = true;
      if(!alInLijst) {
        for(int q = 0 ; q < producten.size() ; q++) {
          if(prodId == ((Product) (producten.elementAt(q))).getProductId()) {
            aantal++;
        int pId = ((Product) (producten.elementAt(i))).getProductId();
        String tNaam = ((Product) (producten.elementAt(i))).getTypeNaam();
        String tit = ((Product) (producten.elementAt(i))).getTitel();
        String omschr = ((Product) (producten.elementAt(i))).getOmschrijving();
        double pr = ((Product) (producten.elementAt(i))).getPrijs();
        int hoev = ((Product) (producten.elementAt(i))).getStock();
        FormProduct formProduct = new FormProduct(pId,tNaam,tit,omschr,pr,hoev,aantal);
        lijst.addElement(formProduct);
      return lijst;
    public double berekenTotaal() {
      double totaal = 0;
      for(int i = 0 ; i < producten.size() ; i++) {
        Product p = (Product) producten.elementAt(i);
        totaal = totaal + p.getPrijs();
      return totaal;
    public ByteArrayOutputStream fix() throws DocumentException {
         Vector vector = genereerFormLijst();
         Document doc = new Document();
          ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
          PdfWriter docWriter = null;
          try
               docWriter = PdfWriter.getInstance(doc, baosPDF);
               doc.addAuthor("author");
               doc.addCreationDate();
               doc.addProducer();
               doc.addCreator(Variabelen.getPdfAuteur());
               doc.addTitle("BESTELLING");
               doc.setPageSize(PageSize.LETTER);
               HeaderFooter footer = new HeaderFooter(
                                   new Phrase("BESTELLING     ID:           GEPLAATST DOOR:"),
                                   false);
               doc.setFooter(footer);
               doc.open();
               for(int i = 0 ; i < vector.size() ; i++) {
               doc.add(new Paragraph( ((FormProduct) vector.elementAt(i)).getProductId() ));
               doc.add(new Paragraph(
                              "This document was created on "
                              + new java.util.Date()));
          catch (DocumentException dex)
               baosPDF.reset();
               throw dex;
          finally
               if (doc != null)
                    doc.close();
               if (docWriter != null)
                    docWriter.close();
          if (baosPDF.size() < 1)
               throw new DocumentException(
                    "document has "
                    + baosPDF.size()
                    + " bytes");          
          return baosPDF;
}the code of the JSP-file
<html>
<head>
</head>
<%@ page import="java.io.ByteArrayOutputStream" %>
<%@ page import="java.io.PrintWriter"%>
<%@ page import="be.steppe.cursusdienst.instellingen.Variabelen"%>
<%@ page import="be.steppe.cursusdienst.beans.WinkelWagen"%>
<%@ page import="be.steppe.cursusdienst.Product"%>
<%@ page import="java.util.*" %>
<%@ page import="com.lowagie.text.*" %>
<%@ page import="com.lowagie.text.pdf.*" %>
<jsp:useBean class="WinkelWagen" id="winkelWagen" scope="session" />
<body>
<%
ByteArrayOutputStream baosPDF = null;     
try
               baosPDF = winkelWagen.fix();
               StringBuffer sbFilename = new StringBuffer();
               sbFilename.append("filename_");
               sbFilename.append(System.currentTimeMillis());
               sbFilename.append(".pdf");
               response.setHeader("Cache-Control", "max-age=30");
               response.setContentType("application/pdf");
               StringBuffer sbContentDispValue = new StringBuffer();
               sbContentDispValue.append("inline");
               sbContentDispValue.append("; filename=");
               sbContentDispValue.append(sbFilename);
               response.setHeader("Content-disposition",sbContentDispValue.toString());
               response.setContentLength(baosPDF.size());
               ServletOutputStream sos;
               sos = response.getOutputStream();
               baosPDF.writeTo(sos);
               sos.flush();
          catch (DocumentException dex)
               response.setContentType("text/html");
               PrintWriter writer = response.getWriter();
               writer.println(
                         this.getClass().getName()
                         + " caught an exception: "
                         + dex.getClass().getName()
                         + "<br>");
               writer.println("<pre>");
               dex.printStackTrace(writer);
               writer.println("</pre>");
          finally
               if (baosPDF != null)
                    baosPDF.reset();
%>
</body>
          </html>can anyone please help me out ...
gr
Steppe

ok,
I removed the html tags in the jsp-file and now acrobat reader does start.
but it says the pdf file is damaged and cannot be repaired ...
any ideas?
gr
Steppe

Similar Messages

  • Problem to visualize characters in a pdf file

    Hello ,
    i'm from italy i have a problem with Adobe Reader X.
    I don't visualize some characters in a pdf file. On the arrow in the page there are numebrs and letter , actually there is a grey line .In the first page there is this phrase:
    If grey lines appear instead of words, please do the following. In Acrobat Reader
    go to --> File --> Preferences --> General. Make sure "Use Greek Text Below ____ Pixels" is deselected.
    In Reader there isn't this option........
    With another type of pdf reader i visualize correctly my pdf file.

    You need Adobe Acrobat to do it after it's a PDF file.  If you are in the parent application then you do that operation in the parent application before creating a PDF file from the document.

  • Chiness bold characters in the PDF file is not apperaing

    Hi,
    facing the problem, when i went to PO Display (ME23N) - Message -> selecting the output message like NEUA , -> Edit -> Display Originals .
    This time the chiness characters are displaying in the PDF file, but not in the bold format. Define the character format like Family - CNHEI, Size 8.0 and 6.0 with Bold on, Underlined On in both the case i am not able to getting the bold characters in the PDF file.
    Please give me any suggestion on this issue.
    Regards,
    Ravisankar - 9880517373

    ricardo-sa wrote:
    I bought Adobe Reader X ...
    Where did you buy Adobe Reader?  Adobe Reader can be downloaded for free from http://get.adobe.com/reader/
    As Michael already explained, the free Adobe Reader cannot convert anything; it is just a reader.

  • Strange-shaped fonts and unreadable characters in the PDF file

    Hello,
    A colleague of mine printed out a PDF file that I generated. Some of the fonts in the printed PDF file appear out-of-shape (slightly squiggly but still readable). These fonts are in plain body text and some of the heading styles. In addition, unreadable characters appear for fonts in the PDF where a keyboard input character format was specified in the source (in Framemaker a different character format can be specified for individual words within a paragraph format).
    He printed this PDF file a total of eight times. For the first five times there were no issues, but in the last three times the problems occured.
    He printed the files from the same printer and some of the printing was with the PCL profile, while others were with the PS profile.
    My colleague viewed the files using Adobe Reader 8 running on Windows XP.
    My PC is also Windows XP. The document source is FrameMaker 7.2. When generating the file, I used Acrobat Distiller 8.0. It is compatible with Acrobat 5.0 (PDF 1.0). The Acrobat Reader I have on my PC is Acrobat 8.0.
    Thanks,
    Ken

    I'm using acrobat 8.1.0 and I believe I have the same problem as Ken.
    However, I have a question. If the fonts simply weren't installed, wouldn't they also appear as weird characters when looking at a soft copy in acrobat? Why would the problem only occur when printing?

  • Adobe Acrobat 9 Pro making .log files instead of .pdf files

    I just uninstalled Acrobat 9 from one computer and installed it on my new one.  Now when I try to create a .pdf, it's creating a .log file instead. I have tried uninstalling again and installng it. Also, there is NOT a pdf hiding somewhere else. The program worked before on my other computer.

    If you are receiving a .log file, it typically means that an error has occurred during the creation of the PDF file from a PostScript or EPS file via the Distiller. Open up the .log file in NotePad (assuming you are on Windows) and see what it says! Likely, the problem is that you new system is missing some fonts from your old system.
            - Dov

  • Convert  strange  characters  to  compilance java file

    Hi guys
    I need help!
    How I can translate these strange characters
    into an compilance java file
    are these a memory locations ,machine language , or
    in which language they are written?
    thanks in advance.
    �� - y ��� � ()I ()J ()Ljava/lang/String; ()V ()Z (I)Ljava/lang/String; (IC)Ljava/lang/StringBuffer; (II)Ljava/lang/String; (J)V (Ljava/lang/Object;)Z &(Ljava/lang/String;)Ljava/lang/String; ,(Ljava/lang/String;)Ljava/lang/StringBuffer; (Ljava/lang/String;)V '(Ljava/lang/String;I)Ljava/lang/String; '(Ljava/lang/String;Ljava/lang/String;)V - 0000 <init> Code DC- Illegal key J
    SourceFile [DashoPro-V1.3BETA-091199] a append b c com/diginet/digichat/common/a3 com/esial/util/c d e equals f g h insert java/io/Serializable java/lang/Exception java/lang/IllegalStateException java/lang/Long java/lang/Object java/lang/String java/lang/StringBuffer java/util/Random length      longValue      substring toString 5 4 3 1 % / & 0 2 . 6      - 9 ! " $ ' ! # ,
    +
    '      (      $      ! ! ) 8 8 7
    : D
    ; E
    < F
    ; G
    ; H
    = I
    = H
    > J
    ; D
    ; K     > L     > M     > N     > O �
    > P
    > Q
    > R
    > S
    > T
    @ U
    A E
    > V
    < W
    < X
    < Y
    B D
    = E
    = Z 1 > B C ! # $ ' ! ? 3� :Y� [N� ;Y+� \:+� ]6� 0� ^W����� _� ! b V*� e     �� *� f     �� �� =Y*� f� `� aL� =Y*� e� `� aM*+� bL*,� bM� ;Y� c+� d,� d� _� # b V*� g     �� *� h     �� �� =Y*� h� `� aL� =Y*� g� `� aM*+� bL*,� bM� ;Y� c+� d,� d� _� $      * *� g i�<*� f i�= �� '      A 5*� h i�<*� f i�=*� f{ i�>�~6 �� (      D 8*� h i�<*� g{ i�=�~>*� e
    { i�6 �� *
    B .*� kW*� lW*� m� *� n� *� o � �L� + + ? +
    C 7*� g
    ��@*� f
    ��B!�� !     �� � �� AY� p� q� ,
    > 2*� g{
    �<*� e{
    �=
    � � �� AY� p� q� 1 9 � �*� rL+� s� �++� ]d� tM++� ]d� uN-� ]� !� ;Y� c-� ]d� t� d-� d� _N,� ]� !� ;Y� c,� ]d� t� d,� d� _M� ;Y� c� d-� d� d,� d� _� *� v� � �*� v� ;Y� c+� u� d+� t� d� _N,� ]6-� ]6*� =Y,d� u� w� x� g*� =Y,dd� t� w� x� h*� =Y-d� u� w� x� e*� =Y-dd� t� w� x� f�{code}{code}
    Edited by: vanpersie on Feb 9, 2008 12:35 PM

    This data is Bytecode of a Java class. Read about Java Bytecode structure in Java Documentation at SUN Site.

  • Strange Behaviour when opening pdf files using search results

    Hi
    I have observed inconsistencies between opening a pdf file when in the document library itself (it opens in a browser - good).
    However, when I click on a the same file in my search results having used Search and the Search Centre it opens in the adobe reader.  I would rather it opened in a browser rather than the adobe reader.
    The only difference I can see is that when opening from a document library the url ends in ".pdf", whereas when opening from the search results the url ends in ".pdf#search=<search string>.
    Anybody any ideas ?
    Regards
    Nigel
    Nigel Price NJPEnterprises

    Hi Nigel,
    According to your description, my understanding is that you want to open pdf from search result in browser.
    Firstly , permissive Browser File Handing in Central Administration, you can refer to the link:
    http://social.technet.microsoft.com/wiki/contents/articles/18858.sharepoint-2013-how-to-view-pdf-files-in-browsers.aspx
    Whether you are using OWA for SharePoint 2013. If Office Web Apps is not used for Search results of PDFs, the opening of PDFs in the browser passes the search terms into Adobe. So, if you don’t use OWA, please configure it for SharePoint 2013.
    More information, please refer to:
    http://stevemannspath.blogspot.com/2013/04/sharepoint-2013-pdf-support-and.html
    I hope this helps.
    Thanks,
    Wendy
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Wendy Li
    TechNet Community Support

  • Need to remove sixth and remaining characters from a PDF file name

    Typical file name:
    1925a - SomeotherTextHere.pdf
    Need to remove everything after and including the "-" symbol or the sixth position.
    I've tried this but to no avail:
    var filePath = this.path.replace(this.documentFileName,"");
    var newFileName = this.documentFileName.substring(0,6);
    this.saveAs(filePath + newFileName);
    Thanks in advance,
    Russell

    You were right......but a quick question. Why does this work without it? Thanks again!!!
    var filePath = this.path.replace(this.documentFileName,"");
    var newFileName = this.documentFileName.substring(1);
    this.saveAs(filePath + newFileName);

  • Not readable characters in generating PDF file...in Dev10g

    Hi ,
    When i generate the report to PDF ... all greek characters are not readable...
    Normally my Adobe 8.0 displays correctly the greek languages.
    Is there any solution...????
    Thanks,
    Sim

    Hello,
    If you want to generate an output with Greek characters, you have to use Font Subsetting or Font Embedding .
    http://download-uk.oracle.com/docs/cd/B14099_17/bi.1012/b14048/pbr_pdf.htm
    Oracle® Application Server Reports Services Publishing Reports to the Web
    10g Release 2 (10.1.2)
    B14048-02
    6 Using PDF in Oracle Reports
    Regards

  • Strange characters

    printer All-in-one Officejet Pro L 7580
    windows  XP
    i get strange characters when printing PDF files , sometimes the whole document and somethimes an part
    when i try to print 1 page a time it often comes out ok but not always

    Hi mamae,
    Looks like your Adobe program needs to be updated or reinstalled. Is this issue only appearing when you try to print PDFs? How about from Word processing programs like MS Word or Excel?
    If you have garbled text characters as well with your other programs, you also need to reinstall the printer drivers on your computer. When this happens on the USB connection, usually I had the cable replaced and that fixes it.
    You can also check this article - Continuous Pages of Strange or Garbled Characters Print in Windows
    Here's the Full Feature SW download for: Windows XP or Windows XP x64
    Hope this works for you!
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    Cheers!
    * If this post has helped you, the White Kudos star on the left is a great way to say thanks!
    * Please mark Accept As Solution if it solves your problem so other users can benefit as well.

  • PDF file will not print out Special Characters

    I am currently a technician for a college and, and the customer that I am attending currently has the following Problem:
    I am using Adobe PRO 9 to convert my Word files to pdfs for [a New York Printing Company].... The Greek letters used in Word are seen in Word, are seen in PDF, but do not come out in ...[the New York Printing Companies'] printing.
    What could be the stubling block for the NY printing company to not be able to print out the Special Characters in the PDF files? I clearly cannot go to the company myself and tell them to change their printer settings or something like that.

    Thank you, I have checked the font and I see all the fonts I need already installed. I am not sure if this will solve the problem, and there is a chance that the Adobe Acrobat settings on my customers PC need to be adjusted like you said.
    At least I can start looking somewhere .

  • How do I open PDF files on a website from my MacBook Air?

    I get only a blank page when I click on a pdf file on a website. (I am able to open in Safari with a right click.)
    I downloaded the PDF Viewer, but it didn't help.
    I went to TOOLS to disable blocking extensions, but none were listed.

    See:
    * https://support.mozilla.org/kb/pdf-files-are-blank-and-cant-be-downloaded-mac
    * https://support.mozilla.org/kb/Opening+PDF+files+within+Firefox
    Disable the Adobe Reader plugin in Firefox (Tools > Add-ons > Plugins) and use the external Adobe Reader application or Preview application instead.
    PDF files may be found under entries like Portable document or Adobe PDF document.
    *Firefox > Preferences > Applications > Adobe PDF document : Use Adobe Reader

  • Why can't I open PDF files in Firefox?

    I cannot get PDF files to open for viewing in Firefox. I am on Mac OS platform. This seems to be such an ongoing issue. I have followed the troubleshooting procedures to no avail. I like the look of Firefox better than Chrome, but I am switching over to Chrome because PDF's are so much easier to handle on Chrome, and I am sick of wasting time with this. Any last minute tips or advice?

    The Adobe Reader plugin may not be working properly on Mac.
    * https://support.mozilla.org/kb/pdf-files-are-blank-and-cant-be-downloaded-mac
    * https://support.mozilla.org/kb/Opening+PDF+files+within+Firefox
    Disable the Adobe Reader plugin in Firefox (Tools > Add-ons > Plugins) and use the external Adobe Reader application or Preview application instead.
    PDF files may be found under entries like Portable document or Adobe PDF document or Adobe Acrobat Document.
    *Firefox > Preferences > Applications > Adobe PDF document : Use Adobe Reader

  • My macBook Pro I click a link on a site for a PDF file and all I get is blank? I have done the preferance settings listed here but still blank. Please help

    When I open a PDF file from an internet site all I get is "Blank" . I have tried the preference settings listed here but it is still blank. Please help

    Disable the Adobe Reader plugin in Firefox (Tools > Add-ons > Plugins) and use the external Adobe Reader application or Preview application instead.
    PDF files may be found under entries like Portable document or Adobe PDF document or Adobe Acrobat Document.
    *Firefox > Preferences > Applications > Adobe PDF document : Use Adobe Reader

  • In quick view mode, why can't I enlarge pdf files like it used to?

    When I use quick view mode by pressing space bar when I have selected a file, say pdf files, I could used  to stretch the corners to get the page larger. But now, in Lion, it doesn't behave like that anymore. The page stays the same size however wide I stretch the quick view window. Is there an option to fixing this? Or is this intended? It is very bad indeed!

    The Adobe Reader plugin may not be working properly on Mac.
    * https://support.mozilla.org/kb/pdf-files-are-blank-and-cant-be-downloaded-mac
    * https://support.mozilla.org/kb/Opening+PDF+files+within+Firefox
    Disable the Adobe Reader plugin in Firefox (Tools > Add-ons > Plugins) and use the external Adobe Reader application or Preview application instead.
    PDF files may be found under entries like Portable document or Adobe PDF document or Adobe Acrobat Document.
    *Firefox > Preferences > Applications > Adobe PDF document : Use Adobe Reader

Maybe you are looking for

  • How to connect my xbox 360 through my linksys - WRT54G

    Hi, I do not understand why my xbox's built in wireless system does not find my linksys router (in order to play online via the internet) providing that other devices in my house such as laptops and phones do. Iv'e heard that these routers may be set

  • Acrobat X and Yosemite Issues

    I have been using acrobat 10 and OS Mavericks to manage my office documents using a Fujitsu scanner. After I upgraded to OS Yosemite, I have been unable to print any of the documents that I have scanned. The image of the doc will show up on the print

  • Record set per message

    hi if suppose this is my input structure <car> <color = red/> <manufavture = 200/> <car/> i want to know the entire structure above is 1 recordset per message,please explain the difference between recordset per message and a mesage.

  • Discount not required for a particular line item in PO

    Hi All,   There is one requirement wherein PO contains 500 line items, in which discount should not be applicable to a particular line item , whereas all the other line items should consist of discount.   Making a separate PO for that particular line

  • Pulling keys on shiny objects - how to implement holdouts?

    I am working on pulling a key in Shake, using the Keylight node. The fg is a close-up of a hand holding a coin, and I am using trackers on the hand to matchmove an inverted rotoshape that goes to the garbage matte input of the Keylight. The idea is t