Hello, we have an application that uses your TAdvPDFViewer component to view PDF files in the form and then print them using this code:
_Impresora := _Impre;
For k := 0 To Printer.Printers.Count - 1 Do
Begin
If SameText(Printer.Printers[k], _Impresora) Then
Begin
Printer.PrinterIndex := k;
Break;
End;
End; PDFVisor.Clear;
PDFVisor.Invalidate;
LabelBase64 := Package.LabelImages[j];
SaveBase64ToPDF(LabelBase64, OutputPDFFile);
PDFVisor.FileName := OutputPDFFile;
PDFVisor.Print(OutputPDFFile);
Application.ProcessMessages;
PDFVisor.Clear;
PDFVisor.Invalidate;
The problem lies in the fact that we have a loop that generates PDF files, which are loaded into the component and then sent to the printer. The first one works correctly, but when the next cycle of the loop runs the code again, we get the following error: Project EtiModule.exe raised exception class $C0000005 with message 'c0000005 ACCESS_VIOLATION'.
It seems that this error is because the component's print function uses the Windows system, specifically the NITRO PDF virtual printer that we have installed. In fact, it opens that programme and prints the first label/PDF, but until we close that programme, it does not continue with the next cycle, and that is when the error occurs. We have searched for information and have been told that the correct way to print the PDF would be to use AdvPDFPrinter, but it is not available, even though we have the TMS ALL ACCESS package with the latest version of components installed. Could you please advise us on how to proceed so that we can print the different PDFs without the error occurring?
Thank you for everything.
We do not have a component named TAdvPDFPrinter. Not sure where you found this information.
What is PDFVisor here? Is this an instance of the TAdvPDFViewer class?
Maybe you need to decouple the printing from the PDF viewing.
You can independently from the TAdvPDFViewer send it to the printer via:
uses
Winapi.Windows, Winapi.ShellAPI;
procedure PrintPDF(const FileName: string);
begin
ShellExecute(0, 'print', PChar(FileName), nil, nil, SW_HIDE);
end;
// Example:
PrintPDF('C:\Docs\myfile.pdf');
Hello Bruno, good afternoon, thank you for your instructions. Perhaps I misread something about TadvPdfPrinter.
Our question is whether your TAdvPDFViewer component allows the PDF file loaded in that viewer to be printed, and whether PDFVisor is the name of this component that we have placed in the form.
What we want to do is for the viewer, apart from displaying the PDF file, to send the document to the printer we specify, but as we have already indicated, if we call the Print method of your component several times, the error mentioned above occurs.
The code you suggest is not valid, as we need to be able to specify the printer to which the print job should be sent.
I look forward to hearing from you.
Thank you for everything.
To allow printer selection you could from TAdvPDFViewer together with a TPrinterSetupDialog use something like:
begin
if printersetupdialog1.Execute then
begin
AdvPDFViewer1.Print(filename);
end;
end;
Hello, Bruno, I think you have misunderstood me.
With your TadvPDFViewer component and the PRINT method, we can now print using the code we used before:
For k := 0 To Printer.Printers.Count - 1 Do
Begin
If SameText(Printer.Printers[k], _Printer) Then
Begin
Printer.PrinterIndex := k;
Break;
End;
End;
With this code, we configure the printer used for printing using TadvPDFViewer.Print(PDFFileName); the problem is that if we call this method more than once, that's when the error occurs.
Well, I don't know if this is perhaps because your component uses the Windows printing method.
Thank you.
What do you do different from
var
sl: TStringList;
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
for i := 0 to sl.Count - 1 do
begin
AdvPDFViewer1.FileName := sl.Strings[i];
AdvPDFViewer1.Print(sl.Strings[i]);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if printersetupdialog1.Execute then
begin
caption := Printer.Printers[Printer.PrinterIndex];
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
sl := TStringList.Create;
sl.Add('E:\TMS\TMS VCL UI Pack\Doc\TMS VCL UI Pack Quick Start.pdf');
sl.Add('E:\TMS\TMS VCL UI Pack\Doc\TMS TWebUpdate Developers Guide.pdf');
end;
?