PurePDF Version 2.0

Developed or developing a new product in PureBasic? Tell the world about it.
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PurePDF Version 2.0

Post by yrreti »

Hi ABBKlaus

I've got a severe issue when using PB 5.10 b5, that causes a severe problem with your excellent PurePDF.
Your PurePDF works 'great' with PB version 5.0, and I really! really!! appreciate this program.
But when I installed PB 5.10 in parallel with 5.0 to test it, it always displays garbage when using PB 5.10.
After some experimentation, I discovered that with PB 5.10, it only works with Compiler Option
Create unicode executable checked. In doing this test, I also realized that I had just totally
messed up one of my special programs data base. Because using unicode messed up some of the
special characters I was using in the data base. I can not use unicode with out a major major rewrite
of not only that program, but several other programs that I wrote. My lack of understanding in some of this
stuff hurts me from time to time. But can you shed some light on this issue, and if there is something
that I can do, or that can be done about this issue? I can not use unicode. I just don't understand what they
did to version 5.10 that is causing this problem, and I'm desperately hoping that it's something simple that
you can see or fix with PurePDF to make it work like in version PB 5.0.
I attached some test code that runs great in PB 5.0 with or with out Create unicode executable checked.
But will only work with Create unicode executable checked when using PB 5.10.
Thank you sincerely! for your help.

Code: Select all

;#################################################################################################
;IMPORTANT NOTE when using PurePDF: 
;PB 5.0 has no problem, but with PB 5.10, you have to compile with create unicode executable, even
;if your not using unicode.   If you don't, the text is all garbled!
;#################################################################################################


Global swt$ = "Test PDF Creation with Page Break"
Global lsa=4  ;left side adjust
Global y = 5; initial Y position
Global tl=y;top y position

Procedure Header()
  pdf_Line(lsa+1,y,204,y):y=y+6
  pdf_SetFont("Lucida Console","",9);, #PB_Font_Default)
  pdf_Text(lsa+60,y, swt$):y=y+6 ; 0,y is the line position
 
  pdf_Line(lsa+1,y,204,y):y=y+1
  pdf_Line(lsa+1,y,204,y):y=y+4
EndProcedure

Procedure Footer()
  Protected txt.s
  pdf_SetY(-15)
  pdf_SetFont("Arial","I",8)
  pdf_SetTextColor(128)
  txt.s = "Page " + Str(pdf_GetPageNo())
  pdf_Cell(0,10,txt,0,0,#PDF_ALIGN_CENTER)
EndProcedure

Procedure PdfTestsheet()
  If pdf_Create()
    pdf_SetProcFooter(@Footer())
    pdf_SetProcHeader(@Header())
    pdf_AliasNbPages()
    pdf_AcceptPageBreak()
    
    pdf_SetFont("Lucida Console","",10);, #PB_Font_Default)
    
    For p=1 To 2
      y=5
     pdf_AddPage();this line is needed between sections
     pdf_SetY(10);this part really isn't needed here because I use yhe x and y value to poaition the text.
     ;But out side of a For Next loop like in this example, I need to set the x and y values to start at page top again
     ;or it will be at the bottom on the next page.  eg: y=5
     
      For x= 1 To 25
        pdf_Text(lsa+5,y, "Line "+Str(x)+"  Test line   Test line   Test line   Test line   Test line   Test line   Test line")
        y=y+4
      Next x
      pdf_Text(lsa+5,y, "Line "+Str(x)+"                        Need Footer entered and then Page Break Here"):y=y+4
     
      ;The data I need to put is line by line, varies in number of lines, and the line length can change.
      ;So I can't really use cells as in your nice examples.
     
      ;I need to create page breaks between sections.
     
      ;************************************************************************************
      ;Here I want to put the footer page number, and then go to and start on the next page.
      ;************************************************************************************
      pdf_Line(lsa+1,y,204,y):y=y+1
      pdf_Line(lsa+1,y,204,y)
      bl=y;bottom line
      ;Debug Str(bl)
      ;vertical lines tl = top line y
      pdf_Line(lsa+1,tl,lsa+1,bl)
      pdf_Line(lsa+200,tl,lsa+200,bl)
    Next p
   
   
    Define file$="Test PDF Creation With Page Break.pdf"
    pdf_Save(file$)
    RunProgram(file$)
  Else
    err=pdf_GetErrorCode()
    MessageRequester("PrintTestsheet()  error: ",Str(err),0)
  EndIf
EndProcedure

PdfTestsheet()
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PurePDF Version 2.0

Post by ABBKlaus »

Hi yrreti,

are you using the lib version or the includefile method ?
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PurePDF Version 2.0

Post by yrreti »

Hi ABBKlaus

Thanks for replying.
Sorry I couldn't answer back right away. I got a call after posting, and had to pick up my wife from a doctors appointment.
I have been always using your lib file. I did try using your include file when I was trying to fix this, but it had too many
'Native types can't be used with pointers' and 'Boolean comparison issues'. Again -> PB 5.10 issues.
It is a very impressive piece of code work, but a lot is still beyond my abilities. :oops:
Edit: Forgot to mention that I am also using your latest PurePDF223_PB50X86.zip file.
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PurePDF Version 2.0

Post by ABBKlaus »

Thats fine, the lib file is only for PB5.00 !
The current TailBite is not able to produce libs for 5.10 because of the change in Labels.
But the includefile works now.

Just use this simple lines to include PurePDF. Only Thing to Change is the path ;-)

