Cflock and iText

Developers,
I'm using CFMX 7 with iText. I have a form in which users can
select multiple pdf documents via checkboxes. After selecting a
number of checkboxes, they can either immediately hit the Submit
button to merge (using iText) all selected documents, or from a
dropdown box, select an image to be applied to the top of each
document, and then hit Submit, which will merge the documents
first, then apply the image to each page of the merged documents.
(reference this post for additional information:
iText
Watermark position issue)
The merging and watermarks work great; however the problem
I'm having now is what appears to be file corruption. Every now and
again, when a user selects the documents and an image, the page
processes, but returns a previously merged document with a previous
image applied. Looking at merged file on the server confirms that
the file is corrupt and sometimes I am able to delete the file and
then future selections merge correctly.
So I figured I could apply cflock - as this must be a race
condition issue - to prevent the corruption. However, I don't think
I fully understand it as it does not appear to be working. I have
some documentation where you are supposed to name the locks the
same and other documentation states to name one readonly and the
other exclusive.
Attached is my code below. Can someone please look and give
advice as how to proceed? Also, I can include the code from
mergeOnly.cfm and mergeWatermark.cfm if necessary.
Thanks.

Also, if you are replacing an _existing_ file, you might
consider using a temporary file, to avoid locking the entire call.
Then at the end, replace the existing file with the temporary one,
and delete the temp file.
Here is a good link on locking file renames:
http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49321#263456

