ddoc.dll Print and Preview...
Posted: Mon Jan 16, 2006 6:59 pm
I've just done an include file for "the great web divide"s ddoc.dll
Here is a test app:
The ddoc library is used to make it easier add a print preview and other functions to your program. I know you can do this thing with PureBasic directly, but its much easier with the dll and saves a lot of time.
The code was written for the registered one (it cost me $25 - thats £15!), but its well worth the money. It should be easy to fix it for the demo version of the dll.
see http://www.greatwebdivide.com for more info.
Code: Select all
; PureBasic Interface for the ddoc Print and Preview Engine
; Errors returned by dpStartDoc
#DDOC_NOHANDLES = -1
#DDOC_BADFILE = -2
#DDOC_FILEEXISTS = -3
; Status Codes returned by dpMailInit
Enumeration
#DDOC_MAIL_SUCCESS
#DDOC_MAIL_FNF
#DDOC_MAIL_LNF
#DDOC_MAIL_NOH
#DDOC_MAIL_HEIGHT_INVALID
#DDOC_MAIL_WIDTH_INVALID
#DDOC_MAIL_LABHEIGHT_INVALID
#DDOC_MAIL_LABWIDTH_INVALID
#DDOC_MAIL_COL_INVALID
#DDOC_MAIL_ROW_INVALID
#DDOC_MAIL_LINES_INVALID
EndEnumeration
; Unit of measure constants as passed to dpStartDoc
Enumeration
#DDOC_INCH
#DDOC_CM
EndEnumeration
; This can be passed in any of these iOptions parameters in
; dpStartDoc or dpEndDoc:
; Paper / Orientation / Bin
; If passed, then ddoc will respect
; the user's choice of orientation And Bin (Or the system
; defaults if not specified by the user).
#DDOC_SYSTEM_DEFAULT = -1
#DDOC_SAME_AS_FIRST = -2
#DDOC_PAPER_CUSTOM = -3 ; use custom paper size
; Orientation Constants for use with dpStartDoc
Enumeration
#DDOC_PORTRAIT
#DDOC_LANDSCAPE
EndEnumeration
; Paper Bin Constants used in dpStartDoc and dpNewPage
Enumeration 1
#DDOC_BIN_ONLYONE
#DDOC_BIN_LOWER
#DDOC_BIN_MIDDLE
#DDOC_BIN_MANUAL
#DDOC_BIN_ENVELOPE
#DDOC_BIN_ENVMANUAL
#DDOC_BIN_AUTO
#DDOC_BIN_TRACTOR
#DDOC_BIN_SMALLFMT
#DDOC_BIN_LARGEFMT
#DDOC_BIN_LARGECAPACITY
#DDOC_BIN_CASSETTE = 14
EndEnumeration
#DDOC_BIN_LAST = #DDOC_BIN_CASSETTE
#DDOC_BIN_UPPER = #DDOC_BIN_ONLYONE
#DDOC_BIN_FIRST = #DDOC_BIN_ONLYONE
; Paper Size Constants used in dpStartDoc and dpNewPage
Enumeration 1
#DDOC_PAPER_LETTER ; Letter 8 1/2 x 11 in
#DDOC_PAPER_LETTERSMALL ; Letter Small 8 1/2 x 11 in
#DDOC_PAPER_TABLOID ; Tabloid 11 x 17 in
#DDOC_PAPER_LEDGER ; Ledger 17 x 11 in
#DDOC_PAPER_LEGAL ; Legal 8 1/2 x 14 in
#DDOC_PAPER_STATEMENT ; Statement 5 1/2 x 8 1/2 in
#DDOC_PAPER_EXECUTIVE ; Executive"7 1/2 x 10 in
#DDOC_PAPER_A3 ; A3 297 x 420 mm
#DDOC_PAPER_A4 ; A4 210 x 297 mm
#DDOC_PAPER_A4SMALL ; A4 Small 210 x 297 mm
#DDOC_PAPER_A5 ; A5 148 x 210 mm
#DDOC_PAPER_B4 ; B4 250 x 354
#DDOC_PAPER_B5 ; B5 182 x 257 mm
#DDOC_PAPER_FOLIO ; Folio 8 1/2 x 13 in
#DDOC_PAPER_QUARTO ; Quarto 215 x 275 mm
#DDOC_PAPER_10x14 ; 10x14 in
#DDOC_PAPER_11X17 ; 11x17 in
#DDOC_PAPER_NOTE ; Note 8 1/2 x 11 in
#DDOC_ENV_9 ; Envelope #9 3 7/8 x 8 7/8
#DDOC_ENV_10 ; Envelope #10 4 1/8 x 9 1/2
#DDOC_ENV_11 ; Envelope #11 4 1/2 x 10 3/8
#DDOC_ENV_12 ; Envelope #12 4 \276 x 11
#DDOC_ENV_14 ; Envelope #14 5 x 11 1/2
#DDOC_ENV_DL = 27 ; Envelope DL 110 x 220mm
#DDOC_ENV_C5 ; Envelope C5 162 x 229 mm
#DDOC_ENV_C3 ; Envelope C3 324 x 458 mm
#DDOC_ENV_C4 ; Envelope C4 229 x 324 mm
#DDOC_ENV_C6 ; Envelope C6 114 x 162 mm
#DDOC_ENV_C65 ; Envelope C65 114 x 229 mm
#DDOC_ENV_B4 ; Envelope B4 250 x 353 mm
#DDOC_ENV_B5 ; Envelope B5 176 x 250 mm
#DDOC_ENV_B6 ; Envelope B6 176 x 125 mm
#DDOC_ENV_ITALY ; Envelope 110 x 230 mm
#DDOC_ENV_MONARCH ; Envelope Monarch 3.875 x 7.5 in
#DDOC_ENV_PERSONAL ; 6 3/4 Envelope 3 5/8 x 6 1/2 in
#DDOC_FANFOLD_US ; US Std Fanfold 14 7/8 x 11 in
#DDOC_FANFOLD_STD_GERMAN ; German Std Fanfold 8 1/2 x 12 in
#DDOC_FANFOLD_LGL_GERMAN ; German Legal Fanfold 8 1/2 x 13 in
EndEnumeration
; dpStartDoc Option Constants
#DDOC_VIEWBUILD = 1
#DDOC_ALLOWFAX = 2
#DDOC_ALLOWMAPI = 4
#DDOC_ALLOWSAVE = 8
#DDOC_ZOOMWIDTH = 64
#DDOC_ZOOMFIT = 128
#DDOC_ZOOM75 = 256
#DDOC_ZOOM100 = 512
#DDOC_ZOOM125 = 1024
#DDOC_SCALETEXT = 2048
#DDOC_FASTTEXT = 0
#DDOC_SAVE_EXE_ONLY = 4096
#DDOC_ALLOWSMTP = 8192
; Constants For dpDuplex
#DDOC_DUPLEX_HORIZONTAL = 16384
#DDOC_DUPLEX_VERTICAL = 32768
; Font Style Bit-wise constats for the dpFont call
#DDOC_FONTNORMAL = 0
#DDOC_FONTBOLD = 1
#DDOC_FONTITALIC = 2
#DDOC_FONTUNDERLINE = 4
#DDOC_FONTSTRIKEOUT = 8
#DDOC_FONTBASELINE = 16
; dpEndDoc Option constants
#DDOC_END_VIEW = 0
#DDOC_END_PRINT = 1
#DDOC_END_CLOSE = 2
#DDOC_END_DELETE = 4
#DDOC_END_PRINT_NODIALOG = 8
#DDOC_END_FAX = 16
#DDOC_END_EMAIL = 32
#DDOC_END_SPECIFIC_PRINTER = 64
#DDOC_END_CREATE_EXE = 128
; Text alignment constants for dpText, dpPageNo, dpPageCount
Enumeration
#DDOC_LEFT
#DDOC_CENTER
#DDOC_RIGHT
#DDOC_DECIMAL
EndEnumeration
; Error codes for dpSelfExtract
#DDOC_INPUT_NOT_FOUND = -5
#DDOC_OUTPUT_EXISTS = -4
#DDOC_ERR_OPEN_INPUT = -3
#DDOC_ERROR_OPEN_OUTPUT = -2
#DDOC_ERROR_OPEN_STUB = -1
#DDOC_SUCCESS = 0
; Button codes to Assign hints (captions) to buttons
; these will normally be used only by International users
; to replace the English INTs on the screen. Used by
; the dpCaption function
Enumeration
#DDOC_INIT_WORDS ; Initialization flag
#DDOC_MENU_FILE ; File Menu
#DDOC_MENU_DOC ; Document Menu
#DDOC_BTN_EXIT ; Exit button hint and exit menu
#DDOC_BTN_FIRST ; First Button hint and menu
#DDOC_BTN_PREV ; Previous Button hint and menu
#DDOC_BTN_NEXT ; Next button hint and menu
#DDOC_BTN_LAST ; Last Button hint and menu
#DDOC_BTN_JUMP ; Jump Button hint and menu
#DDOC_BTN_PRINT ; Print hint and menu
#DDOC_WORD_ZOOM ; Zoom label caption
#DDOC_WORD_ZOOMFIT ; Zoom Fit INT in drop down
#DDOC_WORD_ZOOMWIDTH ; Zoom Width in drop down
#DDOC_WORD_DOCINDEX ; INT Document index
#DDOC_WORD_PAGE ; Page
#DDOC_WORD_OF ; of
#DDOC_DLG_JUMP_TITLE ; jump dialog title
#DDOC_DLG_JUMP_TEXT ; dialog jump text
#DDOC_BTN_CANCEL ; cancel button
#DDOC_BTN_OK ; ok button
#DDOC_DLG_PW_TITLE ; passINT box title
#DDOC_DLG_PW_TEXT ; passINT text in dialog
#DDOC_DLG_PW_INVALID ; passINT is invalid (try again)
#DDOC_DLG_PW_CANCEL ; passINT invalid (3 strikes and you:'re out)
#DDOC_BTN_EMAIL ; email button
#DDOC_BTN_FAX ; fax button
#DDOC_BTN_SAVE ; save button
EndEnumeration
Global ddoc_libno
Procedure StartDDoc()
ddoc_libno=OpenLibrary(#PB_Any,"ddoc32.dll")
ProcedureReturn ddoc_libno
EndProcedure
Procedure StopDDoc()
If ddoc_libno
CloseLibrary(ddoc_libno)
ddoc_libno=0
EndIf
EndProcedure
; Document generation
Procedure dpStartDoc(hParent,zTitle$,zFile$,iUOM,iPaper,iOrient,iBin,iOptions)
ProcedureReturn CallFunction(ddoc_libno,"dpStartDoc",hParent,@zTitle$,@zFile$,iUOM,iPaper,iOrient,iBin,iOptions)
EndProcedure
Procedure dpNewPage(iHandle,iPaper,iOrient,iBin)
ProcedureReturn CallFunction(ddoc_libno,"dpNewPage",iHandle,iPaper,iOrient,iBin)
EndProcedure
Procedure dpBookmark(iHandle,zBookmark$)
ProcedureReturn CallFunction(ddoc_libno,"dpBookmark",iHandle,@zBookmark$)
EndProcedure
Procedure dpEndDoc(iHandle,iOptions)
ProcedureReturn CallFunction(ddoc_libno,"dpEndDoc",iHandle,iOptions)
EndProcedure
Procedure dpEndDocInst()
ProcedureReturn CallFunction(ddoc_libno,"dpEndDocInst")
EndProcedure
Procedure dpGetFileName(iHandle,zDoc$,iLen)
ProcedureReturn CallFunction(ddoc_libno,"dpGetFileName",iHandle,@zDoc$,iLen)
EndProcedure
Procedure dpChangeWords(iHandle,iWhich,zText$)
ProcedureReturn CallFunction(ddoc_libno,"dpChangeWords",iHandle,iWhich,zText$)
EndProcedure
Procedure dpSelfExtract(zInputFile$,zDDOC$,zOutEXE$)
ProcedureReturn CallFunction(ddoc_libno,"dpSelfExtract",@zInputFile$,@zDDOC$,@zOutEXE$)
EndProcedure
Procedure dpCheckAbort(iHandle)
ProcedureReturn CallFunction(ddoc_libno,"dpCheckAbort",iHandle)
EndProcedure
Procedure dpSetProgress(iHandle,iProgress)
ProcedureReturn CallFunction(ddoc_libno,"dpSetProgress",iHandle,iProgress)
EndProcedure
Procedure dpSetTabs(iHandle,zTabStops$)
ProcedureReturn CallFunction(ddoc_libno,"dpSetTabs",iHandle,@zTabStops$)
EndProcedure
Procedure dpTabText(iHandle,y.f,zText$)
ProcedureReturn CallFunction(ddoc_libno,"dpTabText",iHandle,@y,@zText$)
EndProcedure
; Document Options
Procedure dpSetPassword(iHandle,zPassword$)
ProcedureReturn CallFunction(ddoc_libno,"dpSetPassword",iHandle,@zPassword$)
EndProcedure
Procedure dpSetScreenOptions(iHandle,x,y,x2,y2,iMaximize)
ProcedureReturn CallFunction(ddoc_libno,"dpSetScreenOptions",iHandle,x,y,x2,y2,iMaximize)
EndProcedure
Procedure dpSetAttachExt(iHandle,zExt$)
ProcedureReturn CallFunction(ddoc_libno,"dpSetAttachExt",iHandle,@zExt$)
EndProcedure
Procedure dpSetEMailOptions(iHandle,zLogon$,zPassword$,zNames$,zAddress$,zSubject$,zNote$,iShowDialog,iMailSelfExtract)
ProcedureReturn CallFunction(ddoc_libno,"dpSetEMailOptions",iHandle,@zLogon$,@zPassword$,@zNames$,@zAddress$,@zSubject$,@zNote$,iShowDialog,iMailSelfExtract)
EndProcedure
Procedure dpSetFaxOptions(iHandle,zLogon$,zPassword$,zRecip$,zSubject$,zNote$,iShowDialog)
ProcedureReturn CallFunction(ddoc_libno,"dpSetFaxOptions",iHandle,@zLogon$,@zPassword$,@zRecip$,@zSubject$,@zNote$,iShowDialog)
EndProcedure
Procedure dpSMTPOptionsProcedure(hParent)
ProcedureReturn CallFunction(ddoc_libno,"dpSMTPOptionsProcedure",hParent)
EndProcedure
Procedure dpDuplexProcedure(iHandle,iHow)
ProcedureReturn CallFunction(ddoc_libno,"dpDuplexProcedure",iHandle,iHow)
EndProcedure
Procedure dpPaperSizeProcedure(iHandle,sgWidth,sgHeight)
ProcedureReturn CallFunction(ddoc_libno,"dpPaperSizeProcedure",iHandle,sgWidth,sgHeight)
EndProcedure
; Font and Text Functions
Procedure dpFont(iHandle,iStyle,Size.f,iColor,zFontName$)
ProcedureReturn CallFunction(ddoc_libno,"dpFont",iHandle,iStyle,Size,iColor,@zFontName$)
EndProcedure
Procedure dpText(iHandle,x.f,y.f,iAlign,zText$)
ProcedureReturn CallFunction(ddoc_libno,"dpText",iHandle,x,y,iAlign,@zText$)
EndProcedure
Procedure dpSpecialText(iHandle,x.f,y.f,iAlign,zText$)
ProcedureReturn CallFunction(ddoc_libno,"dpSpecialText",iHandle,x,y,iAlign,@zText$)
EndProcedure
Procedure dpFontSpacing(iHandle,dblPoints)
ProcedureReturn CallFunction(ddoc_libno,"dpFontSpacing",iHandle,dblPoints)
EndProcedure
Procedure dpWrapText(iHandle,x.f,y.f,x2.f,y2.f,leading.f,zText$)
ProcedureReturn CallFunction(ddoc_libno,"dpWrapText",iHandle,x,y,x2,y2,leading,@zText$)
EndProcedure
Procedure dpWrapContinue(iHandle,x.f,y.f,x2.f,y2.f,leading.f)
ProcedureReturn CallFunction(ddoc_libno,"dpWrapContinue",iHandle,x,y,x2,y2,leading)
EndProcedure
Procedure dpWrapCount(iHandle)
ProcedureReturn CallFunction(ddoc_libno,"dpWrapCount",iHandle)
EndProcedure
Procedure dpAngleText(iHandle,x.f,y.f,iAngle,zText$)
ProcedureReturn CallFunction(ddoc_libno,"dpAngleText",iHandle,x,y,iAngle,@zText$)
EndProcedure
Procedure dpClipText(iHandle,x.f,y.f,w,iAlign,zText$)
ProcedureReturn CallFunction(ddoc_libno,"dpClipText",iHandle,x,y,w,iAlign,@zText$)
EndProcedure
Procedure dpPageOffset(iHandle,iOffset)
ProcedureReturn CallFunction(ddoc_libno,"dpPageOffset",iHandle,iOffset)
EndProcedure
Procedure dpPageNo(iHandle,x.f,y.f,iAlign,iAngle)
ProcedureReturn CallFunction(ddoc_libno,"dpPageNo",iHandle,x,y,iAlign,iAngle)
EndProcedure
Procedure dpPageCount(iHandle,x.f,y.f,iAlign,iAngle)
ProcedureReturn CallFunction(ddoc_libno,"dpPageCount",iHandle,x,y,iAlign,iAngle)
EndProcedure
Procedure dpTextWidth(iHandle,Asciiz$)
ProcedureReturn CallFunction(ddoc_libno,"dpTextWidth",iHandle,Asciiz$)
EndProcedure
; Lines and Graphics
Procedure dpLine(iHandle,x.f,y.f,x2.f,y2.f,w.f,c)
ProcedureReturn CallFunction(ddoc_libno,"dpLine",iHandle,x,y,x2,y2,w,c)
EndProcedure
Procedure pArc(iHandle,x.f,y.f,x2.f,y2.f,aStart.f,aEnd.f,w.f,iColor)
ProcedureReturn CallFunction(ddoc_libno,"pArc",iHandle,x,y,x2,y2,aStart,aEnd,w,iColor)
EndProcedure
Procedure dpPie(iHandle,x.f,y.f,x2.f,y2.f,aStart.f,aEnd.f,w.f,ilineColor,ifillColor)
ProcedureReturn CallFunction(ddoc_libno,"dpPie",iHandle,x,y,x2,y2,aStart,aEnd,w,ilineColor,ifillColor)
EndProcedure
Procedure dpRect(iHandle,x.f,y.f,x2.f,y2.f,w.f,iFillColor,iBorderColor)
ProcedureReturn CallFunction(ddoc_libno,"dpRect",iHandle,x,y,x2,y2,w,iFillColor,iBorderColor)
EndProcedure
Procedure dpEllipse(iHandle,x.f,y.f,x2.f,y2.f,w.f,iFillColor,iBorderColor)
ProcedureReturn CallFunction(ddoc_libno,"dpEllipse",iHandle,x,y,x2,y2,w,iFillColor,iBorderColor)
EndProcedure
Procedure dpRoundRect(iHandle,x,y,x2,y2,roundW,roundH,w,iColor,iBorderColor)
ProcedureReturn CallFunction(ddoc_libno,"dpRoundRect",iHandle,x,y,x2,y2,roundW,roundH,w,iColor,iBorderColor)
EndProcedure
Procedure dpGraphic(iHandle,x.f,y.f,x2.f,y2.f,zFileName$)
ProcedureReturn CallFunction(ddoc_libno,"dpGraphic",iHandle,x,y,x2,y2,@zFileName$)
EndProcedure
Procedure dpEmbedGraphicProcedure(iHandle,x.f,y.f,x2.f,y2.f,zFileName$)
ProcedureReturn CallFunction(ddoc_libno,"dpEmbedGraphicProcedure",iHandle,x,y,x2,y2,@zFileName$)
EndProcedure
Procedure dpAddGraphic(iHandle,zFile$)
ProcedureReturn CallFunction(ddoc_libno,"dpAddGraphic",iHandle,@zFile$)
EndProcedure
Procedure dpDrawGraphic(iHandle,hBitmap,x.f,y.f,x2.f,y2.f)
ProcedureReturn CallFunction(ddoc_libno,"dpDrawGraphic",iHandle,hBitmap,x,y,x2,y2)
EndProcedure
Procedure dpStretchMode(iHandle,iStretch)
ProcedureReturn CallFunction(ddoc_libno,"dpStretchMode",iHandle,iStretch)
EndProcedure
; Printer Handling
Procedure dpPrinterCount()
ProcedureReturn CallFunction(ddoc_libno,"dpPrinterCount")
EndProcedure
Procedure.s dpGetPrinter(iWhich)
ProcedureReturn PeekS(CallFunction(ddoc_libno,"dpGetPrinter",iWhich))
EndProcedure
Procedure dpIsPrinter(zPrinter$)
ProcedureReturn CallFunction(ddoc_libno,"dpIsPrinter",@zPrinter$)
EndProcedure
Procedure dpSpecifyPrinter(iWhich,zPrinter$)
ProcedureReturn CallFunction(ddoc_libno,"dpSpecifyPrinter",iWhich,@zPrinter$)
EndProcedure
Procedure dpPrinterCopies(iWhich,iCopies)
ProcedureReturn CallFunction(ddoc_libno,"dpPrinterCopies",iWhich,iCopies)
EndProcedure
; Mailing Label API
Procedure dpMailInit(iHandle,szIniFile$,szIniSection$,nAlign)
ProcedureReturn CallFunction(ddoc_libno,"dpMailInit",iHandle,@szIniFile$,@szIniSection$,nAlign)
EndProcedure
Procedure dpLabelLines(iHandle)
ProcedureReturn CallFunction(ddoc_libno,"dpLabelLines",iHandle)
EndProcedure
Procedure dpLabelsPerPage(iHandle)
ProcedureReturn CallFunction(ddoc_libno,"dpLabelsPerPage",iHandle)
EndProcedure
Procedure dpLabelText(iHandle,szLabelLine$)
ProcedureReturn CallFunction(ddoc_libno,"dpLabelText",iHandle,@szLabelLine$)
EndProcedure
Procedure dpNextLabel(iHandle)
ProcedureReturn CallFunction(ddoc_libno,"dpNextLabel",iHandle)
EndProcedure
Procedure dpSetLabelLine (iHandle,nLabelLine)
ProcedureReturn CallFunction(ddoc_libno,"dpSetLabelLine",iHandle,nLabelLine)
EndProcedure
Procedure dpSetLabel(iHandle,nLabelNumber)
ProcedureReturn CallFunction(ddoc_libno,"dpSetLabel",iHandle,nLabelNumber)
EndProcedure
Procedure dpPrintTemplate(iHandle,LabAlign)
ProcedureReturn CallFunction(ddoc_libno,"dpPrintTemplate",iHandle,LabAlign)
EndProcedure
Procedure.f dpLabelX(iHandle)
CallFunction(ddoc_libno,"dpLabelX",iHandle,@sngX.f)
ProcedureReturn sngX
EndProcedure
Procedure.f dpLabelY(iHandle)
CallFunction(ddoc_libno,"dpLabelY",iHandle,@sngY.f)
ProcedureReturn sngY
EndProcedure
Code: Select all
; testp32.pb
; test program for ddoc Print and Preview
; copyright 1995-1998, Don Dickinson, All rights reserved.
; PureBasic version converted by Anthony Ball
IncludeFile "ddoc.pb"
#MainWindow=0
; Constants for the controls
Enumeration
#btnBasic
#btnFancy
#btnWrap
#btnGraphic
#btnBookmark
#btnLabels
#btnQuit
#optPreview
#optPrint
EndEnumeration
; Needed Color Constants (Vb compatible)
#vbBlack = $0
#vbRed = $ff
#vbGreen = $ff00
#vbYellow = $ffff
#vbBlue = $ff0000
#vbMagenta = $ff00ff
#vbCyan = $ffff00
#vbWhite = $ffffff
#vbGrey = $c0c0c0
#LIGHT_SHADE = $e0e0e0
Global gDDOCPath$ ; read from the win.ini file
; GetWinIni
Procedure.s GetWinIni(sSection$,sKey$,sDefault$)
sString$=Space(1000)
e=GetProfileString_(@sSection$,@sKey$,@sDefault$,@sString$,Len(sString$)-1)
ProcedureReturn Trim(sString$)
EndProcedure
Procedure Demo_Basic(endcode)
hFile=dpStartDoc(0,"Basic Document","",#DDOC_INCH,#DDOC_PAPER_LETTER,#DDOC_PORTRAIT,#DDOC_BIN_AUTO,#DDOC_ZOOMFIT)
If hFile<1
MessageRequester("Error",Str(hFile),#MB_ICONERROR)
Else
dpFont(hFile,#DDOC_FONTNORMAL,12,#vbBlack,"Times New Roman")
dpText(hFile,4.25,1.5,#DDOC_CENTER,"Hello World from ddoc Print and Preview")
dpEndDoc(hFile,endCode)
EndIf
EndProcedure
Procedure Demo_Fancy(endcode)
hFile=dpStartDoc(0,"Fancy Text Demo","",#DDOC_INCH,#DDOC_PAPER_LETTER,#DDOC_PORTRAIT,#DDOC_BIN_UPPER,#DDOC_ZOOMFIT)
If hFile<1
MessageRequester("Error",Str(hFile),#MB_ICONERROR)
Else
dpBookmark(hFile,"Color and Style")
dpFont(hFile,#DDOC_FONTNORMAL,10,#vbBlack,"Times New Roman")
dpText(hFile,0.5,1,#DDOC_LEFT,"Just")
dpFont(hFile,#DDOC_FONTNORMAL,14,#vbBlack,"Courier New")
dpText(hFile,0.5,1.2,#DDOC_LEFT,"about")
dpFont(hFile,#DDOC_FONTITALIC+#DDOC_FONTUNDERLINE+#DDOC_FONTBOLD,8,#vbBlack,"Courier New")
dpText(hFile,0.5,1.5,#DDOC_LEFT,"any combinataion")
dpFont(hFile,#DDOC_FONTBOLD,18,#vbBlack,"Arial")
dpText(hFile,0.5,1.7,#DDOC_LEFT,"of font")
dpFont(hFile,#DDOC_FONTITALIC,9,#vbBlack,"Time New Roman")
dpText(hFile,0.5,2.1,#DDOC_LEFT,"and style")
dpFont(hFile,#DDOC_FONTSTRIKEOUT,20,#vbBlack,"Arial")
dpText(hFile,0.5,2.3,#DDOC_LEFT,"is supported!")
dpLine(hFile,4.25,3.25,4.25,4.35,0,#vbBlack)
dpFont(hFile,#DDOC_FONTNORMAL,10,#vbBlack, "Times New Roman")
dpText(hFile,4.25,3.5,#DDOC_RIGHT,"Text can be right justified!")
dpText(hFile,4.25,3.75,#DDOC_CENTER,"Text can be centered!")
dpText(hFile,4.25,3.95,#DDOC_LEFT,"Text can be left justified!")
dpText(hFile,4.25,4.15,#DDOC_DECIMAL,"Finally, decimal aligned $9.99")
dpFont(hFile,#DDOC_FONTBOLD,24,#vbMagenta,"Arial")
dpText(hFile,4.25,7,#DDOC_CENTER,"Colors")
dpFont(hFile,#DDOC_FONTBOLD,24,#vbBlue,"Arial")
dpText(hFile,4.25,7.4,#DDOC_CENTER,"are")
dpFont(hFile,#DDOC_FONTBOLD,24,#vbGreen,"Arial")
dpText(hFile,4.25,7.8,#DDOC_CENTER,"not")
dpFont(hFile,#DDOC_FONTBOLD,24,#vbYellow,"Arial")
dpText(hFile,4.25,8.2,#DDOC_CENTER,"a")
dpFont(hFile,#DDOC_FONTBOLD,24,#vbRed,"Arial")
dpText(hFile,4.25,8.6,#DDOC_CENTER,"problem.")
dpNewPage(hFile,#DDOC_PAPER_LETTER,#DDOC_PORTRAIT,#DDOC_BIN_UPPER)
dpBookmark(hFile,"Angles")
dpFont(hFile,#DDOC_FONTNORMAL,18,#vbBlack,"Courier New")
dpAngleText(hFile,6,1,180,"Text can be printed upside down !!!")
dpFont(hFile,#DDOC_FONTBOLD,14,#vbMagenta,"Times New Roman")
For a=0 To 330 Step 30
dpAngleText(hFile,5,5,a,"This text is at "+Str(a)+" degrees")
Next
dpFont(hFile,#DDOC_FONTNORMAL,18,#vbBlack,"Arial")
dpAngleText(hFile,1,5,270,"Text can be printed")
dpAngleText(hFile,1,7.2,330,"at any angle")
dpEndDoc(hFile,endCode)
EndIf
EndProcedure
Procedure Demo_Wrap(endcode)
hFile=dpStartDoc(0,"Lines, Rectangles, and Bitmap Demo","",#DDOC_INCH,0,#DDOC_PORTRAIT,0,#DDOC_ZOOMFIT)
If hFile<1
MessageRequester("Error",Str(hFile),#MB_ICONERROR)
Else
lh.f=0.17
zText$="This is a test of a long string of text wrapped into "
zText$+"a rectangle. It will wrap text in the rectangle "
zText$+"until there is no more text to wrap or until "
zText$+"the rectangle has been filled. Besides the text "
zText$+"to print and the defining rectangle, you need "
zText$+"to tell the engine how much leading to use. "
zText$+"The leading (as I have defined it anyway :) "
zText$+"is the amount of space from the top of one line "
zText$+"of text to the top of the next line of text. "
zText$+"Breaking at paragraphs is very easy, just put "
zText$+"carriage returns (and optionally line feeds) "
zText$+Chr(13)+Chr(13)+"If you look at the code, "
zText$+"you will notice that I have inserted 2 carriage returns "
zText$+"before this sentence. ddoc respects the carriage return "
zText$+"and starts the text following it on the next line. "
zText$+"It treats a carriage return followed by a line feed ("
zText$+"ascii 13 followed by ascii 10) the same as a single "
zText$+"carriage return."
dpFont(hFile,#DDOC_FONTBOLD,9,#vbBlue,"Arial")
dpText(hFile,2,8,#DDOC_LEFT,"The text above is wrapped in a rectangle")
dpText(hFile,2,8.2,#DDOC_LEFT,"1 inch over and 1 inch down to 3 inches")
dpText(hFile,2,8.4,#DDOC_LEFT,"over and 3 inches down.")
dpFont(hFile,#DDOC_FONTNORMAL,10,#vbBlack,"Times New Roman")
iLen=Len(zText$)
While iLen>0
iPrinted=dpWrapText(hFile,1,1,3,3,lh,zText$)
If iPrinted=0 ; safety valve!
Break
EndIf
iLen-iPrinted
If iLen>0
dpNewPage(hFile,#DDOC_PAPER_LETTER,#DDOC_PORTRAIT,#DDOC_BIN_AUTO)
dpFont(hFile,#DDOC_FONTBOLD,9,#vbBlue,"Arial")
dpText(hFile,2,8,#DDOC_LEFT,"The text above is wrapped in a rectangle")
dpText(hFile,2,8.2,#DDOC_LEFT,"1 inch over and 1 inch down to 3 inches")
dpText(hFile,2,8.4,#DDOC_LEFT,"over and 3 inches down.")
dpFont(hFile,#DDOC_FONTNORMAL,10,#vbBlack,"Times New Roman")
zText$=Mid(zText$,iPrinted,Len(zText$))
EndIf
Wend
iLinesPrinted=dpWrapCount(hFile)
dpFont(hFile,#DDOC_FONTNORMAL,9,#vbRed,"Arial")
zText$="This line follows the wrapped text and shows how to use dpWrapCount"
dpText(hFile,1,iLinesPrinted*lh+1,#DDOC_LEFT,zText$)
dpEndDoc(hFile,endCode)
EndIf
EndProcedure
Procedure Demo_Graphic(endcode)
hFile=dpStartDoc(0,"Lines, Rectangles, and Bitmap Demo","",#DDOC_INCH,0,#DDOC_PORTRAIT,0,#DDOC_ZOOMFIT)
If hFile<1
MessageRequester("Error",Str(hFile),#MB_ICONERROR)
Else
If FileSize(gDDOCPath$+"ddoc.bmp")<1
MessageRequester("Error","Unable to find demo graphic file!",#MB_ICONERROR)
Else
lh.f=0.17
hBitmap=dpAddGraphic(hFile,gDDOCPath$+"ddoc.bmp")
If hBitmap
dpDrawGraphic(hFile,hBitmap,0.5,0.5,2,1)
EndIf
dpFont(hFile,#DDOC_FONTBOLD,18,#vbBlue,"Arial")
dpText(hFile,8.2,0.5,#DDOC_RIGHT,"INVOICE")
dpRect(hFile,0.4,2,3.6,3.25,0,#LIGHT_SHADE,#vbRed)
dpFont(hFile,#DDOC_FONTBOLD,9,0,"Arial")
dpText(hFile,0.5,2.1,#DDOC_LEFT,"Ship To:")
dpFont(hFile,#DDOC_FONTNORMAL,9,0,"Arial")
dpText(hFile,0.75,2.55,#DDOC_LEFT,"Don Dickinson")
dpText(hFile,0.75,2.75,#DDOC_LEFT,"5229 6th Street NE")
dpText(hFile,0.75,2.95,#DDOC_LEFT,"Columbia Hts, MN 55421")
dpRect(hFile,0.4,3.6,8.2,3.9,-1,#LIGHT_SHADE,0)
dpFont(hFile,#DDOC_FONTBOLD,9,0,"Arial")
dpText(hFile,0.75,3.7,#DDOC_RIGHT,"Qty")
dpText(hFile,0.85,3.7,#DDOC_LEFT,"Desc")
dpText(hFile,6,3.7,#DDOC_CENTER,"Price")
dpText(hFile,7.5,3.7,#DDOC_CENTER,"Total")
cy.f=4
dpFont(hFile,#DDOC_FONTNORMAL,9,0,"Arial")
dpText(hFile,0.75,cy,#DDOC_RIGHT,"5")
dpText(hFile,0.85,cy,#DDOC_LEFT,"Part #1")
dpText(hFile,6,cy,#DDOC_DECIMAL,"3.50")
dpText(hFile,7.5,cy,#DDOC_DECIMAL,"17.50")
cy+lh
dpText(hFile,0.75,cy,#DDOC_RIGHT,"1")
dpText(hFile,0.85,cy,#DDOC_LEFT, "Part #2")
dpText(hFile,6,cy,#DDOC_DECIMAL, "1.11")
dpText(hFile,7.5,cy,#DDOC_DECIMAL, "1.11")
dpRect(hFile,0.65,6.9,4.35,9.5,5,#LIGHT_SHADE,0)
dpFont(hFile,#DDOC_FONTNORMAL,10,0,"Times New Roman")
zText$="Note:"+Chr(13)+"This order comes with a 30 day, "
zText$+"money-back guarantee. If for any reason, you are un-satisfied "
zText$+"with the ddoc Print Preview system, you may return it to the "
zText$+"author for a full refund. "+Chr(13)+Chr(10)+Chr(13)
zText$+Chr(10)+"ddoc Print Preview is written entirely with Power "
zText$+"Basic's PB/DLL compiler. It is a real, machine code, win32 "
zText$+"application. Because it is written in native code, it is fast, "
zText$+"lean, and has no run-time requirements. Just distribute ddoc.exe "
zText$+"(< 70k) and either ddoc16.dll or ddoc32.dll (< 50k) with your "
zText$+"application."
iLeft=dpWrapText(hFile,0.75,7,4,9.5,lh,zText$)
dpLine(hFile,0.4,10.25,8.2,10.25,0.5,#vbBlue)
dpRect(hFile,0.4,10.25,2,10.55,0,#vbBlue,#vbBlue)
dpFont(hFile,#DDOC_FONTBOLD, 10,#vbWhite,"Arial")
dpText(hFile,0.5,10.3,#DDOC_LEFT,"ddoc Print Preview")
dpFont(hFile,#DDOC_FONTITALIC,9,0,"Arial")
dpText(hFile,7.7,10.4,#DDOC_RIGHT,"Page")
dpPageNo(hFile,7.8,10.4,#DDOC_LEFT,0)
dpText(hFile,7.95,10.4,#DDOC_LEFT,"of")
dpPageCount(hFile,8.2,10.4,#DDOC_RIGHT, 0)
EndIf
dpEndDoc(hFile,endCode)
EndIf
EndProcedure
Procedure Demo_Bookmark(endcode)
hFile=dpStartDoc(0,"Bookmark Demo","",#DDOC_INCH,#DDOC_PAPER_LETTER,#DDOC_PORTRAIT,#DDOC_BIN_AUTO,#DDOC_ZOOMFIT)
If hFile<1
MessageRequester("Error",Str(hFile),#MB_ICONERROR)
Else
dpBookmark(hFile,"Dickinson,Donald")
dpFont(hFile,#DDOC_FONTBOLD,18,#vbBlue,"Arial")
dpText(hFile,8.2,0.5,#DDOC_RIGHT,"Don Dickinson")
dpFont(hFile,#DDOC_FONTBOLD,9,#vbBlack, "Arial")
dpText(hFile,0.5,0.75,#DDOC_LEFT,"Address:")
dpFont(hFile,#DDOC_FONTNORMAL,9,#vbBlack, "Arial")
dpText(hFile,0.75,0.95,#DDOC_LEFT,"Don Dickinson")
dpText(hFile,0.75,1.15,#DDOC_LEFT,"5229 6th Street NE")
dpText(hFile,0.75,1.35,#DDOC_LEFT,"Columbia Hts, MN 55421")
dpText(hFile,0.75,1.55,#DDOC_LEFT,"Email - ddickinson@usinternet.com")
dpFont(hFile,#DDOC_FONTITALIC,9,#vbBlack,"Times New Roman")
dpPageNo(hFile,7.7,10.25,#DDOC_RIGHT,0)
dpText(hFile,7.8,10.25,#DDOC_LEFT,"of")
dpPageCount(hFile,8,10.25,#DDOC_LEFT,0)
dpNewPage(hFile,#DDOC_PAPER_LETTER,#DDOC_LANDSCAPE,#DDOC_BIN_AUTO)
dpBookmark(hFile,"Spike")
dpFont(hFile,#DDOC_FONTBOLD,18,#vbBlue,"Arial")
dpText(hFile,0.75,0.75,#DDOC_LEFT,"Spike")
dpFont(hFile,#DDOC_FONTBOLD,9,#vbBlack,"Arial")
dpText(hFile,0.75,1.25,#DDOC_LEFT,"Type: Dog")
dpFont(hFile,#DDOC_FONTNORMAL,9,#vbBlack,"Arial")
dpText(hFile,0.775,1.45,#DDOC_LEFT,"Note: Very Large, Eats everything")
dpBookmark(hFile,"KC")
dpFont(hFile,#DDOC_FONTBOLD,18,#vbBlue,"Arial")
dpText(hFile,6.25,0.75,#DDOC_LEFT,"KC")
dpFont(hFile,#DDOC_FONTBOLD,9,#vbBlack,"Arial")
dpText(hFile,6.25,1.25,#DDOC_LEFT,"Type: Dog")
dpFont(hFile,#DDOC_FONTNORMAL,9,#vbBlack,"Arial")
dpText(hFile,6.25,1.45,#DDOC_LEFT,"Note: Not quite as large, but equally hungry.")
dpFont(hFile,#DDOC_FONTBOLD,12,#vbBlue,"Arial")
dpText(hFile,5.5,7,#DDOC_CENTER,"You are free to mix landscape and portrait within a document!")
dpFont(hFile,#DDOC_FONTITALIC,9,#vbBlack,"Times New Roman")
dpPageNo(hFile,10.25,7.75,#DDOC_RIGHT,0)
dpText(hFile,10.3,7.75,#DDOC_LEFT,"of")
dpPageCount(hFile,10.5,7.75,#DDOC_LEFT,0)
dpNewPage(hFile,#DDOC_PAPER_LETTER,#DDOC_PORTRAIT,#DDOC_BIN_AUTO)
dpBookmark(hFile,"Dickinson, Tammy")
dpFont(hFile,#DDOC_FONTBOLD,18,#vbBlue,"Arial")
dpText(hFile,8.2,0.5,#DDOC_RIGHT,"Tammy Dickinson")
dpFont(hFile,#DDOC_FONTBOLD,9,#vbBlack,"Arial")
dpText(hFile,0.75,0.75,#DDOC_LEFT,"Type: Wife")
dpFont(hFile,#DDOC_FONTNORMAL,9,#vbBlack,"Arial")
dpText(hFile,0.75,0.95,#DDOC_LEFT,"Note: Not as hungry as dogs, but not yet fully house-broken.")
dpFont(hFile,#DDOC_FONTITALIC,9,#vbBlack,"Times New Roman")
dpPageNo(hFile,7.7,10.25,#DDOC_RIGHT,0)
dpText(hFile,7.8,10.25,#DDOC_LEFT,"of")
dpPageCount(hFile,8,10.25,#DDOC_LEFT,0)
dpEndDoc(hFile,endCode)
EndIf
EndProcedure
Procedure Demo_Labels(endcode)
If FileSize(gDDOCPath$+"include\ddocml.ini")<1
MessageRequester("Error","Unable to find demo graphic file!",#MB_ICONERROR)
ProcedureReturn
EndIf
iHandle=dpStartDoc(0,"Mailing Label Demo","",#DDOC_INCH,#DDOC_PAPER_LETTER,#DDOC_PORTRAIT,#DDOC_BIN_AUTO,#DDOC_ZOOMFIT)
If iHandle<1
MessageRequester("Error",Str(iHandle),#MB_ICONERROR)
Else
If dpMailInit(iHandle,gDDOCPath$+"include\ddocml.ini","Avery5260",#DDOC_CENTER)
MessageRequester("Error","Unable to initialise the mail engine!",#MB_ICONERROR)
Else
dpFont(iHandle,#DDOC_FONTITALIC,8,$FF,"Courier New")
dpBookmark(iHandle,"Left Aligned Template")
dpPrintTemplate(iHandle,#DDOC_LEFT)
dpNewPage(iHandle,#DDOC_PAPER_LETTER,#DDOC_PORTRAIT,#DDOC_BIN_AUTO)
dpFont(iHandle,#DDOC_FONTNORMAL,12,$FF0000,"Times New Roman")
dpBookmark(iHandle,"Centered Template")
dpPrintTemplate(iHandle,#DDOC_CENTER)
dpNewPage(iHandle,#DDOC_PAPER_LETTER,#DDOC_PORTRAIT,#DDOC_BIN_AUTO)
dpFont(iHandle,#DDOC_FONTNORMAL,9,0,"Times New Roman")
dpBookmark(iHandle,"Usage Example")
dpSetLabel(iHandle,1)
dpLabelText(iHandle,"Line 1")
dpLabelText(iHandle,"Line 21")
dpLabelText(iHandle,"Line 322")
dpLabelText(iHandle,"Line 4333")
dpNextLabel(iHandle)
dpLabelText(iHandle,"Line 1")
dpLabelText(iHandle,"Line 2")
dpLabelText(iHandle,"Line 3")
dpNextLabel(iHandle)
dpLabelText(iHandle,"Line 1")
dpLabelText(iHandle,"Line 2")
dpNextLabel(iHandle)
dpLabelText(iHandle,"Line 1")
dpNextLabel(iHandle)
x.f=dpLabelX(iHandle)
y.f=dpLabelY(iHandle)
dpText(iHandle,x,y,#DDOC_LEFT,"This is where the next label would be.")
EndIf
dpEndDoc(iHandle,endCode)
EndIf
EndProcedure
gPreview=#True
gDDOCPath$=GetWinIni("ddoc Samples","ddoc","c:\ddoc")
If Right(gDDOCPath$,1)<>"\"
gDDOCPath$+"\"
EndIf
OpenWindow(#MainWindow,100,200,250,200,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget,"DDOC Test")
CreateGadgetList(WindowID(#MainWindow))
ButtonGadget(#btnBasic,10,10,110,25,"The Basics")
ButtonGadget(#btnFancy,10,40,110,25,"Fancy Text")
ButtonGadget(#btnWrap,10,70,110,25,"Wrapped Text")
ButtonGadget(#btnGraphic,10,100,110,25,"Lines, Rects, Bmps")
ButtonGadget(#btnBookmark,10,130,110,25,"Bookmarks")
ButtonGadget(#btnLabels,10,160,110,25,"Mailing Labels")
OptionGadget(#optPreview,130,10,110,25,"Preview")
OptionGadget(#optPrint,130,40,110,25,"Print")
ButtonGadget(#btnQuit,130,160,110,25,"Quit")
SetGadgetState(#optPreview,#True)
If StartDDoc()
Repeat
EventID=WaitWindowEvent()
If gPreview
endCode=#DDOC_END_VIEW+#DDOC_END_DELETE
Else
endCode=#DDOC_END_PRINT+#DDOC_END_DELETE
EndIf
Select EventID
Case #PB_Event_Gadget
Select EventGadgetID()
Case #btnBasic
Demo_Basic(endcode)
Case #btnFancy
Demo_Fancy(endcode)
Case #btnWrap
Demo_Wrap(endcode)
Case #btnGraphic
Demo_Graphic(endcode)
Case #btnBookmark
Demo_Bookmark(endcode)
Case #btnLabels
Demo_Labels(endcode)
Case #optPreview
gPreview=#True
Case #optPrint
gPreview=#False
Case #btnQuit
Quit=#True
EndSelect
EndSelect
Until EventID=#PB_Event_CloseWindow Or Quit
Else
MessageRequester("Error","Unable to start dll",#MB_ICONERROR)
EndIf
End
The code was written for the registered one (it cost me $25 - thats £15!), but its well worth the money. It should be easy to fix it for the demo version of the dll.
see http://www.greatwebdivide.com for more info.