Skip to main content
November 19, 2009
Question

How to position text in an existing PDF document with X,Y coordinates

  • November 19, 2009
  • 2 replies
  • 659 views

There used to be a CFX PDF tag that could do this.  the company (www.easel2.com) does not appear to exist any more.

This is what i want to do.  I have an existing PDF file that is uploaded by a user.  I want to receive the file, then put a registration number (some text) in the lower left corner of the 2nd page (I don't know the exact x,y coordinate but I can figure that out later).

Does anyone know how I can do this?

    This topic has been closed for replies.

    2 replies

    November 20, 2009

    Solution above.

    Inspiring
    November 20, 2009

    Create an HTML page with the number. Convert that HTML page to PDF using cfdocument. Then use cfpdf action=watermark to add that PDF as a watermark to the PDF you have.

    November 20, 2009

    Unfortunately, I can not create the PDF.  It is uploaded by the user, and I have to open the PDF, insert the text and save it.  BUT, I did find the solution in a slight roundabout way.

    1) Create an image file containing the text I need

    2) Use that image file as a watermark with 10 opacity and use the tag's x,y coordinate setting.

    Below is the code I found to work:

    <!--- Create a blank image that is 500 pixels square. --->
    <cfset myImage=ImageNew("",500,500)>
    <!--- Set the background color for the image to white. --->
    <cfset ImageSetBackgroundColor(myImage,"white")>
    <!---Clear the rectangle specified on myImage and apply the background color. --->
    <cfset ImageClearRect(myImage,0,0,500,500)>
    <!--- Turn on antialiasing. --->
    <cfset ImageSetAntialiasing(myImage)>

    <!--- Draw the text. ---> 
    <cfset attr=StructNew()>
    <cfset attr.size=50>
    <cfset attr.style="bold">
    <cfset attr.font="Verdana">
    <cfset ImageSetDrawingColor(myImage,"blue")>
    <cfset ImageDrawText(myImage,"PROOF",100,250,attr)>

    <!--- Write the text image to a file. --->
    <cfimage action="write" source="#myImage#" destination="text.tiff" overwrite ="yes">

    <!--- Use the text image as a watermark in the PDF document. --->
    <cfpdf action="addwatermark" source="c:/book/1.pdf" image="text.tiff"
        destination="watermarked.pdf" overwrite="yes">