Similar Messages

  • NetBeans and iText

    hi everyone,
    I am new to netbeans and iText. I have to do a project using them, so any one can help me about how to use iText in NetBeans, means how can I configure NetBeans for iText. I have downloaded iText.jar file from iText website.
    Thanks in advance

    Hello.
    Im not sure what do you want to do, but here is a more detailed code which u can see how to check or uncheck a radio button using itext:
    try {
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("radiobutton.pdf"));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    cb.moveTo(0, 0);
    PdfFormField radio = PdfFormField.createRadioButton(writer, true);
    PdfAppearance tpOff = cb.createAppearance(20, 20);
    PdfAppearance tpOn = cb.createAppearance(20, 20);
    tpOff.circle(10, 10, 9);
    tpOff.stroke();
    tpOn.circle(10, 10, 9);
    tpOn.stroke();
    tpOn.circle(10, 10, 3);
    tpOn.fillStroke();
    radio.setFieldName("CreditCard");
    radio.setValueAsName("MasterCard");
    PdfFormField radio1 = PdfFormField.createEmpty(writer);
    radio1.setWidget(new Rectangle(100, 700, 120, 720), PdfAnnotation.HIGHLIGHT_INVERT);
    radio1.setAppearanceState("MasterCard");
    radio1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff);
    radio1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "MasterCard", tpOn);
    radio.addKid(radio1);
    PdfFormField radio2 = PdfFormField.createEmpty(writer);
    radio2.setWidget(new Rectangle(100, 660, 120, 680), PdfAnnotation.HIGHLIGHT_INVERT);
    radio2.setAppearanceState("Off");
    radio2.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff);
    radio2.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Visa", tpOn);
    radio.addKid(radio2);
    PdfFormField radio3 = PdfFormField.createEmpty(writer);
    radio3.setWidget(new Rectangle(100, 620, 120, 640), PdfAnnotation.HIGHLIGHT_INVERT);
    radio3.setAppearanceState("Off");
    radio3.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff);
    radio3.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "American", tpOn);
    radio.addKid(radio3);
    writer.addAnnotation(radio);
    catch(DocumentException de) {
    System.err.println(de.getMessage());
    catch(IOException ioe) {
    System.err.println(ioe.getMessage());
    this is just a way to do it, if this not what do you want to do, just post again!
    Belthazor

  • APEX and iText PDF generation

    Hi,
    Has any one used iText in apex to generate PDF documents in APEX. The reason for me to look for a solution to generate PDF documents like invoice, Purchase Order for different customer in different format. Since the online hosting companies have different reporting services like (JasperReport/Oracle BI publisher etc) it is a pain full procedure to have rtf and XML-FO. If I use iText within the PL/SQL procedure which will generate PDF document by supplying PDF form and XML data.
    In this case the client can create there PDF form which can be filled by XML data.
    Thank you.

    I had a look but seems like I have use command line to execute the process. You do.
    I want to generate from PL/SQL. My package does. Mind you -- I have to make use of a host command to perform the actual integration. When a process 'prints' to a PDF, it supplies the PDF form to be filled in, the specific fields to be filled in, and the values for the fields. I write these values out to an FDF file for the appropriate PDF form on the OS, then call PDFTK via a host command to integrate the blank PDF and the newly-created FDF into a 'filled' PDF form. I then email the completed PDF file to the user that requested it.

  • Servlet and iText pdf creator

    Hi,
    I have seen that all examples using iText and servlets send the pdf through the browser by using:
    response.setContentType("application/pdf");
    PdfWriter.getInstance(document, response.getOutputStream());
    I would need that besides send that info, the servlet should store a pdf file on the local system where the web server is installed. Is that possible?
    Could you please attach a full example code?
    Thank you in advance.

    If you want to send output to two simultaneous output streams (one for the browser and the other to save the PDF in the server's filesystem), then the following may help:
    final public class Tee extends OutputStream {
        // Class Variables //
        /** First output stream to write to */
        final private OutputStream first;
        /** Second output stream to write to */
        final private OutputStream second;
        // Constructors //
         * Creates a Tee that will output to the two streams specified.
         * @param     first          First stream to write to
         * @param     second          Second stream to write to
        public Tee(final OutputStream first, final OutputStream second) {
            super();
            this.first = first;
            this.second = second;
        // Public Methods //
         * Writes the specified byte data to both streams.
         * @param     target          Data to output
         * @throws     IOException
         * @see          OutputStream#write(int)
        final public void write(final int target)
             throws IOException {
            first.write(target);
            second.write(target);
         * Flushes the data buffer of both streams.
         * @throws      IOException
         * @see          OutputStream#flush()
        final public void flush()
             throws IOException {
            first.flush();
            second.flush();
         * Closes both streams.  If an exception occurs when the first stream is closed, the
         * second stream will be closed before the exception is thrown.
         * @throws     IOException
         * @see          OutputStream#close()
        final public void close()
             throws IOException {
            IOException thrown = null;
            try {
                first.close();
            catch (IOException e) {
                thrown = e;
            try {
                second.close();
            catch (IOException e) {
                thrown = e;
            if (thrown != null) {
                throw thrown;
    }- Saish

  • Create pdf using a .xdp file and iText

    Hello experts,
    my question is regarding the generation of a pdf file using a .xdp file and the iText API. I have an .xdp file of a designed form and I would like to generate a pdf using this file, the iText API and the context.
    Is it possible? are there any tutorials or examples? any help is welcome!
    Thanks in advance.
    Alperen

    Hi,
    Please check the following links:
    How to import an xdp-File to Web Dynpro Interactive Forms
    https://wiki.sdn.sap.com/wiki/display/XI/CODE-CreateaPDFFileviatheiText+Library
    Sample project how to use Itext (pdf) in webdynpro
    Itext PDF Creation
    Regards.
    Rajat

  • CFLock and Passing parameters

    Hello there, I have two questions...
    In numerous examples of site security, I've noticed the CFlock tag used. Hwoever, when looking at CF9 documentation, in a specific example of site security that includes user roles (using an application.cfc file) there is no mention of CFLocks. Are they necessary to authenticate users or not? I can't see why they would be. The variable being changed is the users status (authenticated or not) and since it is in the session scope, it is already unique, right? So why bother with CFLock?
    Second, how can I redirect a person to the same page they where on after submitting a form? I have a news letter form present on all pages of the website, and I would like the person to return to teh same page they where on when they submitted the form.

    @Mel.Husseini
    So why bother with CFLock?
    @Ian Skinner
    In pre-mx days, i.e. ColdFusion 4.5, ColdFusion suffered from a bad memory leak with shared memory variables like session.  One of the popular work arounds was to <cflock...> all reads and writes to these variables.  That has long been unnecessary, but there is still tons of old code examples and old developers that continue to utilze this work around.
    Those are issues that are resolved by the fact that Coldfusion is now a thread-safe Java application. However, there are other uses for cflock.
    Here are some examples. A web shop application may store the shopping cart in session scope. A session lock would then be necessary, for example, to prevent the customer from adding an item while his order is proceeding to checkout. You need a named lock to ensure that one user completely uploads or writes to a file, before another can read it. 
    @Mel.Husseini
    Second, how can I redirect a person to the same page they where on after submitting a form? I have a news letter form present on all pages of the website, and I would like the person to return to teh same page they where on when they submitted the form.
    There are CGI variables and Coldfusion functions that give the value of the current page. Coldfusion also passes the current page as an argument in the onRequestStart event of Application.cfc. Put the value in a hidden field in the form. Then, on the action page, use cflocation to redirect to it.

  • How is cflock and cffinally guaranteed?

    Consider this
    <cflock ...>
       <cftry>
       <cfcatch>
          <cfexit method="exittemplate">
       </cfcatch>
       </cftry>
    </cflock>
    Will the </cflock>-related code execute despite the <cfexit> or maybe even <cfabort>?
    Unfortunately, one cannot write
    <cftry>
       <cflock ...>
    <cfcatch>
       <cfexit method="exittemplate">
    </cfcatch>
    <cffinally>
       </cflock>
    </cffinally>
    </cftry>
    Or will this do what I want, regardless of whatever and where the exception is thrown?
    <cftry>
       <cflock ...>
       </cflock>
    <cfcatch>
       <cfexit method="exittemplate">
    </cfcatch>
    </cftry>
    Anyone to make this more clear to me?
    Thank you
    Martin

    My instinct is that the first approach will work fine: CF needs to be clever enough to clear locks even when the closing CFLOCK tag is never encountered. This would be pretty easy for you to test, really.
    Either the first or third approach will work: if all that's happening in the CFCATCH is the CFEXIT call, then you don't need to have that in the lock anyhow: there's nothing that needs locking.
    If there was code in the CFCATCH that needed to be within the same lock as the rest of the code, then the first approach would be necessary.
    Adam

  • IText and setExtraMargin

    I've been going around and around on trying to get a properly
    formatted flat pdf created with my data. I have to say that Adobe's
    ability to actually format a multi-line field as it was presented
    when it was editable is frustrating. CFMX8, pdfTK and iText all
    have the same problem of aligning the data in a multi-line field to
    the top when the pdf is flattened. activePDF is the only app i've
    found that does the formatting correctly, but they have SO many
    other issues with correctly populating a complex form that I'm back
    to trying to make something like iText work correct.
    I found this function for iText called setExtraMargin(); and
    it works perfect with the values 0, 6 to jog the text down. Now my
    problem is how to set this dynamicly based on if the the field is
    multi-line or not.
    I found this bit of code, but I'm not able to figure out how
    to convert this to <cfscript>. I need to be able to loop over
    something like this for each form key/value pair I'm inserting back
    into the pdf template.
    Any help would be great.
    I'm currently testing on MX8 if it makes a difference. Altho
    i will eventually trying to make this work on a cf4.5.1 server.
    --Dennis--

    > but need to chk each field for the FF_Multiline value
    for that field
    No. I think PdfFormField.FF_MULTILINE is a constant value
    used to represent that a field
    is multi-line.
    Looks like you extract the field's setting into a variable
    named "n" here:
    PdfNumber n = (PdfNumber)merged.get(PdfName.FF);
    The value is then compared to the constant
    PdfFormField.FF_MULTILINE. If the values are equal it means the
    field is multiline.
    if (n != null && (n.intValue() &
    PdfFormField.FF_MULTILINE) !=0)
    af.setExtraMargin(0, 6);

  • Problem with application-variables - CFLOCK?

    Hi,
    i have a problem with my application. It is a multi-user
    application with 100 parallel-users and CFMX 7.
    The problem wich occures is with application variables. These
    are mainly structs wich get filled onApplicationStart(). The
    problem is, that the variables suddenly disappear, they are empty.
    I have read about CFLock and found out, that it is necesseary
    to use cflock. And i found out, that onApplicationStart does
    correct locking automatically. That is where i do not understand
    the problem. The variables get intialized correctly and in further
    they only get read-access. Why can they be corrupted?
    My other question about that is, wheather i need cflock for
    all Read-Access to Application and Session-Variables, even if there
    happens no writing to the variables?
    Best Regards,
    Andreas

    > ?The element of position 2, of dimension 2, of an array
    object used as part of
    > an expression, cannot be found.?
    > The array is in this case the struct.
    Well, OK, that could be a problem. Arrays are not structs:
    they are two
    different things, are not interchangeable, and have
    completely different
    sets of functions to utilise them. You cannot treat a struct
    as an array.
    If CF is claiming your "struct" is an array, then it actually
    *is* an
    array, not a struct.
    What's the line of code which is generating that error?
    I suppose one could get this error if you have an array of
    structs thus:
    myArray
    .key1
    myArray.key2
    (etc)
    and you're trying to reference it with a numeric key rather
    than by key
    name, eg:
    myArray
    [n]
    When n is an integer value, rather than a string (which
    corresponds to the
    name of the key).
    > > Have you trapped the error, done a <cfdump>
    of the application scope and
    > > checked to see if it's the whole lot going awry, or
    just some values?
    > I have not used cfdump for it, because the server had to
    be immediately
    > restarted for our customers. But i think, that it is
    not completely empty,
    > because the index runs to pos2 of dimenstion2.
    So does this not happen in your dev / testing environment?
    > Will
    > onApplicationStart() be called before? Or only if
    onRequestStart() returns true?
    I would ***-u-me that the application one would be called
    before the
    request one. It's pretty easy for you to test this though, I
    should think?
    (Sorry: for reasons beyond the scope of this conversation,
    we're still
    forced to use Application.cfm in our software, so I've only a
    passing
    knowledge of how Application.cfc works).
    > Here is the code from onRequestStart()
    > <cffunction name="onRequestStart"
    returntype="boolean">
    > <cfargument name="Requestedpage" required="yes" />
    > <cfscript>
    > var lFile = "/cargorent/Login.cfm";
    > var iPosn = ListFindNoCase( lFile,
    Arguments.Requestedpage );
    > if( iPosn gt 0 )
    > return true;
    >
    > if( NOT IsDefined( "session.user.Loginname" ) or
    session.user.Loginname eq
    > "" )
    > {
    > WriteOutput( "<p><p> The current user is no
    longer valid, please log in
    > again.</p></p>" & chr(10) & chr(13)
    > WriteOutput( "<script
    language=""javascript"">parent.location = ""
    http://"
    > & CGI.HTTP_HOST &
    "/Login/Login.cfm"";</script>" );
    > return false;
    > }
    >
    > return true;
    > </cfscript>
    > </cffunction>
    One thing I will say here is that I really think you should
    be separating
    your processing from your display. A function should do
    processing. it
    should pass that processing back to a CFM template which
    should handle
    whatever needs to be displayed on the browser. Although
    that's nowt to do
    with your current issue.
    Adam

  • How do I save and manipulate an attached document through gmail?

    How do I save and manipulate an attached document through gmail on my iPhone?

    I had a client that had hundreds of session variables
    scattered in hundreds of CF pages. There was very little CFLOCKing,
    and consequently the apps were quite unstable in a loaded
    environment.
    What I finally did was to copy the session scope variables to
    ses.request scope variables of the same name, then did a global
    replace of session. with ses.request. In OnRequestEnd.cfm, and
    immediately before all CFLOCATIONs, I copied ths ses.request scope
    back to session scope (locked, of course). There was no measurable
    performance hit, and the apps were rock solid.
    Perhaps you could copy your client variables to session
    scope; then back again in OnRequestEnd.cfm

  • How do I save and restore Session?

    Is it possible to have a user leave the site for a period of
    time, say 2 or 3 days, and when they come back, restore their last
    session and all the session variables? I have an idea of building a
    database and writing them all to the db on each page load with the
    last visited page, and then resetting from that on their next
    visit, but is there an easier way through Cold Fusion that I'm not
    aware of? Any assistance is apprecaited.

    I had a client that had hundreds of session variables
    scattered in hundreds of CF pages. There was very little CFLOCKing,
    and consequently the apps were quite unstable in a loaded
    environment.
    What I finally did was to copy the session scope variables to
    ses.request scope variables of the same name, then did a global
    replace of session. with ses.request. In OnRequestEnd.cfm, and
    immediately before all CFLOCATIONs, I copied ths ses.request scope
    back to session scope (locked, of course). There was no measurable
    performance hit, and the apps were rock solid.
    Perhaps you could copy your client variables to session
    scope; then back again in OnRequestEnd.cfm

  • What are correct steps of integrating and using jasper report with ADF 11g?

    Hi,
    I am using JDev 11.1.1.2.0 with ADF 11g.
    I want to use jasperreports 3.7.0 along with ADF 11g to build reports in PDF on a button event. This is the first time I will be attempting it so before starting up I went through forum to get exact and clear steps on the jars and integration points of jasper with adf. There is exhaustive list but still it does not have the needed clarity.
    Can anyone help in listing down the jars and integration steps? and also want to know if there are any points in particular that I need to be aware of while running i along with ADF faces.
    Pls note the ver. of jasper and adf mentioned above.
    Thanks in advance.
    Edited by: user8925296 on May 14, 2010 4:06 PM

    Hi,
    Basically, you need to:
    - have all the jars in ViewProject/WEB-INF/lib, and include them to the project (Project properties -> Libraries and Classpath) - last time I did this was with version 3.1.3 and the necessary jars were jasperreports-3.1.3.jar, jcommon-1.0.0.jar and iText-2.1.4.jar (plus poi<+whatever is the latest version+>.jar if you want to generate .XLS reports)
    - call the code for generating reports from your backing bean (button's actionListener)
    - flush the report to the client (directly to HTTPResponse or by using af:fileDownloadListener)
    Those are the general steps, without going into the coding.
    Pedja

  • Add Image to Jasper Report with Struts 2 and Hibernate

    Hi I want to add image to jasper report[pdf] in the environment of Struts 2 framework and hibernate. I am trying
    this for last couple of days, but i am unable to get the work done. if any body know the steps to add image to
    jasper reports, please help me or if u have any tutorials please let me know. I am using iReport-nb-3.5.0 to generate jasper files.
    Thanks in advance

    Finally i found a way to add image to jasper report. It is pretty simple, just give the exact image location to the image expression. In your web application, the image location may vary so, dynamically set the image location from your model class. Also, make sure that your lib folder contains itext-1.3.1.jar. If your lib folder contains itext-1.3.1.jar and iText-2.1.3.jar u will get like: java.lang.NoSuchMethodError: com.lowagie.text.Image.plainWidth()F
    So remove the iText-2.1.3.jar and keep only itext-1.3.1.jar, try this will work

  • How to create tagged PDF using java iText

    Hi
    I want to create PDF for accessibility purpose using java and iText
    Please help.
    Thanks in advance

    i did this some yrs ago ..scratched and found some code for you. Have a look
    package com.oq.utility;
    import com.lowagie.text.Cell;
    import com.lowagie.text.Document;
    import com.lowagie.text.Element;
    import com.lowagie.text.Font;
    import com.lowagie.text.HeaderFooter;
    import com.lowagie.text.Image;
    import com.lowagie.text.PageSize;
    import com.lowagie.text.Phrase;
    import com.lowagie.text.Rectangle;
    import com.lowagie.text.Table;
    import com.lowagie.text.pdf.BaseFont;
    import com.lowagie.text.pdf.PdfWriter;
    import com.oq.model.Sale;
    import java.io.FileOutputStream;
    import java.util.ArrayList;
    import java.util.List;
    public class iTextExample
        public static void main (String[] args)
            iTextExample eg = new iTextExample();
            Sale sale = new Sale();
            sale.setOdrNumber("1");
            sale.setOdrDate("12-12-12");
            sale.setOdrCatCode("Örder");
            sale.setTotalInvValue("1234");
            sale.setRefNumber("in the line of fire");
            Sale sale1 = new Sale();
            sale1.setOdrNumber("1");
            sale1.setOdrDate("12-12-12");
            sale1.setOdrCatCode("Örder");
            sale1.setTotalInvValue("1234");
            sale1.setRefNumber("fire line");
            Sale sale2 = new Sale();
            sale2.setOdrNumber("1");
            sale2.setOdrDate("12-12-12");
            sale2.setOdrCatCode("Örder");
            sale2.setTotalInvValue("1234");
            sale2.setRefNumber("in the line of firel");
            List<Sale> list = new ArrayList<Sale>();
            list.add(sale);
            list.add(sale1);
            list.add(sale2);
            eg.printPDF(list);
        public void printPDF(List list) {
            Document document = new Document(PageSize.A4, 50, 50, 50, 50);
            try
                // creation of the different writers
                PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("iTextExample.pdf"));
                // various fonts
                BaseFont bf_helv = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false);
                BaseFont bf_times = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", false);
                BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", false);
                BaseFont bf_symbol = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", false);
                // headers and footers must be added before the document is opened
                HeaderFooter footer = new HeaderFooter(
                            new Phrase("This is page: ", new Font(bf_courier)), true);
                footer.setBorder(Rectangle.NO_BORDER);
                footer.setAlignment(Element.ALIGN_CENTER);
                document.setFooter(footer);
                HeaderFooter header = new HeaderFooter(
                            new Phrase("This is a header without a page number", new Font(bf_symbol)), false);
                header.setAlignment(Element.ALIGN_CENTER);
                document.setHeader(header);
                document.open();
                Image img = Image.getInstance("arrow-ff.gif");
                img.setAlignment(Image.RIGHT | Image.TEXTWRAP);
                Table goodTable = new Table(2);     
                      Cell cell1 = new Cell(img);
                goodTable.addCell(cell1);
                document.add(goodTable);
                Cell c = new Cell("Header");
                c.setHeader(true);
                goodTable.addCell(c);
                Cell c1 = new Cell("Header1");
                c1.setHeader(true);
                goodTable.addCell(c1);
                Cell c2 = new Cell("Header2");
                c2.setHeader(true);
                goodTable.addCell(c2);
                goodTable.endHeaders();
                int j=0;
                          while (j< list.size())
                              Sale sale = (Sale)list.get(j);
                              c = new Cell(sale.getOdrDate());
                              goodTable.addCell(c);
                              goodTable.addCell(sale.getRefNumber());
                             j++;
                document.add(goodTable);
                // add text at an absolute position
                document.close();
            } catch (Exception ex) {
                System.err.println(ex.getMessage());
        }

  • Printing and converting to pdf

    Hi,
    any ideas how should I do following tasks? I have a chart which I need to print or convert into pdf. Following code does the basics and now I need some advices.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.SwingUtilities;
    import javax.swing.JPopupMenu;
    import javax.swing.JMenuItem;
    public class MyChart extends Frame  {
         final Draw panel;
         public MyChart(){     
              addWindowListener(new WindowAdapter()     {     
                   public void windowClosing(WindowEvent ev)           
                   dispose();               
                   System.exit(0);
              setBounds(1,1,670,450);     
              panel = new Draw();     
              add(panel);          
              setVisible(true);
              MouseListener ml = new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                   if (SwingUtilities.isRightMouseButton(e)) {
                     Point p = e.getPoint();
                     System.out.println("Mouse pressed");
                }//mousePressed
                public void mouseReleased(MouseEvent e) {
                  if (SwingUtilities.isRightMouseButton(e)) {
                        Point p = e.getPoint();
                        MyPopupMenu jPopupMenu1 = new MyPopupMenu();
                        jPopupMenu1.show(panel, p.x, p.y);
                        System.out.println("Mouse released");
                }//mouseReleased
              };//mouseListener
              panel.addMouseListener(ml);
         public class Draw extends Panel{     
              int xt[] = {1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1};     
              int yv[] = {40,15,30,90,105,128,120,98,199,250,269,203,90,210,200,145};          
              int sx = 40;     
              int sy = 30;     
              public Draw(){     
                   super();     
                   setBackground(Color.pink);
              public void paint(Graphics g){      
                   g.setColor(Color.white);     
                   for (int i=0; i < 21; i++)     {          
                        g.setColor(Color.white);          
                        g.drawLine(i*30+sx,sy,i*30+sx,sy*10);          
                        g.setColor(Color.blue);          
                        g.drawString(""+i*30,i*sy+sy+2,30*10+30/2);     
                   for (int i=0; i < 10; i++)     {          
                        g.setColor(Color.lightGray);          
                        g.drawLine(sx,i*30+sy,20*30+sx,i*30+sy);          
                        g.setColor(Color.blue);          
                        g.drawString(""+i*30,10,i*sy+sy+2);     
                   g.setColor(Color.black);     
                   for (int i=0; i < xt.length-1; i++)     {          
                        if (xt[ i ] == 1)          
                             g.drawLine(i*30+sx,yv[ i ]+sy,(i+1)*30+sx,yv[ i+1 ]+sy);     
              public void update(Graphics g){     
                   paint(g);
         public class MyPopupMenu extends JPopupMenu {
              JMenuItem menuItem, menuItem2;
              public MyPopupMenu() {
                        menuItem = new JMenuItem("Print chart");
                        menuItem.addActionListener(new ActionListener() {
                          public void actionPerformed(ActionEvent e) {
                            System.out.println("Printing...");
                        menuItem2 = new JMenuItem("Convert to pdf");
                        menuItem2.addActionListener(new ActionListener() {
                          public void actionPerformed(ActionEvent e) {
                            System.out.println("Converting...");
                        add(menuItem);
                        add(menuItem2);
         public static void main(String[] args ) {     
              new MyChart();
    }

    I wrote a document a while back describing how to use JFreeChart and iText to generate charts in PDF format. You can download it from the JFreeChart project page on SourceForge:
    http://sourceforge.net/projects/jfreechart
    Look in the 'Files' section under 'Documentation' for a file called 'jfreechart2pdf-v2.pdf'. It should give you some pointers.
    Regards,
    Dave Gilbert
    JFreeChart Project Leader

Maybe you are looking for

  • PersistenceManager: Saving large amounts of data

    Hello, I am looking for the best way to save/cache songs in my music app after they have been download. I am using the PersistenceManager to save user login info, but what is the best way to save large files (like a 3 meg song(s))? Currently I am sto

  • Cant get iMovie and iPhoto.

    Few days later, I bought my macbook air. as you all know there are already installed Imovie and Iphoto, but this time they actually dont. i tried to bought in apple store its rather didnt work out. it allways asks for my apple id and then says that p

  • Copying multiple files to multiple locations

    I'll give you as much background detail as possible to help explain this one. We've made ourselves a little filemaker application, and at the moment I'm just working on creating a final disc image for it. I figure I'm going to create an Automator app

  • Problem to edit Custom section for Italian users

    Hi, In our system we have some users are set Italian as UI language in their profile. These users aren't able to edit custom sections when these Custom Sections are on a GSM spec. But the same users are able to edit the CS after I change UI Language

  • Do you have to pay to download previous purchases from itunes in the cloud

    to download music that you previously bought on itunes, do you have to pay for them again using the icould feature?