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
640

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 (1)

Accepted Solutions (1)

Alexander_0001
Participant
0 Kudos

Not possible to merge two pdfs and to save the new pdf within CPQ via code because of limitation  :

Forbidden .NET Classes and Namespaces
The following .NET namespaces and classes are forbidden in IronPython scripts:

System.IO

System.Data

System.Configuration

Webcom.Configurator.Util.ConnectionStringProvider

System.Environment

System.GC

System.Type

System.Web.WebPages.Razor

System.Reflection

System.Web

System.Diagnostics

If there are scripts that contain System import * and Webcom.Configurator.Util import * and any of the words from the forbidden classes, the system disables saving scripts (for example, saving is disabled if there is System import * and Data in the same script).

For troubleshooting, please contact the SAP CPQ Support team.

Source: https://help.sap.com/docs/SAP_CPQ/884885f05e6b4c8082254d4d9d63f19b/91907b16b55f4daba0b34a266...

Answers (0)