Skip to main content
Known Participant
January 31, 2011
Question

CF 9, iText PDF creation, MySQL database: Apostrophe disappears in output PDF

  • January 31, 2011
  • 1 reply
  • 5966 views

I create PDF files using iText. I insert variable data from a MySQL database into form fields (in an existing PDF file). I have an entry in the database "O'Malley" and (only on the output PDF file) the apostrophy is dropped, resulting in "OMalley". The name displays correctly in the database and in online cfm pages. All other special characters that I have tried display correctly in the PDF files as well as online pages. Any assistance would be appreciated.

    This topic has been closed for replies.

    1 reply

    Inspiring
    January 31, 2011

    Can you post a small (stand-alone) example that reproduces the problem?

    Known Participant
    January 31, 2011

    Are you requesting a URL or the code that is used to create the PDF file?

    Inspiring
    January 31, 2011

    Below is sample code. I also created a page that correctly displays the data (with apostrophe) on a standard webpage and with a link to the iText generated PDF file (that drops the apostrophe): www.accountmembers.com/register/name.cfm

    You will need to create two PDF files each with a text field labeled "name" (case-sensitive). One will be the input file and one will be the output file.

    <CFQUERY NAME="inputdata" DATASOURCE="xxxxxx" username="xxxxxxx" password="xxxxxxxxx">
    SELECT fullname FROM agents
    WHERE ID = 'xxxxx'
    </CFQUERY>

    <cfoutput query="inputdata">

    <cfset fullname = "#fullname#">

    </cfoutput>
    <cfset inputFilePath = expandPath(".") &"\folder\filenamein.pdf">
    <cfset outputFilePath = expandPath(".") &"\folder\filenameout.pdf">
    <cfscript>
    reader = createObject("java", "com.lowagie.text.pdf.PdfReader").init(inputFilePath);
    fos = createObject("java", "java.io.FileOutputStream").init(outputFilePath);
    stamp1 = createObject("java", "com.lowagie.text.pdf.PdfStamper").init(reader, fos);
    acrForm = stamp1.getAcroFields();
    acrForm.setField("name", fullname);

    stamp1.setFormFlattening(true);
    stamp1.close();
    fos.close();
    </cfscript>

    <cflocation url="folder\filenameout.pdf">


    Let me test it.

    BTW, I meant to ask - since you are running CF9 is there a reason you cannot use cfpdfform?