A question by Mr. Jean-Pierre Loquet attracted my attention. He asks about Printing remote PDF. The problem is like this: There is a PDF template (of course the template must have appropriate format or you won´t be able to use it in the following scenario) on an external non-SAP server/ webpage. The programmer wants to use this template the same way he would use a form template saved in the SAP system (transaction SFP, integrated LCD in your SAP GUI etc.).
I feel it could be difficult to figure out what are all the important parts of the puzzle and how to glue it up together, so I blog about it. It could also help people whose scenarios are slightly different but they could use a part of the process I am going to describe.
So, let me describe me idea about how to implement the scenario
The basic idea/ where to start from
- The idea is based on the demo report provided by SAP, it is called FP_PDF_TEST_19. This report lets the user to read a form template from the hard-drive, read the XML data file from the hard-drive and merge it together using your ADS service (note: you need to have the ADS service installed and configured, so make sure you have it before starting to implement this).
- Now we can split the problem into three parts: how to get the XML data, how to get the template, how to merge it together. The third part is obviously solved by the source code of the mentioned report, so that is not a problem and I will only discuss the first two parts.
How to get the XML data
For those who are not aware of it, you can generate the testing XML file from the LCD as well. Go to: File – Form properties – Preview – Data file and have the file generated by the LCD. This probably fits the best the process where the template comes from an external SAP source (but still had to be designed in LCD).
Now you know, how you need to shape the XML. (To be precise: you cannot use any SAP tools for this since you don´t have the DDIC structures and an interface for the external form, right? But you could create the structures and use it in an interface, which will not be implemented by any SAP form template. Or you could change the process flow of the forms: create a template in the SAP system (with the interface etc.) and using some job you will export the template so the forms are available on the external “site/server” like it was needed in the original scenario. Then you would be able to simplify things: you could use the ordinary forms printing instead of this complicated one. But that is another story).
Let´s create the XML file now. There are ways how to do it. You can create a simple transformation, write the XML envelope as a static text into a body of the transformation and dynamically fill the variables into the specified place. If you´re interested in the transformations, there are plenty of course where to read about “ABAP simple transformation”. Or you can create a DDIC structure corresponding with the structure of the XML file and use transformation ID to do the most of the work for you. I hope you have the file now.
How to get the file
In the report mentioned above you can read how would you read the file if it would be saved on your desktop. You need to change the process so it can be done by the server without the user interventions. There are several ways how to do it and I will let you search for the details. An important question is when the server will download the template from the external source. Every time a form is printed from SAP? Or a synchronization tool should be created for this purpose? It is up to you and the process.
Alternatives and non-ABAP tools
If you don´t like this way, I am sure there are alternatives, but I am not aware of any alternative in ABAP. If you can use Java and can do some Java, you can use iText library to manipulate the PDF file. You would read the template into Java, set the fields one by one, and save the new file filled with data. But you mostly don´t have the option to run external Java (ok, you could do it from the Portal for example, but could be an issue from ABAP).
By the way, sometimes it is very useful if you can use the external tools, for example when you Converting multiple files in a PDF-spool-job into one sinlge PDF (what is not possible with the current version of Ads, I believe, correct me if I am wrong, because it would help hundreds of people, check for yourself how many times this question was asked in the forums).
Hope these lines will spare somebody some time. Please comment, I am ready to improve the text with any ideas you might have. Regards Otto