codice:
<%
public sub InsertTesto(objPdf,H,stringa)
objPdf.WriteHtml H,stringa
end sub
dim imgPath 'cartella che contiente le immagini
dim hFont 'grandezza del font
dim hLinea 'altezza di una linea
dim idArticolo 'id dell'articolo
imgPath="fotoarticoli/"
hFont=12
hLinea=18
idArticolo=cint(request.QueryString("Idart"))
if idArticolo=0
then
response.Redirect("index.asp")
response.End()
end if
'************ APRO LA CONNESSIONE ************
set conn=server.CreateObject("adodb.connection")
conn.open "driver={Microsoft Access Driver (*.mdb)}; dbq=d:\inetpub\webs\zacintonet\mdb-database\zacintonet.mdb"
'ricavo il testo
sql="select a.ArticoloTesto as testo, a.ArticoloData as data,a.Firma as firma, u.memberUser as autore"
sql=sql & " from Articolo a, Member u where ArticoloCd=" & idArticolo & " and u.memberCd=a.memberCd"
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,3,3
testo=replace(rs("testo"),VBCRLF,"
")
data=rs("data")
firma=rs("Firma")
autore=rs("autore")
rs.close
'ricavo le foto
sql="select fotoNome from foto where articoloCd=" & idArticolo & " order by fotoNumero asc"
rs.open sql,conn,3,3
dim TOT
while not rs.eof
TOT=TOT+1
rs.movenext
wend
redim immagini(TOT)
i=0
rs.movefirst
while not rs.eof
immagini(i)=rs("fotoNome")
i=i+1
rs.movenext
wend
Set pdf=CreateJsObject("FPDF")
pdf.CreatePDF "P","pt"
pdf.SetPath("fpdf/")
pdf.SetFont "Arial","",hFont
pdf.LoadModels("NumeroPagina")
pdf.Open()
pdf.AddPage()
'stampo il Header
pdf.SetFont "Arial","BI",hFont+4
strHeader="Articolo di " & autore
pdf.MultiCell 0,hLinea, strHeader,0,"C"
pdf.SetFont "Arial","I",hFont
strHeader="del " & data
pdf.MultiCell 0,hLinea, strHeader,0,"C"
strHeader="fornito da www.zacinto.net"
pdf.MultiCell 0,hLinea, strHeader,0,"C"
pdf.SetFont "Arial","",hFont
fine=false
nuovo_testo=testo
while not fine=true
trovato=false
pezzo=""
allign=""
nomeImg=""
var=0
pezzo=""
partenza=1
altezza=""
larghezza=""
larghezza1=0
isImg=false
var=instr(partenza,nuovo_testo,"%")
if var>0 then
trovato=true
pezzo=mid(nuovo_testo,partenza,var-1)
'inserisco il pezzo di testo nel pdf
InsertTesto pdf,hLinea,pezzo
allign=mid(nuovo_testo,var+1,1)
'aggiorno il nuovo_testo
nuovo_testo=right(nuovo_testo,len(nuovo_testo)-var)
'ricavo la stringa per l'immagine
partenza=1
var=instr(partenza,nuovo_testo,"%")
if var>0 then
trovato=true
pezzo=int(mid(nuovo_testo,partenza+1,var-2))
if allign="l" or allign="r" or allign="c" then
isImage=true
end if
if isImage then
nomeImg=imgPath & immagini(pezzo-1)
Set objImageSize = New ImageSize
With objImageSize
.ImageFile = Server.MapPath(nomeImg)
altezza=.ImageHeight
larghezza=.ImageWidth
if larghezza>530 then
larghezza1=530
altezza=int( (larghezza1*altezza)/larghezza)
larghezza=larghezza1
larghezza1=0
end if
end with
set objImageSize=Nothing
altFoglio=pdf.GetY()
if (altFoglio+altezza)- 60>700 then
pdf.AddPage()
end if
altFoglio=""
if allign="l" then
pdf.Image nomeImg,34,pdf.GetY()+10,larghezza
pdf.SetY(pdf.GetY()+(altezza+10))
elseif allign="r" then
pdf.setX(560-larghezza)
pdf.Image nomeImg,pdf.GetX(),pdf.GetY()+10,larghezza
pdf.SetY(pdf.GetY()+(altezza+10))
elseif allign="c" then
pdf.SetX(300-int(larghezza/2))
pdf.Image nomeImg,pdf.GetX(),pdf.GetY()+10,larghezza
pdf.setX(300+(int(larghezza/2)+5))
pdf.SetY(pdf.GetY()+(altezza+10))
end if
altezza=""
larghezza=""
end if
nuovo_testo=right(nuovo_testo,len(nuovo_testo)-var)
end if
end if
if trovato=false then
fine=true
pdf.SetX(pdf.GetX())
pdf.SetY(pdf.GetY()+10)
InsertTesto pdf,hLinea,nuovo_testo
end if
wend
pdf.Close()
pdf.Output()
%>
le dimensioni dell'immagine sono ricavate con ImageSize