Code: Select all

#PurePDF_Include=1
XIncludeFile "PurePDF.pb"
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PurePDF Version 2.0

Post by yrreti »

Hi ABBKlaus

Yay, it does work, after a little mod to PurePDF.pb.

Code: Select all

Procedure.l ipdf_ASCII85_Decode(*InputBuffer,InputLength,*OutputBuffer,*OutputLength)
  Protected tuple.q,c.l,count.l,err.l,*IPos.l,*OPos.l,i.l
just needed to be changed to:

Code: Select all

Procedure.l ipdf_ASCII85_Decode(*InputBuffer,InputLength,*OutputBuffer,*OutputLength)
  Protected tuple.q,c.l,count.l,err.l,*IPos,*OPos,i.l
because of the pointer issue.

Thanks

yrreti
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: PurePDF Version 2.0

Post by Guimauve »

Hello ABBKlaus,

A little feature request to allow Header and Footer user procedure to be optionally called with a pointer to structure as parameter. Only one parameter is enough.
This following code is what I wish you to add to your lib. I know I can edit your code (actually I did because I'm on Linux and your lib is for Windows I guess) but I think it can be useful for everyone.

Code: Select all

Global pHeaderParamPtr
Global pFooterParamPtr

Procedure ipdf_SetProcHeader(ProcAddress, StructAddress = #Null)
  pHeader = ProcAddress
  pHeaderParamPtr = StructAddress
EndProcedure

Procedure ipdf_SetProcFooter(ProcAddress, StructAddress = #Null)
  pFooter = ProcAddress
  pFooterParamPtr = StructAddress
EndProcedure


Procedure ipf_AddPage(Orientation$="",Format$="")
  Protected lsFamily.s,lsStyle.s,lbSize,lfLw.f,lsdc.s,lsfc.s,lstc.s,lbcf
  
  ;Start a new page
  If(pdfState=0)
    ipf_Create()
  EndIf
  
  lsFamily = pdfFontFamily$
  lsStyle = pdfFontStyle$
  If pdfUnderline = #True
    lsStyle = lsStyle + "U"
  EndIf  
  lbSize = pdfFontSizePt
  lflw = pdfLineWidth
  lsdc = pdfDrawColor$
  lsfc = pdfFillColor$
  lstc = pdfTextColor$
  lbcf = pdfColorFlag
  
  If(pdfPage>0)
    ;Page footer
    pdfInFooter = #True
       
    If pFooter
      If pFooterParamPtr <> #Null
        pdf_CallFunction(pFooter, pFooterParamPtr)
      Else
        pdf_CallFunction(pFooter)
      EndIf
      
    EndIf
    
    pdfInFooter = #False
    ;Close page
    ipf_EndPage()
  EndIf
  ;Start new page
  If ipf_BeginPage(Orientation$,Format$) = #False
    ProcedureReturn #False
  EndIf
  ;Set line cap style To square
  ipf_Out("2 J")
  ;Set line width
  pdfLineWidth = lflw
  ipf_Out(ipf_StrF(lflw * pdfK,2) + " w")
  ;Set font
  If(Trim(lsFamily) <> "")
    ipf_SetFont(lsFamily, lsStyle, lbSize)
  EndIf  
  ;Set colors
  pdfDrawColor$ = lsdc 
  If (lsdc <> "0 G")
    ipf_Out(lsdc)
  EndIf  
  pdfFillColor$ = lsfc
  If (lsfc <> "0 g")
    ipf_Out(lsfc)
  EndIf  
  pdfTextColor$ = lstc
  pdfColorFlag = lbcf
  
  ; Page header
  If pHeader
    
    If pHeaderParamPtr <> #Null
      pdf_CallFunction(pHeader, pHeaderParamPtr)
    Else
      pdf_CallFunction(pHeader)
    EndIf
    
  EndIf
  
  ;Restore line width
  If(pdfLineWidth<>lflw)
    pdfLineWidth = lflw
    ipf_Out(ipf_StrF(lflw*pdfK,2) + " w")
  EndIf
  ; Restore font
  If(lsFamily <> "")
    ipf_SetFont(lsFamily,lsStyle,lbSize)
  EndIf
  ;Restore colors
  If(pdfDrawColor$ <> lsdc)
    pdfDrawColor$=lsdc
    ipf_Out(lsdc)
  EndIf
  If(pdfFillColor$ <> lsfc)
    pdfFillColor$ = lsfc
    ipf_Out(lsfc)
  EndIf
  pdfTextColor$ = lstc
  pdfColorFlag = lbcf  
  If pdfNumbering=#True
    pdfNumPageNum = pdfNumPageNum + 1
  EndIf
  
  ProcedureReturn #True
EndProcedure

Procedure ipf_Close() ;Terminates the PDF document.
  
  ;Terminate document
  If(pdfState=3)
    ;Do nothing
  Else
    If(pdfPage=0)
      ipf_AddPage("")
    EndIf  
    ;Page footer
    pdfInFooter=#True 
    
    If pFooter
      If pFooterParamPtr <> #Null
        pdf_CallFunction(pFooter, pFooterParamPtr)
      Else
        pdf_CallFunction(pFooter)
      EndIf
      
    EndIf
    
    pdfInFooter=#False
    ;Close page
    ipf_EndPage();
    ;Close document
    ipf_EndDoc()
  EndIf
  
EndProcedure


Procedure pdf_SetProcHeader(ProcAddress, StructAddress = #Null) ;Set header procedure.
  ipdf_SetProcHeader(ProcAddress, StructAddress)
EndProcedure

Procedure pdf_SetProcFooter(ProcAddress, StructAddress = #Null) ;Set footer procedure.
  ipdf_SetProcFooter(ProcAddress, StructAddress)
EndProcedure

ProcedureDLL pdf_SetProcHeader(ProcAddress, StructAddress = #Null) ;Set header procedure.
  ipdf_SetProcHeader(ProcAddress, StructAddress)
EndProcedure

ProcedureDLL pdf_SetProcFooter(ProcAddress, StructAddress = #Null) ;Set footer procedure.
  ipdf_SetProcFooter(ProcAddress, StructAddress)
EndProcedure
Best regards
Guimauve
Dear Optimist, Pessimist,
and Realist,

While you guys were
busy arguing about the
glass of water, I DRANK IT !

Sincerely,
the Opportunist
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PurePDF Version 2.0

Post by ABBKlaus »

Hi all,

uploaded a new Version!

Code: Select all

- added optional parameter "StructureAdress" to pdf_SetProcFooter() and pdf_SetProcHeader() (Thanks to Guimauve)
- added pdf_SetLineCap() and pdf_SetLineJoin() (Thanks to Po)
http://www.purebasicpower.de/?PurePDF
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: PurePDF Version 2.0

Post by Thorsten1867 »

ABBKlaus wrote:Thats fine, the lib file is only for PB5.00 !
The current TailBite is not able to produce libs for 5.10 because of the change in Labels.
But the includefile works now.
With TailBite V1.4.9 it's now possible to generate a lib. I've tested a lot of the tutorial examples with PB 5.10.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PurePDF Version 2.0

Post by ABBKlaus »

Thorsten1867 wrote:With TailBite V1.4.9 it's now possible to generate a lib. I've tested a lot of the tutorial examples with PB 5.10.
Right, just uploaded it.

http://www.purebasicpower.de/?PurePDF
Version 2.24:
- added pdf_SetDrawColorCMYK() pdf_SetFillColorCMYK() pdf_SetTextColorCMYK() (Thanks to Erlend Rovik)
- added optional parameter "StructureAdress" to pdf_SetProcFooter() and pdf_SetProcHeader() (Thanks to Guimauve)
- added pdf_SetLineCap() and pdf_SetLineJoin() (Thanks to Po)
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PurePDF Version 2.0

Post by yrreti »

Thanks very much ABBKlaus.
I really appreciate your maintaining this excellent library and Include code.
It's been very useful for me.

yrreti
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: PurePDF Version 2.0

Post by captain_skank »

Hi,

I get the follwing error when trying to run the examples :

Line 5329:invalid name: same as an external command

( in purepdf.pb )

Any idea what i'm doing wrong ?

Cheers
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PurePDF Version 2.0

Post by yrreti »

Hi captain_skank

Probably the same thing that happened to me when I first started to use PurePDF, which is a GREAT addition
to PureBasic ! :D :D :D
If you installed the lib, and you want to run the examples, you need to comment out these two lines
in each example.

Code: Select all

#PurePDF_Include=1
XIncludeFile "PurePDF.pb"
That is because that code was written to include the PurePDF code in that directory, which was compiled in the lib.
That's why you get the invalid name:same as external command error.
If you want to just use the code, then you need to remove the installed lib part. Both the file in Residents and in
PureLibraries.
Both work very well in my programs.

yrreti
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: PurePDF Version 2.0

Post by captain_skank »

ding ding ding - we have a winner :)

Thanks for that - for the life of me I couldn't figure it out.

Thanks
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PurePDF Version 2.0

Post by IdeasVacuum »

The following produces an A4 pdf file with a blank page

Code: Select all

pdf_Create("P","mm",#PDF_PAGE_FORMAT_A4)
pdf_AddPage()
pdf_Save("C:\Test.pdf")
I have also tested this issue with a pdf created using PagePlus.

If I check the file properties in Adobe Reader, the page size is recorded as 8.27 x 11.69 inches
which is 210 x 297mm, which is A4. So far, so good......

If I set the View Scale in Reader to 'Actual Size' I should see the page measuring 210 x 297mm,
which is 794 x 1123 pixels (essentially, if I hold a sheet of A4 paper up to the screen, the on-screen sheet should be very close in size). However, the Adobe page actually measures 910 x 1287 pix, or 241 x 340.5mm.

So, it would appear to be the case that 'Actual Size' is not actually! Does anyone know of a work-around? Does anyone know why 'Actual Size' isn't the actual size? I am using Adobe Reader XI (11.0.02), the latest and greatest......

Edit: Aha, found it in Reader's preferences. By default, the actual screen DPI is ignored!! :shock:
The Adobe default is 110 DPI (I wonder why?) whereas my screen has the very common 96DPI.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PurePDF Version 2.0

Post by yrreti »

Hi ABBKlaus
I was doing some memory leak testing on a large program that I wrote that uses your excellent purepdf.pb program.
I used NoLeak 1.3.pb by Luis with infratec's mod added.
http://www.purebasic.fr/english/viewtop ... 8&start=15
After fixing several leaks in my program, (Fonts not freed properly), I discovered two AllocateMemory memory leaks in your program.

The first one was simple to fix:

Code: Select all

            nChars=GetTextFace_(hDC,0,0)
            If nChars>0
              *TextFace=AllocateMemory(nChars*SizeOf(Character))
              If *TextFace
                If GetTextFace_(hDC,nChars,*TextFace)
                  FontName$=PeekS(*TextFace,nChars)
                EndIf
                FreeMemory(*TextFace); <--------<<<<  This line fixed the memory leak here, and the program works fine.
              EndIf
            EndIf
The second one I can't seem to fix? It concerns freeing *cidtogidmap=AllocateMemory(cidtogidmapSize)
Could you please take a quick look at it. Is there a way to free it somehow when your program
is finished doing it's work, and just about to return to my main program ? Everything I tried crashes it.
Sincerely Thanks for any help or ideas.

Code: Select all

Procedure.l ipdf_TTF_Create_cidtogidmap(Array glyph_list.TTF_CharacterMap(1))
  Protected *cidtogidmap.TTF_Segment,cidtogidmapSize=256*256*2,nsize=ArraySize(glyph_list()),i
  ;-* cidtogidmax
  If nsize
    *cidtogidmap=AllocateMemory(cidtogidmapSize)
    If *cidtogidmap
      For i=0 To nsize
        ForEach glyph_list(i)\char_no()
          If glyph_list(i)\char_no()>=0 And glyph_list(i)\char_no()<$FFFF
            ;Debug "i="+Str(i)+" / Char="+Str(glyph_list(i)\char_no())
            *cidtogidmap\segment[glyph_list(i)\char_no()]=ipdf_EndianW(i)&$FFFF
          EndIf
        Next
      Next
      CompilerIf #PB_Compiler_Debugger
;       If CreateFile(1,"cidtogidmap.txt")
;         WriteData(1,*cidtogidmap,cidtogidmapSize)
;         CloseFile(1)
;       EndIf
;       CallDebugger
      CompilerEndIf
    EndIf
  EndIf
  ProcedureReturn *cidtogidmap
EndProcedure
Post Reply