|
Hi all,
I hope that someone can solve my problem. Now, I writing the MFC window application.
My application have some data in the textbox. I want to save that textbox's data to somewhere by text file. I don't know how to output the text file.
If someone know, pls help me.
Regards,
tun
|
|
|
|
|
First of all a big thaks to NeWi
You piece of code helped me a lot.
The memory leak in pdf.cpp
at line 223:
char* buffer = new char [filelen]; (is never deleted)
bad pointer handling at line 270:
buffer+= streamend + 7;
this means that even if buffer is deleted there will
still be some memory left.
My solution:
char* bufferRoot = new char [filelen]; (is never deleted)
char* buffer = bufferRoot;
and then at the end of the if scoope in which the buffer
was created:
delete[] bufferRoot;
Thanks again NeWi
Best regards
Asger-P
|
|
|
|
|
The following is a simple change to fit the need to extract text in Chinese.
Note that this version is still not a complete version. please refer to the PDF specification to make the version complete.
=======================================================================
// PDFTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
//This file contains extremely crude C source code to extract plain text
//from a PDF file. It is only intended to show some of the basics involved
//in the process and by no means good enough for commercial use.
//But it can be easily modified to suit your purpose. Code is by no means
//warranted to be bug free or suitable for any purpose.
//
//Adobe has a web site that converts PDF files to text for free,
//so why would you need something like this? Several reasons:
//
//1) This code is entirely free including for commericcial use. It only
// requires ZLIB (from www.zlib.org) which is entirely free as well.
//
//2) This code tries to put tabs into appropriate places in the text,
// which means that if your PDF file contains mostly one large table,
// you can easily take the output of this program and directly read it
// into Excel! Otherwise if you select and copy the text and paste it into
// Excel there is no way to extract the various columns again.
//
//This code assumes that the PDF file has text objects compressed
//using FlateDecode (which seems to be standard).
//
//This code is free. Use it for any purpose.
//The author assumes no liability whatsoever for the use of this code.
//Use it at your own risk!
//PDF file strings (based on PDFReference15_v5.pdf from www.adobve.com:
//
//BT = Beginning of a text object, ET = end of a text object
//5 Ts = superscript
//-5 Ts = subscript
//Td move to start next line
//No precompiled headers, but uncomment if need be:
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
//YOur project must also include zdll.lib (ZLIB) as a dependency.
//ZLIB can be freely downloaded from the internet, www.zlib.org
//Use 4 byte struct alignment in your project!
#include "zlib.h"
//Find a string in a buffer:
size_t FindStringInBuffer (char* buffer, char* search, size_t buffersize)
{
char* buffer0 = buffer;
size_t len = strlen(search);
bool fnd = false;
while (!fnd)
{
fnd = true;
for (size_t i=0; i<len; i++)
{
if (buffer[i]!=search[i])
{
fnd = false;
break;
}
}
if (fnd) return buffer - buffer0;
buffer = buffer + 1;
if (buffer - buffer0 + len >= buffersize) return -1;
}
return -1;
}
//Keep this many previous recent characters for back reference:
#define oldchar 15
//Convert a recent set of characters into a number if there is one.
//Otherwise return -1:
float ExtractNumber(const char* search, int lastcharoffset)
{
int i = lastcharoffset;
while (i>0 && search[i]==' ') i--;
while (i>0 && (isdigit(search[i]) || search[i]=='.')) i--;
// Added by XJ Yang:
if(search[i] == '-')
i--;
// Ended of Added by Xj Yang.
float flt=-1.0;
char buffer[oldchar+5]; ZeroMemory(buffer,sizeof(buffer));
strncpy(buffer, search+i+1, lastcharoffset-i);
if (buffer[0] && sscanf(buffer, "%f", &flt))
{
return flt;
}
return -1.0;
}
//Check if a certain 2 character token just came along (e.g. BT):
bool seen2(const char* search, char* recent)
{
if ( recent[oldchar-3]==search[0]
&& recent[oldchar-2]==search[1]
&& (recent[oldchar-1]==' ' || recent[oldchar-1]==0x0d || recent[oldchar-1]==0x0a)
&& (recent[oldchar-4]==' ' || recent[oldchar-4]==0x0d || recent[oldchar-4]==0x0a)
)
{
return true;
}
return false;
}
unsigned char TwoChars2Hex(unsigned char c1, unsigned char c2)
{
// 该函数将一个形如 'F', '3' 的两个字符, 看作一个16进制的两位, 转变为一个形如0xF3的字符:
unsigned char c;
if( isdigit(c1))
c = (c1 - '0');
else if( c1 >= 'a' && c1 <='z')
c = (c1 - 'a');
else if( c1 >= 'A' && c1 <='Z')
c = (c1 - 'A') + 10;
else
c = 0;
if( isdigit(c2))
c = c * 16 + (c2 - '0');
else if( c2 >= 'a' && c2 <='z')
c = c * 16 + (c2 - 'a');
else if( c2 >= 'A' && c2 <='Z')
c = c * 16 + (c2 - 'A') + 10;
else
c = c * 16;
return c;
}
//This method processes an uncompressed Adobe (text) object and extracts text.
void ProcessOutput(FILE* file, char* output, size_t len)
{
//Are we currently inside a text object?
bool intextobject = false;
//Is the next character literal (e.g. \\ to get a \ character or \( to get ( ):
bool nextliteral = false;
//() Round bracket nesting level. Text appears inside ()
int rbdepth = 0;
// Added by XJ Yang:
//<> Point bracket nesting level. Text appears inside <>
int pbdepth = 0;
// Ended of added by XJ Yang.
//Keep previous chars to get extract numbers etc.:
char oc[oldchar];
int j=0;
for (j=0; j<oldchar; j++) oc[j]=' ';
for (size_t i=0; i<len; i++)
{
// Changed by XJ Yang:
// char c = output[i];
unsigned char c = output[i];
// End of changed by XJ Yang.
if (intextobject)
{
if (rbdepth==0 && seen2("TD", oc))
{
//Positioning.
//See if a new line has to start or just a tab:
float num = ExtractNumber(oc,oldchar-5);
// Changed by XJ Yang:
/*
if (num>1.0)
{
fputc(0x0d, file);
fputc(0x0a, file);
}
if (num<1.0)
{
// Changed by XJ Yang:
// fputc('\t', file);
// End of changed by XJ Yang.
}
*/
// Ended of changed by Xj Yang.
if (num > 1.0)
{
fputc(0x0d, file);
fputc(0x0a, file);
}
}
// Added by XJ yang:
if (pbdepth==0 && seen2("Tw", oc))
{
float num = ExtractNumber(oc,oldchar-5);
if (num < 1.0 && num > 0)
{
fputc(0x0d, file);
fputc(0x0a, file);
}
}
// End of added by XJ Yang.
if (rbdepth==0 && seen2("ET", oc))
{
//End of a text object, also go to a new line.
intextobject = false;
fputc(0x0d, file);
fputc(0x0a, file);
}
else if (c=='(' && rbdepth==0 && !nextliteral)
{
//Start outputting text!
rbdepth=1;
//See if a space or tab (>1000) is called for by looking
//at the number in front of (
int num = (int) ExtractNumber(oc,oldchar-1);
if (num>0)
{
if (num>1000.0)
{
fputc('\t', file);
}
else if (num>100.0)
{
fputc(' ', file);
}
}
}
else if (c==')' && rbdepth==1 && !nextliteral)
{
//Stop outputting text
rbdepth=0;
}
else if (rbdepth==1)
{
//Just a normal text character:
if (c=='\\' && !nextliteral)
{
//Only print out next character no matter what. Do not interpret.
nextliteral = true;
}
else
{
nextliteral = false;
if ( ((c>=' ') && (c<='~')) || ((c>=128) && (c<255)) )
{
fputc(c, file);
}
}
}
// Added by XJ Yang:
else if (c=='<' && pbdepth==0 && !nextliteral)
{
//Start outputting text!
pbdepth=1;
//See if a space or tab (>1000) is called for by looking
//at the number in front of (
int num = (int) ExtractNumber(oc,oldchar-1);
if (num>0)
{
if (num>1000.0)
{
fputc('\t', file);
}
else if (num>100.0)
{
fputc(' ', file);
}
}
}
else if (c=='>' && pbdepth==1 && !nextliteral)
{
//Stop outputting text
pbdepth=0;
}
else if (pbdepth==1)
{
//Just a normal text character:
if (c=='\\' && !nextliteral)
{
//Only print out next character no matter what. Do not interpret.
nextliteral = true;
}
else
{
nextliteral = false;
if ( ((c>=' ') && (c<='~')) || ((c>=128) && (c<255)) ) // 是汉字:
{
unsigned char c2 = output[++i];
unsigned char combinedChar = TwoChars2Hex(c, c2);
fputc(combinedChar, file);
}
}
}
// End of added by Xj Yang.
}
//Store the recent characters for when we have to go back for a number:
for (j=0; j<oldchar-1; j++) oc[j]=oc[j+1];
oc[oldchar-1]=c;
if (!intextobject)
{
if (seen2("BT", oc))
{
//Start of a text object:
intextobject = true;
}
}
}
}
int main(int argc, char * argv[])
{
//Discard existing output:
FILE* fileo = fopen("output.txt", "w");
if (fileo) fclose(fileo);
fileo = fopen("output.txt", "a");
//Open the PDF source file:
FILE* filei = fopen("Some.pdf", "rb");
if (filei && fileo)
{
//Get the file length:
int fseekres = fseek(filei,0, SEEK_END); //fseek==0 if ok
long filelen = ftell(filei);
fseekres = fseek(filei,0, SEEK_SET);
//Read ethe ntire file into memory (!):
char* buffer = new char [filelen]; ZeroMemory(buffer, filelen);
size_t actualread = fread(buffer, filelen, 1 ,filei); //must return 1
bool morestreams = true;
//Now search the buffer repeated for streams of data:
while (morestreams)
{
//Search for stream, endstream. We ought to first check the filter
//of the object to make sure it if FlateDecode, but skip that for now!
size_t streamstart = FindStringInBuffer (buffer, "stream", filelen);
size_t streamend = FindStringInBuffer (buffer, "endstream", filelen);
if (streamstart>0 && streamend>streamstart)
{
//Skip to beginning and end of the data stream:
streamstart += 6;
if (buffer[streamstart]==0x0d && buffer[streamstart+1]==0x0a) streamstart+=2;
else if (buffer[streamstart]==0x0a) streamstart++;
if (buffer[streamend-2]==0x0d && buffer[streamend-1]==0x0a) streamend-=2;
else if (buffer[streamend-1]==0x0a) streamend--;
//Assume output will fit into 10 times input buffer:
size_t outsize = (streamend - streamstart)*10;
char* output = new char [outsize]; ZeroMemory(output, outsize);
//Now use zlib to inflate:
z_stream zstrm; ZeroMemory(&zstrm, sizeof(zstrm));
zstrm.avail_in = streamend - streamstart + 1;
zstrm.avail_out = outsize;
zstrm.next_in = (Bytef*)(buffer + streamstart);
zstrm.next_out = (Bytef*)output;
int rsti = inflateInit(&zstrm);
if (rsti == Z_OK)
{
int rst2 = inflate (&zstrm, Z_FINISH);
if (rst2 >= 0)
{
//Ok, got something, extract the text:
size_t totout = zstrm.total_out;
ProcessOutput(fileo, output, totout);
}
}
delete[] output; output=0;
buffer+= streamend + 7;
filelen = filelen - (streamend+7);
}
else
{
morestreams = false;
}
}
fclose(filei);
}
if (fileo) fclose(fileo);
return 0;
}
xjyang
|
|
|
|
|
Can we open this project by using VS2003. What are the steps?
I just need a .NET component to convert PDF to TXT.
shammie.lk
|
|
|
|
|
Hi.... i used ur application, it was so great... superb.... but for some pdf files i didnt got any output, bcoz it is generating a empty file.... i dont know where is the problem? i feel it is in the compression format, but in my file it is default compression only.... can u give me any suggution
DreamUth
|
|
|
|
|
Thank NeWi for this article. It is very useful and save me a lot of time.
However, some of the PDF files I am trying to convert come up as garbage. Interesting enough, I do find some readable characters like this among the jibbish after the pdf is decompressed by the zlib module, so that means the decompression should be at least partially correct.
"URW Software, Copyright 1997 by URW. See the file COPYING (GNU General Public License) for license conditions. As a special exception, permission is granted to include this font program in a Postscript or PDF file that consists of a document that contains text to be displayed or printed using this font, regardless of the conditions or license applying to the document itself.Standard Symbols LCopyright URW Software, Copyright 1997 by URW "
NeWi mentioned that the newer PDF files may be encrypted and an updated version will be developed. Did anybody get the updated version? Would you mind post it here or email it to me? Many thanks!
I examined those failed PDFs, the trailer is something like this
trailer
<< /Size 39 /Root 1 0 R /Info 2 0 R
/ID [(†¾•®ïT*Yý8J´<æ)(†¾•®ïT*Yý8J´<æ)]
>>
startxref
42616
%%EOF
which doesn't specify it is encrypted...Does it mean that it doesn't fall into the catergory NeWi was mentioning?
|
|
|
|
|
Please, da error "unresolved external symbol _inflate y _inflateInit_" y no se como solucionarlo. Thanks.
Sergio
|
|
|
|
|
Solucionado, incluí la zdll.lib en la lista de librerias a utilizar por el compilardor.
|
|
|
|
|
your code works well when source PDF is writen in "pure English",but it does not support chinese/japanese/korean.
how can i fix it ?
i love coding,i love dreaming!
|
|
|
|
|
A big thanks from me too!I am on a project and I cannot even imagine what I would do without your help!
However i have the same problem as zenofchina.
What can I do so that other languages will be supported?
|
|
|
|
|
What does the number represent?
|
|
|
|
|
Can I have a full working project for reference? I got problems trying to include your souce code into my project. Thks in advance!
|
|
|
|
|
Thanks!
I have a pretty limited understanding of C, so much of what I do is in VB/VBA. As such I have had to take what you have done and "translate"... then modify the algorithm for performance.
I would not have had a clue where to even start without this... Your example is greatly appreciated!
Cheers Mate!
|
|
|
|
|
Will you share your code in VB?
Thanks
Reed
|
|
|
|
|
Please share!!
|
|
|
|
|
|
Hi I am compiling the code using VC++ but I get this error. Why?
Syntax error indentifier _TChar
Thanks in advance
EJ
|
|
|
|
|
Try adding the stdafx.h header file to your project.
|
|
|
|
|
First of all, this code is great .
But for my Project i don't want to create a textfile, but i want to get the text as string to put this in my database.
Can anybody tell me how can i do this?
Thanks
Theo Mprotsis
|
|
|
|
|
Will you be uploading the release version? I working with a project that might benefit.
Thanks!
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
Hi
I just wanted to find out if one can get a visual basic equivalent for the c code to extract the text, any ideas?
|
|
|
|
|
yes, I have not been able to find ANY examples in VB which perform the same task.
|
|
|
|
|
Hardly what I would call robust or efficient... but it works...
You need to reference the microsoft scripting runtime and the zlib.dll (I don't recall where I found that).
Option Explicit
Private Const oldchar = 15
Private Type StreamLimit
PtrStart As Long
PtrEnd As Long
End Type
'Declares
Private Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hwnd As Long, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function compress Lib "zlib.dll" (dest As Any, destLen As Any, src As Any, ByVal srcLen As Long) As Long
Private Declare Function uncompress Lib "zlib.dll" (dest As Any, destLen As Any, src As Any, ByVal srcLen As Long) As Long
Public Function FastExtractText(FileName As String)
Dim result As String
Dim InBuffer() As Byte
Dim BufferLength As Long
Dim Stream() As Byte
Dim Ptr As Long
Dim PDFData As String
Dim Limits As StreamLimit
Dim ThisString As String
'//Open the PDF source file:
InBuffer = OpenFileToBytes(FileName)
BufferLength = UBound(InBuffer)
'//Now search the buffer repeated for streams of data:
Ptr = 0
Limits = FastNextCleanStream(InBuffer, Ptr)
While ((Limits.PtrEnd > 0) And (Limits.PtrEnd < BufferLength))
'//Now use zlib to inflate:
PDFData = FastInflate(FileName, Limits)
ThisString = ProcessPDFData(PDFData)
result = result + ThisString
Limits = FastNextCleanStream(InBuffer, Limits.PtrEnd + 9)
DoEvents
Wend
FastExtractText = result
End Function
Private Function OpenFileToBytes(FileName As String, Optional Start As Long = 0, Optional Length As Long = 0) As Byte()
Dim FS As New Scripting.FileSystemObject
Dim InFile() As Byte
Dim FN As Long
If FS.FileExists(FileName) Then
ReDim InFile(FileLen(FileName))
FN = FreeFile
Open FileName For Binary As FN
If Start <= 0 Then
Get FN, , InFile
ElseIf Length <= 0 Then
Get FN, Start, InFile
Else
ReDim InFile(Length)
Get FN, Start, InFile
End If
OpenFileToBytes = InFile
Close FN
End If
End Function
Private Function ProcessPDFData(PDFData As String) As String
'Are we currently inside a text object?
Dim intextobject As Boolean
intextobject = False
'Is the next character literal (e.g. \\ to get a \ character or \( to get ( ):
Dim nextliteral As Boolean
nextliteral = False
'() Bracket nesting level. Text appears inside ()
Dim rbdepth As Integer
rbdepth = 0
'Keep previous chars to get extract numbers etc.:
Dim oc(oldchar) As Byte
Dim Ptr As Long
Dim c As String
Dim num As Double
Dim Length As Long
Length = Len(PDFData)
Dim NxtBT As Long
Dim NxtET As Long
Dim NxtOB As Long
Dim NxtCB As Long
Dim result As String
NxtET = 1
Dim done As Boolean
done = False
Do While Not done
NxtBT = GetNextSpaced("BT", NxtET, PDFData)
If NxtBT <= 0 Then
'Nup - nothing left
Exit Do
End If
NxtET = GetNextSpaced("ET", NxtBT, PDFData)
NxtOB = FindNextNoEscape("(", NxtBT, PDFData)
Do While (NxtOB < NxtET)
NxtCB = FindNextNoEscape(")", NxtOB, PDFData)
If NxtCB < NxtET Then
If NxtCB >= 0 Then
If result <> "" Then
result = result + "" + Mid(PDFData, NxtOB + 1, NxtCB - NxtOB - 1)
Else
result = Mid(PDFData, NxtOB + 1, NxtCB - NxtOB - 1)
End If
NxtOB = FindNextNoEscape("(", NxtCB, PDFData)
Else
NxtOB = NxtET
End If
Else
Do Until NxtET > NxtCB
NxtET = GetNextSpaced("ET", NxtET, PDFData)
If NxtET <= 0 Then
'Data error...
Exit Do
End If
Loop
End If
Loop
Loop
ProcessPDFData = ReplaceSpecialCharacters(result)
End Function
Private Function FastNextCleanStream(sBuffer() As Byte, ByRef After As Long) As StreamLimit
Dim Limits As StreamLimit
Dim sDelimit As String
Dim eDelimiter As String
sDelimit = "stream"
Limits = FastGrabStreamLimits(sBuffer, After, sDelimit, "endstream")
After = After + Limits.PtrEnd + Len("endstream")
Limits = FastCleanStream(sBuffer, Limits)
FastNextCleanStream = Limits
End Function
Private Function GetNextSpaced(Chars As String, After As Long, InData As String) As Long
Dim DataLen As Long
Dim result As Long
Dim found As Boolean
Dim CheckChar As String
DataLen = Len(InData)
found = False
result = After + 1
Do While Not found And result > 0
result = InStr(result, InData, Chars, vbTextCompare)
If result <= 0 Then
Exit Do
End If
CheckChar = Mid(InData, result - 1, 1)
If CheckChar = " " Or CheckChar = Chr(10) Or CheckChar = Chr(13) Then
If (result + Len(Chars) + 2) <= DataLen Then
CheckChar = Mid(InData, result + Len(Chars), 1)
If CheckChar = " " Or CheckChar = Chr(10) Or CheckChar = Chr(13) Then
found = True
Exit Do
Else
result = result + Len(Chars)
End If
Else
Exit Do
End If
Else
result = result + Len(Chars)
End If
Loop
If found Then
GetNextSpaced = result
Else
GetNextSpaced = -1
End If
End Function
Private Function FindNextNoEscape(Char As String, After As Long, InData As String) As Long
Dim DataLen As Long
Dim result As Long
Dim found As Boolean
Dim CheckChar As String
found = False
result = After
Do While Not found And result > 0
result = InStr(result, InData, Char, vbBinaryCompare)
If result > After Then
CheckChar = Mid(InData, result - 1, 1)
If Not (CheckChar = "\") Then
found = True
Else
result = result + 1
End If
Else
found = True
End If
Loop
If found Then
FindNextNoEscape = result
Else
FindNextNoEscape = -1
End If
End Function
Private Function ReplaceSpecialCharacters(InString As String) As String
Dim result As String
result = InString
result = Replace(result, "\\", "'")
result = Replace(result, "\322", Chr(34)) ' "
result = Replace(result, "\323", Chr(34)) ' "
result = Replace(result, "\252", " TM")
result = Replace(result, "\320", "-")
result = Replace(result, "\311", "...")
result = Replace(result, "'", "\")
result = Replace(result, "\325", "'")
result = Replace(result, "\", "")
'Result = Replace(Result, "\)", ")")
ReplaceSpecialCharacters = result
End Function
Private Function FastGrabStreamLimits(Buffer() As Byte, After As Long, StartDelimiter As String, EndDelimiter As String) As StreamLimit
Dim result As StreamLimit
result.PtrStart = FindSpacedBytesLocation(After, Buffer, StartDelimiter)
'Result.PtrStart = GetNextSpaced(StartDelimiter, After, Buffer)
If result.PtrStart > 0 Then
result.PtrStart = result.PtrStart + Len(StartDelimiter)
result.PtrEnd = FindSpacedBytesLocation(result.PtrStart, Buffer, EndDelimiter)
Else
result.PtrStart = UBound(Buffer)
End If
FastGrabStreamLimits = result
End Function
Private Function FindSpacedBytesLocation(Start As Long, Buffer() As Byte, Search As String) As Long
Dim result As Long
Dim LastResult As Long
Dim done As Boolean
result = 0
Do Until done
LastResult = result
result = FindBytesLocation(Start, Buffer, Search)
done = True
If result = LastResult Then
result = 0
done = True
End If
If result <= 0 Then
done = True
End If
Loop
FindSpacedBytesLocation = result
End Function
Private Function FindBytesLocation(Start As Long, Buffer() As Byte, Search As String) As Long
Dim result As Long
Dim Ptr As Long
Dim Max As Long
Dim Srch As Byte
Dim SrchLen As Long
Dim found As Boolean
Max = UBound(Buffer)
Srch = Asc(Mid(Search, 1, 1))
SrchLen = Len(Search)
found = False
For result = Start To Max
If Buffer(result) = Srch Then
found = True
For Ptr = 1 To SrchLen - 1
If Not Buffer(result + Ptr) = Asc(Mid(Search, Ptr + 1, 1)) Then
found = False
Exit For
End If
Next Ptr
If found Then
Exit For
Else
found = False
result = result + Ptr
End If
End If
Next result
If found Then
FindBytesLocation = result
Else
FindBytesLocation = -1
End If
End Function
Private Function FastInflate(FileName As String, ZLData As StreamLimit) As String
Dim zstrm As New ZLIBTOOLLib.ZlibTool
Dim tmpZipped As String
Dim tmpUnZipped As String
Dim ZippedData() As Byte
tmpZipped = "C:\temp\tmpin": tmpUnZipped = "C:\temp\tmpout"
ZippedData = OpenFileToBytes(FileName, ZLData.PtrStart + 1, ZLData.PtrEnd - ZLData.PtrStart - 1)
DumpStreamToDisk ZippedData, tmpZipped
zstrm.InputFile = tmpZipped: zstrm.OutputFile = tmpUnZipped
zstrm.Decompress
FastInflate = OpenFileToText(tmpUnZipped)
Kill tmpZipped: Kill tmpUnZipped
End Function
Private Function FastCleanStream(Buffer As Variant, Limits As StreamLimit) As StreamLimit
Dim BufferLen As Long
Dim i As Long
Dim done As Boolean
BufferLen = Len(Buffer)
With Limits
done = False
i = 0
Do Until done
i = i + 1
If BufferLen < .PtrStart + i Then
done = True
Else
If Not _
(Buffer(.PtrStart + i) = 10 Or _
Buffer(.PtrStart + i) = 13 Or _
Buffer(.PtrStart + i) = 32) Then
done = True
End If
End If
Loop
.PtrStart = .PtrStart + i
done = False
i = 0
Do Until done
i = i + 1
If .PtrEnd - i <= 0 Then
done = True
Else
If Not _
(Buffer(.PtrEnd - i) = 10 Or _
Buffer(.PtrEnd - i) = 13 Or _
Buffer(.PtrEnd - i) = 32) Then
done = True
End If
End If
Loop
.PtrEnd = .PtrEnd - i
End With
FastCleanStream = Limits
End Function
Private Sub DumpStreamToDisk(Stream As Variant, FileName As String)
Dim OutFileNum As Long
Dim Data() As Byte
On Error Resume Next
Kill FileName
On Error GoTo 0
OutFileNum = FreeFile
Open FileName For Binary As OutFileNum
Data = Stream
Put OutFileNum, , Data
Close OutFileNum
End Sub
Private Function OpenFileToText(FileName As String) As String
Dim FS As New Scripting.FileSystemObject
Dim InFile As TextStream
If FS.FileExists(FileName) Then
Set InFile = FS.OpenTextFile(FileName)
If Not InFile.AtEndOfStream Then
OpenFileToText = InFile.ReadAll
End If
End If
End Function
Cheers Mate!
|
|
|
|
|
I've asked NeWi if he has code available, but I have not yet received a response.
Does anyone else know how to decrypt a text stream?
PS. I'm developing NeWi's code to parse the text metrics; whch will give a more accurate return vis-a-vis end-of-line characters.
Midders
|
|
|
|
|
Hello,
I am wondering if you have made any progress or learned any new information regarding decrypting text streams?
Thanks,
Daniel
|
|
|
|
|