Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help Needed to Improve Code
Message
From
11/03/2013 05:15:34
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Title:
Help Needed to Improve Code
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01567959
Message ID:
01567959
Views:
61
I have Post Script files. I am trying to write a code that could merge two or More Pages of the file so that there is least paper wastage.
I the help of few experts namely Tore, and others I have written a little code and its working fine also.

The code is Replicated Below
Clear
lcStr = filetostr('1021337392.ps')
lnPOS = At("%%Pages:",lcStr)
lcPageCount = alltrim(substr(lcStr, lnPOS, 12))
lnPageCount = VAL(STRTRAN(lcPageCount,'%%Pages:',''))

IF lnPageCount>2
DIMENSION occoupiedrange(lnPageCount)
DIMENSION unoccoupiedrange(lnPageCount)
Local lcFile, lcText
m.lcFile = [1021337392.ps]
Create Cursor Dummy (PS c(254), pos i,pageno n(2),recordnum i)
Append From (m.lcFile) Sdf

Scan
IF Getwordnum(PS, Getwordcount(PS)) = [x] .OR. ;
Getwordnum(PS, Getwordcount(PS)) = [y] .OR. ;
Getwordnum(PS, Getwordcount(PS)) = [w]
m.lcText = Getwordnum(PS, Getwordcount(PS) - 1) && The second last word
IF Len(Chrtran(m.lcText, [1234567890], [])) = 0 && lcText contains only digits
Replace pos With Val(m.lcText)
Endif
ENDIF
ENDSCAN

FOR I= 1 TO lnPageCount
PGNO=I
NEXTPGNO=PGNO+1
PGNO=ALLTRIM(STR(PGNO))
NEXTPGNO=ALLTRIM(STR(NEXTPGNO))
CURTEXT='%%Page: '+PGNO+' '+PGNO
NeXTTEXT='%%Page: '+NEXTPGNO+" "+NEXTPGNO
LOCATE FOR ALLTRIM(PS)=curtext
IF FOUND()
SCAN WHILE ALLTRIM(ps)<>nexttext OR EOF()=.T.
REPLACE pageno WITH I
ENDSCAN
ENDIF
ENDF

FOR I=1 TO lnPageCount
SELECT MIN(Pos) FROM Dummy WHERE Pageno=I AND Pos>30 INTO ARRAY X
SELECT MAX(Pos) FROM Dummy WHERE Pageno=I INTO ARRAY Y
STORE Y-X+1 TO Occoupiedrange(I)
STORE (x-30) TO unoccoupiedrange(I)
ENDFOR

FOR I=2 TO (lnPageCount-1)
IF unoccoupiedrange(I)> occoupiedrange(I+1)
NeXTTEXT='%%Page: '+ALLTRIM(STR(I+1))+" "+ALLTRIM(STR(I+1))
LOCATE FOR ps=NeXTTEXT
Skip-1
Replace ps WITH NeXTTEXT && U1 Removed by Page No
SKIP
Replace ps WITH '0 -72 6 mul translate'  && Insert Post Script Page Break command
i=i+1
ENDIF
ENDFOR
ENDIF
I don't want to disturb Page Number-1.

For Page Number 2 and above, If the Blank space (Unoccoupied Space) is Greater than the Occoupied space of The next page, the entire Next Page will be Shifted on the Previous Page. For This 'U1' Shall be Removed and Page Break command Shall be inserted.

MY PROBLEMS

(1) With the above code, I am able to merge the next page if the Previous page has ample blank space, however if the Previous page has even more space that could accomodate the even next to next page, this I am not able to Do.

(2) The code is taking sufficient time for processing, Can it be made Much faster as I will be Having more than 50000 PS files.

(3) The Cursor Being Created will have to be again translated. I Tried this with the following Code, but the file being created , although opens but becomes big in size and formatting is not like as It was before.

I am Using the following code for This.
SELECT Dummy
set textmerge to Myfile.ps on noshow
scan
for ix = 1 to fcount()
 \<< EVALUATE(alltrim(field(m.ix))) >>
endfor
endscan
set textmerge to
set textmerge off
Kinldy Help on My above problems.

Sample PS can be Downloaded from

https://www.dropbox.com/s/6x5an3dyg8syvmx/1021337392.ps
Regards
Harsh
Harsh
Reply
Map
View

Click here to load this message in the networking platform