cancel
Showing results for 
Search instead for 
Did you mean: 

CPQ 2.0 - How to convert and merge PDF Files via IronPython or .NET code in CPQ?

Alexander_0001
Participant
0 Kudos

Hi SAP Community,

I try to load pdf's via a global script from additional files directory. I call the pdfs and receive a System.IO.MemoryStream objects.How can I merge multiple pdfs with the given code capabilities? 

Additionally, I have to convert System.IO.MemoryStream objects to a FileStream object to store it again in content files directory. How can I achieve this due to the fact that system namespace System.IO forbidden?

My orientation was the following documentation: SAP Docu

################################################################################


### Define Parameter ###

File1 = '001.pdf'
File2 = '002.pdf'

BaseUrl = 'additionalfiles'

PathToDataSheet1 = BaseUrl + File1

PathToDataSheet2 = BaseUrl + File2

### Get the Pdf files ###

GetDatasheetFile = FileHelper.GetStreamFromPath(PathToDataSheet1)

GetDatasheetFile = FileHelper.GetStreamFromPath(PathToDataSheet2)

### Convert MemoryStream to HTTPContent ###

HTTPContent1 = ?
HTTPContent2 = ?

### Merge files ###

MergedFile = ?

### Store Merged file ###

#add headers using AddContentHeaders() method
MergedFile.AddContentHeaders('Content-Type', 'application/pdf')

#making MultipartFormDataContent and specifying its name
MultiPartContent = MultipartFormDataContent()
MultiPartContent.Add(StreamContent(MergedFile), "file", "MergedFile.pdf")

# add new file to managed content
urlSetSpesificContentFile = baseUrl + '/api/v1/admin/files/ContentFile'
NewSpesificContentFile = RestClient.Put(urlSetSpesificContentFile, headers, MultiPartContent)

@LukaPilipovic Maybe you could help me with my coding issue here or know someone which maybe has the experience to know a solution for this issue. 

Kind regards
Alexander



Accepted Solutions (0)

Answers (0)