I have made this routine that is able to convert one or more file asci in txt
txt2pdf
I hope that maj be usefull for learn http://libharu.sourceforge.net/

compile using hbhpdf.hbc
/*
read info abour hbharu at http://libharu.org/wiki/Documentation/API/Graphics
 */



-------------txt2pdf.prg
#include "harupdf.ch"

//----------------------------------------------------------------------//

Function Main( cFileToRead, cFileToSave )
  if empty( cFiletoRead )
     cFiletoRead:= "txt2pdf.prg"
  endif

  if empty( cFileToSave )
     cFileToSave := "txt2pdf.pdf"
  endif
  HANDLE := fcreate("read.max")
            fwrite(HANDLE,"harbour test")
           fclose(HANDLE)
  delete file (cfiletosave)
  if CovertAsciiPDF(  {cFileToRead,"read.max"},cFileToSave )
     ? "PDF File <"+cFileToSave+"> is Created!"
     // run cFileToSave
  else
     Alert( "Some problems in creating the PDF!" )
  endif
  a=inkey(0)

  Return nil

//----------------------------------------------------------------------//

Function CovertAsciiPDF( acFileToRead,cFileToSave )
  local txt  ,x_ret
  local page,height,width
  Local pdf := HPDF_New()
  local tw
  local l,a
  if pdf == NIL
     alert( " Pdf could not been created!" )
     return nil
  endif
  // set compression mode
  hpdf_setpagemode(pdf,HPDF_PAGE_MODE_USE_OUTLINE)
  HPDF_SetCompressionMode( pdf, HPDF_COMP_ALL )
  page := HPDF_AddPage(pdf)
  height := HPDF_Page_GetHeight(page)
  width  := HPDF_Page_GetWidth(page)
  font := HPDF_GetFont( pdf, "Helvetica", NIL )
  ? page
  ? height
  ? width
  ? acFileToRead[1]
  ? cFileToSave
  fontsize=int(height/66)
  offset=(height-(fontsize*66))/2
  root = HPDF_CreateOutline(pdf, NIL, "File", NIL)
  HPDF_Outline_SetOpened(root, HPDF_TRUE)
  for a=1 to len(acFileToRead)
     if a>1
        page := HPDF_AddPage(pdf)
     endif
   ? acFileToRead[1]
   cFileToRead=   acFileToRead[a]
   outline = HPDF_CreateOutline (pdf, root,cFileToRead ,
HPDF_GetCurrentEncoder() )
   dst = HPDF_Page_CreateDestination (page)
   HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page), 1)
   // HPDF_Destination_SetFitB(dst)
   HPDF_Outline_SetDestination(outline, dst)
   //   HPDF_Page_Stroke( page )
   txtfile=memoread(cFileToRead)
   for l=1 to mlcount(txtfile,255)
     if l/66=int(l/66) .and. l<>1
       page := HPDF_AddPage(pdf)
     endif
     txt=memoline(txtfile,255,l,1,.f.)
     HPDF_Page_SetFontAndSize(page, font, fontsize)
     tw := HPDF_Page_TextWidth(page, txt)
     HPDF_Page_BeginText(page)
     HPDF_Page_MoveTextPos(page,2, HPDF_Page_GetHeight(page)-offset -
mod(l,66)*fontsize)
     HPDF_Page_ShowText(page, txt)
     HPDF_Page_EndText(page)
    next l
  next a
  x_ret= HPDF_SaveToFile( pdf, cFileToSave )
  ? x_ret
  HPDF_Free( pdf )
  Return file( cFileToSave )



2009/11/29 Viktor Szakáts <[email protected]>:
>> Well, as I said in another thread I completed a small OLE interface to
>> PdfCreator and it's ok at the moment. If I will need a pure Harbour
>> pdf generator (to run on linux for example) I will look at the library
>> based on Haru... it seems more complete and AFAIK it generates
>> compressed pdf files...
>
> You can very easily check the capabilities of hbhpdf for
> yourself by building and running its little test program
> (included in SVN).
>
> Brgds,
> Viktor
>
> _______________________________________________
> Harbour mailing list (attachment size limit: 40KB)
> [email protected]
> http://lists.harbour-project.org/mailman/listinfo/harbour
>



-- 
Massimo Belgrano

Iscritto all'albo dei CTU presso il Tribunale di Novara per materia Informatica
Delta Informatica S.r.l. (http://www.deltain.it/) (+39 0321 455962)
Analisi e sviluppo software per Lan e Web -  Consulenza informatica - Formazione
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to