PurePDF 2.14 strange behavior with compression

Just starting out? Need help? Post your questions and find answers here.
schic
User
User
Posts: 34
Joined: Fri Sep 12, 2003 10:17 am

PurePDF 2.14 strange behavior with compression

Post by schic »

used some code from the totorials to show the problem (PB4.30 PurePDF214):

Code: Select all

Global title.s
Global Col.f
Global y0.f
title="20000 Leagues Under the Seas"

#ZLIB_VERSION = "1.2.3"
#ZLIB_VERNUM  = $1230
XIncludeFile "Source\PurePDF_res.pb"
XIncludeFile "Source\PurePDF.pb"

Structure z_stream
  *next_in.l
  avail_in.l
  total_in.l
  *next_out.l
  avail_out.l
  total_out.l
  *msg.l
  *state.l
  zalloc.l
  zfree.l
  opaque.l
  data_type.l
  adler.l
  reserved.l
EndStructure

ImportC "ZLIB.lib"
  _compress.l(*dest,*destlen,*source,sourcelen) As "_compress"
EndImport

Procedure.b Compress(*aData.MEM_DataStructure)
  Protected zerr.b
  Protected CompMem.l
  Protected sourcelen.l
  Protected SourceMem.l
  Protected CompLen.l
  Protected lbError.b
  
  lbError = #False
  sourcelen = *aData\lCurSize
  SourceMem = *aData\pData 
  CompLen.l = (Int(sourcelen/8000)+1)*8000 + 16 
  CompMem=AllocateMemory(CompLen)
  If CompMem
    zerr=_compress.l(CompMem,@CompLen,SourceMem,sourcelen)
    If zerr = 0
      *aData\pData = CompMem
      *aData\lMaxSize = CompLen
      *aData\lCurSize = CompLen
      FreeMemory(SourceMem)
      lbError = #True 
    EndIf
  EndIf
  ProcedureReturn lbError  
EndProcedure

Procedure Header()
  pdf_SetFont3("Arial","B",15)
  w = pdf_GetStringWidth(title)+6
  pdf_SetX((210 - w)/2)
  pdf_SetDrawColor3(0,80,180)
  pdf_SetFillColor3(230,230,0)
  pdf_SetTextColor3(220,50,50)
  pdf_SetLineWidth(1)
  pdf_Cell7(w,9,title,1,1,#PDF_ALIGN_CENTER,1)
  pdf_Ln2(10)
  y0 = pdf_GetY()
EndProcedure

Procedure footer()
  pdf_SetY(-15)
  pdf_SetFont3("Arial","I",8)
  pdf_SetTextColor(128)
  txt.s = "Page " + Str(pdf_GetPageNo())
  pdf_Cell6(0,10,txt,0,0,#PDF_ALIGN_CENTER)
EndProcedure

Procedure AcceptPageBreak()
  ProcedureReturn #True;
EndProcedure

pdf_Init()
pdf_Create()
pdf_SetProcFooter(@footer())
pdf_SetProcHeader(@Header())
pdf_SetProcCompression(@Compress())
pdf_SetProcAcceptPageBreak(@AcceptPageBreak())
pdf_SetFont3("Arial","", 8)
pdf_AddPage()

myshorttext$ = "123456789 123456789 123456789 123456789 123456789 123456789 123456789 "
mylongtext$  = myshorttext$ + #PDF_NEWLINE + myshorttext$ + #PDF_NEWLINE + myshorttext$

Level = 0
For i = 1 To 14000
  pdf_Cell7(10 , 5, Str(i), 0, 0, #PDF_ALIGN_LEFT, 0 )
  pdf_SetX(20) 
  pdf_Cell7(150, 5, myshorttext$, 0, 1, #PDF_ALIGN_LEFT, 0)
  pdf_SetX(25)
  pdf_MultiCell6(150, 3, mylongtext$ , 0, #PDF_ALIGN_LEFT , 0, 0, 0)
Next

pdf_Save("CompressionTest.pdf")
MessageRequester("OK", "Done " + Str(i), #MB_OK|#MB_ICONINFORMATION)
compiling this code, i get an error (file is corrupt) with Acrobat when opening the created PDF-file. The pdf seems to be ok if opened with with a texteditor. Without compression Acrobat opens the file with no error. Reducing the loop to 1000 and using compression, the file is opened with no error.

And the very strange thing: if I use title="Textlist" (line 5) and not title="20000 Leagues Under the Seas", the comressed pdf-file is also opened without error.

Same with PB4.20

Hope ABBKlaus you can help and find a solution
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

works here without any error :?
Here´s the resulting pdf file that loads fine in acrobat reader 9.1 : http://www.purebasicpower.de/downloads/ ... onTest.pdf

Tested on Vista X64 (X64+X86 mode) / Windows XP SP3 (X86 mode) / IPod Touch (2G) [display the pdf only / there is no PureBasic for IPod :wink: ]

using PurePDF v2.14 : http://www.purebasicpower.de/downloads/ ... B43X86.zip
; Generated by WIN-SFV32 v1.0
; (Compatible: Total Commander 7.04a)
PurePDF.pb 1E2A32A5
PurePDF_res.pb EC662128
schic
User
User
Posts: 34
Joined: Fri Sep 12, 2003 10:17 am

Post by schic »

I used Acrobat 5.0. OK - not the newest version :oops:
With Acrobat-Reader 9 it is working well, although a
strange behavior with this pdf-files.

Thanks for the advice and your work on this great library.
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

schic wrote:I used Acrobat 5.0. OK - not the newest version :oops:
With Acrobat-Reader 9 it is working well, although a
strange behavior with this pdf-files.
Ah that really explains it :wink: PurePDF supports Acrobat Version 6.x and above.
Image
schic
User
User
Posts: 34
Joined: Fri Sep 12, 2003 10:17 am

Post by schic »

it seems not only to be the old version I am using, but the installation wich is corrupt. Meanwhile I tried it at work with Acrobat 5.0 and everything works well.

Again, thank you for aiming me to the right direction. I would have looking to the code for an error forever, cause i never had problems with PDFs.
Post Reply