I populate a TImageEnMIO with several images, like this:
procedure TfrmProcessaImg.ProcessarArquivos;
var
TotalDeArquivos, ArqSelecionado, sequencia, sequencia2, i: Integer;
CaminhoDaPasta, NomeDoArquivo, CaminhoCompleto : string;
temQr : Boolean;
idx: Integer;
begin
imgMPdf.Enabled := False;
if ShellListView1.Selected = nil then
ShellListView1.Selected := ShellListView1.Items[0];
//
TotalDeArquivos := (ShellListView1.Items.Count - 1);
ArqSelecionado := ShellListView1.ItemIndex;
CaminhoDaPasta := ShellTreeView1.Path;
NomeDoArquivo := ShellListView1.Folders[ArqSelecionado].DisplayName;
CaminhoCompleto := (CaminhoDaPasta + '\' + NomeDoArquivo);
sequencia := ShellListView1.Selected.Index;
while sequencia <= TotalDeArquivos-1 do begin
Application.ProcessMessages; // <--- ADICIONE ISTO AQUI
//
image.IO.LoadFromFile(CaminhoCompleto);
LerBarCode;
if StrToInt(CaixaSalvar) = StrToInt(edNCaixa.Text) then begin
if IdTpClassQrCode <> '' then begin
//checa se existe o dossie no banco
DMsql.cdsConsDossie.Close;
DMsql.cdsConsDossie.Params[0].AsInteger := StrToInt(IdTpDocQrCode);
DMsql.cdsConsDossie.Params[1].AsInteger := (DMsql.cdsConsCaixaDossieID_CAIXA.AsInteger);
DMsql.cdsConsDossie.Params[2].AsString := (IndRaizQrCode);
DMsql.cdsConsDossie.Params[3].AsString := cbArquivoAtual.Text;
DMsql.cdsConsDossie.Open;
//
DMsql.cdsHerancaDossie.Close;
DMsql.cdsHerancaDossie.Params[0].AsInteger := DMsql.cdsConsDossieID_DOSSIE.AsInteger;
DMsql.cdsHerancaDossie.Open;
//
if (DMsql.cdsConsDossie.IsEmpty) then begin
if imgMPdf.ImageCount <> 0 then begin
NomePastaPDF := DMsql.cdsHerancaDossieTIP_COD_CLA_TP_DOC.AsString + '_' + DMsql.cdsHerancaDossieTIP_NOME_DOCUMENTO.AsString;
NomeArquivoPDF := '';
NomeArquivoPDF := NomeArquivoPDF + IndRaizQrCodeSalva;
//
if not DirectoryExists(IncludeTrailingPathDelimiter(TFrmConfig.DirSaidaLotes) + cbArquivoAtual.Text + '\' + NomePastaPDF + '\' + edNCaixa.Text) then
ForceDirectories(IncludeTrailingPathDelimiter(TFrmConfig.DirSaidaLotes) + cbArquivoAtual.Text + '\' + NomePastaPDF + '\' + edNCaixa.Text); //
DiretorioDestino := IncludeTrailingPathDelimiter(TFrmConfig.DirSaidaLotes) + cbArquivoAtual.Text + '\' + NomePastaPDF + '\' + edNCaixa.Text;
//
SalvarPDF(IncludeTrailingPathDelimiter(TFrmConfig.DirSaidaLotes) + cbArquivoAtual.Text + '\' + NomePastaPDF + '\' + edNCaixa.Text + '\' + NomeArquivoPDF + '.pdf' );
end;
ShowMessage('Documento inexistente.');
Abort
end
else begin
if imgMPdf.ImageCount <> 0 then begin
NomePastaPDF := DMsql.cdsHerancaDossieTIP_COD_CLA_TP_DOC.AsString + '_' + DMsql.cdsHerancaDossieTIP_NOME_DOCUMENTO.AsString;
NomeArquivoPDF := '';
NomeArquivoPDF := NomeArquivoPDF + IndRaizQrCodeSalva;
//
if not DirectoryExists(IncludeTrailingPathDelimiter(TFrmConfig.DirSaidaLotes) + cbArquivoAtual.Text + '\' + NomePastaPDF + '\' + edNCaixa.Text) then
ForceDirectories(IncludeTrailingPathDelimiter(TFrmConfig.DirSaidaLotes) + cbArquivoAtual.Text + '\' + NomePastaPDF + '\' + edNCaixa.Text);
DiretorioDestino := IncludeTrailingPathDelimiter(TFrmConfig.DirSaidaLotes) + cbArquivoAtual.Text + '\' + NomePastaPDF + '\' + edNCaixa.Text;
//
SalvarPDF(IncludeTrailingPathDelimiter(TFrmConfig.DirSaidaLotes) + cbArquivoAtual.Text + '\' + NomePastaPDF + '\' + edNCaixa.Text + '\' + NomeArquivoPDF + '.pdf' );
end;
// ==========================================================
// INÍCIO DA CORREÇÃO: SINCRONIZAÇÃO MÍNIMA
// ==========================================================
if cbMantemQrCode.Checked = False then begin
TThread.Queue(nil,
procedure
begin
// ESTE CÓDIGO RODA AGORA NA THREAD PRINCIPAL (UI)
if Assigned(imgMPdf) then // Adiciona segurança
begin
imgMPdf.Clear;
imgMPdf.MIO.LoadFromFiles(CaminhoCompleto, true, true);
end;
end
);
end
else
imgMPdf.Clear;
// ==========================================================
// FIM DA CORREÇÃO
// ==========================================================
IndRaizQrCodeSalva := IndRaizQrCode;
CaixaSalvar := NumCaixaQrCode;
IdDossieQrCodeSalva := IdDossieQrCode;
//
sequencia := sequencia + 1;
ShellListView1.ItemIndex := sequencia;
CaminhoDaPasta := ShellTreeView1.Path;
NomeDoArquivo := ShellListView1.Folders[sequencia].DisplayName;
CaminhoCompleto := (CaminhoDaPasta + '\' + NomeDoArquivo);
end;
end
else begin
imgMPdf.MIO.LoadFromFiles(CaminhoCompleto, true, true);
//
sequencia := sequencia + 1;
ShellListView1.Selected := ShellListView1.Items[sequencia];
CaminhoDaPasta := ShellTreeView1.Path;
NomeDoArquivo := ShellListView1.Folders[sequencia].DisplayName;
CaminhoCompleto := (CaminhoDaPasta + '\' + NomeDoArquivo);
if sequencia = TotalDeArquivos then begin
imgMPdf.MIO.LoadFromFiles(CaminhoCompleto, true, true);
NomePastaPDF := DMsql.cdsHerancaDossieTIP_COD_CLA_TP_DOC.AsString + '_' + DMsql.cdsHerancaDossieTIP_NOME_DOCUMENTO.AsString;
NomeArquivoPDF := '';
NomeArquivoPDF := NomeArquivoPDF + IndRaizQrCodeSalva;
//
if not DirectoryExists(IncludeTrailingPathDelimiter(TFrmConfig.DirSaidaLotes) + cbArquivoAtual.Text + '\' + NomePastaPDF + '\' + edNCaixa.Text) then
ForceDirectories(IncludeTrailingPathDelimiter(TFrmConfig.DirSaidaLotes) + cbArquivoAtual.Text + '\' + NomePastaPDF + '\' + edNCaixa.Text);
DiretorioDestino := IncludeTrailingPathDelimiter(TFrmConfig.DirSaidaLotes) + cbArquivoAtual.Text + '\' + NomePastaPDF + '\' + edNCaixa.Text;
//
SalvarPDF(IncludeTrailingPathDelimiter(TFrmConfig.DirSaidaLotes) + cbArquivoAtual.Text + '\' + NomePastaPDF + '\' + edNCaixa.Text + '\' + NomeArquivoPDF + '.pdf' );
end;
end;
end
else begin
ShowMessage('favor selecionar a caixa correta.');
Break
end;
end;
imgMPdf.Enabled := True;
end;
and then save a PDF, like this:
for i := 0 to imgMPdf.MIO.ParamsCount - 1 do begin
imgMPdf.MIO.Params[i].PDF_PaperSize := iepAuto;
imgMPdf.MIO.Params[i].PDF_Compression := ioPDF_JPEG; // or ioPDF_G4FAX for monochrome images
end;
IEGlobalSettings().PDFEngine := ieenLegacy;
imgMPdf.MIO.SaveToFilePDF(ExtractFilePath(ParamStr(0)) + 'EditandoPDF\' + NomeArquivoPDF + '.pdf');
CaminhoPDFTemporario := (ExtractFilePath(ParamStr(0)) + 'EditandoPDF\' + NomeArquivoPDF + '.pdf');
IEGlobalSettings().PDFEngine := ieenAuto;
However, I notice that after page (49) my PDF starts repeating the same page until the end (69). This happens when I'm populating the TImageEnMIO; I notice that from page 49 onwards, the thumbnail starts to become blank... Can you help me? How can I improve this routine to ensure that ALL the images I load into my TImageEnMIO are generated in the final PDF?