imagine kitty magazine

Skip over navigation
  • Categories

    • ASP.NET
    • Bible tags
    • Christianity
    • Classic ASP
    • Firearms
    • Humor
    • Random
    • Trackbacks
    • Web design
    • Web standards
    • Why I am the way I am
    • Wordpress
  • Pages

    • Bible verse tags 2.0
    • Portfolio
    • Steps to building a proper web page
  • Blogroll

    • benthack
    • ASP.NET Resources
    • Bible Dude
    • Cake Wrecks
    • Church Communications Pro
    • Creating Passionate Users
    • Dossy’s Blog
    • Gary Turner’s html & css workshop
    • I Will Teach You To Be Rich
    • Pescatarian Cooking
    • SystemDotWeb
    • The Nice Jewish Website
    • The Sneeze
    • Tyssen Design
  • Info

    • home
    • Log in
    • contact mark
    • blogs that link here*
    • valid xhtml
    • valid css
    • valid rss2
    • rss feed
Sigarms P229

spam this

« Making FTP work on Windows Vista
Firing a click event using the enter key »

FPDF.asp carriage return / line feed in MultiCell

Recently I was given the task of printing address labels from a database using Avery 5160 labels. These labels are 3 columns of 10 rows. 2.625″ x 1″ (66.6mm x 25.4mm).

I was having trouble with carriage returns. First problem is that the ASP version of FPDF doesn’t seem to recognize the \n line feed. It was easy enough to replace it with Chr(10) but I suppose I had a misconception of how FPDF handles line feeds in that it used the entire height of the multicell height for every line of text.

At first I used this incorrect code to test (notice the carriage return has no effect):<%@language=vbscript%>
<!--#include file="fpdf.asp"-->
<%
Dim i,pdf
Set pdf=CreateJsObject("FPDF")
pdf.CreatePDF "P","cm","Letter"
pdf.SetPath("fpdf/")
pdf.SetTopMargin(1.27)
pdf.SetLeftMargin(.42)
pdf.SetRightMargin(.42)
pdf.Open()
pdf.AddPage()
pdf.SetFont "Times","",9
for i=0 to 40
labelText = "Client #" & i & Chr(13) & "<--carriage return there address" & Chr(10) & "City, State Zip "
pdf.MultiCell 6.66,2.54,labelText,1,L
Next
pdf.Close()
pdf.Output()
Set pdf = Nothing
%>

with the results shown below:
bad line feeds

Then after googling a bit I found a php version of a script for creating a PDF for Avery 5160 labels and ported it to ASP:<%@language=vbscript%>
<!--#include file="fpdf.asp"-->
<%
Set pdf = CreateJsObject("FPDF")
pdf.CreatePDF "P","mm","Letter"
pdf.Open()
pdf.AddPage()
pdf.SetFont "Arial","B",10
pdf.SetMargins 0,0
pdf.SetAutoPageBreak(0)
x = 0
y = 0
' instead of for next call names and addresses from database
for a = 1 to 40
' Make label text
LabelText = "Contact Name" & a & chr(10) & "Entire Company Name" & a & chr(10) & "1313 Mockingbird Lane" & chr(10) & "Chicago, IL 60617"
LeftMargin = 4.2
TopMargin = 12.7
LabelWidth = 66.6
LabelHeight = 25.45
' Create Co-Ords of Upper left of the Label
AbsX = LeftMargin + ((LabelWidth + 4.22) * x)
AbsY = TopMargin + (LabelHeight * y)
pdf.SetXY AbsX+3,AbsY+3
pdf.MultiCell LabelWidth-8,4.5,LabelText,0,L
y=y+1
if (y=10) then
x=x+1
y = 0
if (x = 3) then
x = 0
y = 0
pdf.AddPage()
end if
end if
next
pdf.Output()
Set pdf = Nothing
%>

Just change the for-next loop to a database call and you’re in business.

I find FPDF extremely useful and am sure to use it in the future.

This entry was posted on 14Dec07 @ 2016 and is filed under Classic ASP. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

One Response to “FPDF.asp carriage return / line feed in MultiCell”

On 11Mar08 at 1159 JK said:

I think you need to be clearer as to the misconception that you tried to explain. I ran into the same problem and probably had the same brain boggle.

The issue is that I thought that the width and height applied to the entire multicell construct. It doesn’t. It applies to each line that is extracted from the text, as broken by the Chr(10).

The phraseology used by FPDF is not very conducive to rapid assimilation.

Sponsored links

Site5 $5 Hosting Dealemail address

Amazon Wishlist

Hello, friends! I've decided to put my Amazon wishlist online. If you feel nice today you can purchase one of the items listed and it will be shipped to my door. My birthday is May 13th and I will gladly accept gifts for any Christian or Jewish holiday. Thank you for your support.

  • RESTful .NET - $26.39
  • jQuery in Action - $21.29
  • People Are Idiots and I Can Prove It!: The 10 Ways You Are Sabotaging Yourself and How You Can Overcome Them - $16.50
  • Programming ASP.NET MVC - $29.69
  • Digital TENS Unit - Powerful Multi-mode TENS - One Week Sale! - n/a
  • Learning WCF: A Hands-on Guide - $25.18
  • Top Secret! - $4.09
  • Kentucky Fried Movie - $4.35
  • The Normal Christian Life - $2.51
  • The Holy Spirit and Reality - $2.51
  • The Richest Man in Babylon - $2.29
  • Tough Guys Don't Dance - $3.54
  • Get Crazy - n/a
  • Don't Let The Irs Destroy Your Small Business: Seventy-six Mistakes To Avoid - $6.88
  • Don't Make Me Think: A Common Sense Approach to Web Usability, 2nd Edition - $19.00
  • Dress Your Best: The Complete Guide to Finding the Style That's Right for Your Body - $11.23
  • Perfect Pushup - Original - $31.96
  • Pro ASP.NET MVC Framework (Pro) - $34.64
  • Benny Hill - Complete & Unadulterated Megaset (1969-1989) - $54.97
  • Young Doctors In Love - $2.78
  • Great White North - $6.37
  • Transylvania 6-5000 - $4.08
  • The Party - $6.14
  • Circuit-Bending: Build Your Own Alien Instruments (ExtremeTech) - $6.00

Disclaimer: All product data in this section belongs to Amazon.com or respective site(s). No guarantees are made as to accuracy of prices or product information. Prices listed are accurate as of the date/time indicated or otherwise within the last 24 hours. Prices and product availability are subject to change. Any price displayed on the Amazon website at the time of purchase will govern the sale of this product.

Site search and links

I'm a friend of Israel

Open Trackback Alliance Logo


Widgetize!
WWW is deprecated
no-WWW class B
*blogs that link here powered by Technorati

©2008 imaginekittymagazine