imagine kitty magazine

Skip to main content
  • Categories

    • America
    • ASP.NET
    • Bible tags
    • C#
    • Christianity
    • Classic ASP
    • Firearms
    • Humor
    • LINQ
    • MVC
    • Programming
    • Random
    • Trackbacks
    • Web design
    • Web standards
    • Why I am the way I am
    • Wordpress
  • Links

    • ASP.NET Resources
    • Bible Dude
    • Cake Wrecks
    • Church Communications Pro
    • Creating Passionate Users
    • Dossy’s Blog
    • Gary Turner’s html & css workshop
    • id Projections
    • Information Pollination
    • SystemDotWeb
    • The Crazy Rants of Samantha Burns
    • The Nice Jewish Website
    • The Sneeze
    • Tyssen Design
  • Pages

    • Bible verse tags 2.0
    • Privacy Policy
    • Steps to building a proper web page
  • 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, Programming. 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

468x60-1 email address
Google
Custom Search

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.

Site search and links

I'm a friend of Israel

234x60

Open Trackback Alliance Logo


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

©2012 imaginekittymagazine