problem with pdf report file generation

public boolean PDFProcess()
    {
        List 			    PDFFiles;
        ListEnumerator      PDFEnumerator;
        boolean             errors;
        filename            _from,_to,_temp, _name, _ext;
        container           _split;
        Bindata             _bin;
        DocuRef             docuref;
        custTable           custTable;
        DocuActionArchive   DocuActionArchive;
        System.IO.MemoryStream stream;
        System.IO.StreamWriter write;
        PDFFiles = VE005FilesTools::GetlistOfFiles(VEParameters.VE005Path2Read,VEParameters.VE005FileNameDocumentFilter);
        PDFEnumerator = PDFFiles.getEnumerator();
        while(PDFEnumerator.moveNext())
        {
            _from = PDFEnumerator.current();
            custTable = this.DecodePDF(_from);

            if (custTable)
            
            {
            
             docuref.clear();
                docuRef.RefRecId = custTable.recid;
                docuRef.RefTableId = custTable.TableId;
                docuRef.DocumentId = newGuid();
                docuref.RefCompanyId = curext();
                docuref.ActualCompanyId = curext();
                docuref.TypeId = VEParameters.VE005DocuTypeId;
                docuRef.insert();

                DocuActionArchive = docuAction::newDocuRef(docuref);
                DocuActionArchive.add(docuref,_from);
            
            
                _split = fileNameSplit(_from);
                _name = conPeek(_split,2);
                _ext = conPeek(_split,3);
                stream = new System.IO.MemoryStream();
                writer = new System.IO.StreamWriter(stream);
                writer.Write(_name);
                writer.Flush();
                docuref = DocumentManagement::attachFileToCommon(CustTable, VEParameters.VE005DocuTypeId, stream, _name+_ext, 'PDF', _name+_ext);
               
               
                if (this.move(_from,VEParameters.VE005Path2Backup))
                {
                    errors = true;
                }
            }
            else
            {
                if (this.move(_from,VEParameters.VE005Path2Errors))
                {
                    errors = true;
                }
            }
        }
        return errors;
    }
 i have batch process that generate pdf. But when i create it, i find it corrupted. Any suggestions for this code? thanks in advance

Parents
  • If I understand your code correctly, you iterate some files and attach them to records.

    Are the input files all right or corrupted? If corrupted, the code above is irrelevant and you should debug the code generating those files. If they're not corrupted, the problem isn't in the batch generating those files, but in how you're attaching them.

    Oh, I think I see a bug. Let's throw away all the clutter and focus on the important part:

    System.IO.MemoryStream stream = new System.IO.MemoryStream();
    System.IO.StreamWriter writer = new System.IO.StreamWriter(stream);
    writer.Write(_name);

    Ask yourself - what data do you write to the stream? It seems that it just a string containing the file name, but that's wrong! You should write the file content, i.e. the actual PDF data.

    By the way, if you have a file on disk that you can read, you can create a stream pointing to the file (FileStream fs = File.OpenRead(filepath)) - you don't need to copy all the content to a MemoryStream.

Reply Children
No Data
Related
Recommended