hi
Create a custom API page for the Attachment table. In the API page, you should include the fields you need to retrieve the PDF attachment, such as Attachment ID, Attachment Name, and Attachment Data.
In the API page, add a codeunit that retrieves the Attachment Data field for the PDF attachment. You can use the "Attachment Management" codeunit to do this.
Modify the "OnGetRecord" trigger in the API page to call the codeunit that retrieves the Attachment Data field. For example, you can add the following code to the "OnGetRecord" trigger:
Trigger OnGetRecord()
Var
AttachmentMgt: Codeunit "Attachment Management";
Begin
AttachmentMgt.GetAttachmentStream(Attachment.ID, Attachment."File Name", PDFStream);
End;
In the above code, "AttachmentMgt" is the codeunit variable that references the "Attachment Management" codeunit. "PDFStream" is a variable that holds the stream of the PDF attachment.
Return the PDF attachment as the response of the API call. You can use the "SendStream" function to do this. For example, you can add the following code to the "OnAfterGetRecord" trigger:
Trigger OnAfterGetRecord()
Begin
Response.ContentDisposition := 'attachment;filename="' + Attachment."File Name" + '"';
Response.ContentType := 'application/pdf';
Response.SendStream(PDFStream);
End;
In the above code, "Response" is the response variable that is returned by the API page. "ContentDisposition" and "ContentType" are the HTTP headers that specify the file name and content type of the PDF attachment. "SendStream" sends the PDF stream as the response of the API call.
DAniele