SharePoint / sp-dev-docs

SharePoint & Viva Connections Developer Documentation
https://docs.microsoft.com/en-us/sharepoint/dev/
Creative Commons Attribution 4.0 International
1.25k stars 1.01k forks source link

How to set the culture of the PDF converter? #8635

Open IllimarAtShareCloud opened 1 year ago

IllimarAtShareCloud commented 1 year ago

What type of issue is this?

Question

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Target SharePoint environment

SharePoint Online

What browser(s) / client(s) have you tested

Additional environment details

No response

Issue description

So we are leveraging the PDF converter .pdfConversionUrl found in in the ListSchema in one of our solution.

Sry hard to explain, because I was not the orginal author, then I do not exactly know the terms, but here is the code:

const viewXml: string = `
                <View Scope='RecursiveAll'>
                    <Query>
                        <Where>
                            <In>
                                <FieldRef Name='ID' />
                                <Values>
                                    <Value Type='Counter'>${file.itemId}</Value>
                                </Values>
                            </In>
                        </Where>
                    </Query>
                    <RowLimit>1</RowLimit>
                </View>
            `;

            let response = await sp.web.lists.getById(file.listId).renderListDataAsStream({ RenderOptions: options, ViewXml: viewXml }) as any;
            // "{.mediaBaseUrl}/transform/pdf?provider=spo&inputFormat={.fileType}&cs={.callerStack}&docid={.spItemUrl}&{.driveAccessToken}"

            let pdfConversionUrl = response.ListSchema[".pdfConversionUrl"];
            let mediaBaseUrl = response.ListSchema[".mediaBaseUrl"];
            let callerStack = response.ListSchema[".callerStack"];
            let driveAccessToken = response.ListSchema[".driveAccessToken"];

            response.ListData.Row.forEach(element => {
                let fileType = element[".fileType"];
                let spItemUrl = element[".spItemUrl"];
                let pdfUrl = pdfConversionUrl
                    .replace("{.mediaBaseUrl}", mediaBaseUrl)
                    .replace("{.fileType}", fileType)
                    .replace("{.callerStack}", callerStack)
                    .replace("{.spItemUrl}", spItemUrl)
                    .replace("{.driveAccessToken}", driveAccessToken)
                ;
                let pdfFileName = element.FileLeafRef.replace(fileType, "pdf");

                const pdfFile:ISharePointPdFConversionFile = {
                    serverRelativeUrl: element["FileRef"], 
                    pdfUrl: pdfUrl, 
                    fileType: fileType, 
                    pdfFileName: pdfFileName,
                    fileSize: parseFloat(element['File_x0020_Size']),
                    sourceUniqueId: file.uniqueId
                };

                ret.push(pdfFile);
            });

Anyway, the endpoint works fine as expected, it is just when converting the Excel files into PDF-s then the date format is always what I assume to be en-US however the site that we are using is ee-ET

Is there a way to set the culture of the converter? I could not find anything on the issue on the wider web.

The closest thing I could find is the Graph API, with uses the same endpoint (at least according to one blog) and there nothing is said about how to set the culture: https://learn.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0&tabs=http

ghost commented 1 year ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.