Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Command- Convert-PnPFileToPdf #3435

Merged
merged 8 commits into from
Dec 22, 2023

Conversation

NishkalankBezawada
Copy link
Contributor

@NishkalankBezawada NishkalankBezawada commented Sep 22, 2023

Type

  • Bug Fix
  • New Feature
  • Sample

Related Issues?

Fixes #3422

What is in this Pull Request ?

New command which converts a file in SharePoint to PDF.

Convert-PnPFileToPDF

Converts a file to Pdf, File contents can either be saved to local, returned as memorystream and can upload the file to SharePoint Online (Same Site Collection)

SYNTAX

Save to local path

Convert-PnPFileToPDF -Url <String> -Path <String> [-Force]

Return as memorystream

Convert-PnPFileToPDF -Url <String> -AsMemoryStream

Save to SharePoint Online (Same SiteCollection)

Convert-PnPFileToPDF -Url <String> -Folder<String>

DESCRIPTION

Allows the conversion of a file from SharePoint Online. The file contents can either be directly saved to local disk, or stored in memory for further processing, or Can be uploaded back to SharePoint Online SiteCollection

EXAMPLES

EXAMPLE 1

Convert-PnPFileToPDF -Url "/sites/project/Shared Documents/Document.docx" -AsMemoryStream

Retrieves the file, converts to PDF, and outputs its content to the console as a Memory Stream

EXAMPLE 2

Convert-PnPFileToPDF -Url "/sites/project/Shared Documents/Document.docx"

Retrieves the file, converts to PDF, and outputs its content to the console as a Memory Stream

EXAMPLE 3

Convert-PnPFileToPDF -Url "/sites/project/Shared Documents/Document.docx" -Path "C:\Temp"

Retrieves the file and converts to PDF, and save it to the given local path

EXAMPLE 4

Convert-PnPFileToPDF -Url "/sites/project/Shared Documents/Document.docx" -Path "C:\Temp" -Force

Retrieves the file and converts to PDF, and save it to the given local path. Force parameter will override the existing file in the location where the document gets saved.

EXAMPLE 5

Convert-PnPFileToPDF -Url "/sites/SampleTeamSite/Shared Documents/Nishkalank's/Book.xlsx" -Folder "Archive"

Retrieves the file and converts to PDF, and save it to the given Document library in SharePoint Online (Same Site Collection). Returns the saved file information in the console.

PARAMETERS

-Url

The URL (server or site relative) to the file

Type: String
Parameter Sets: (All)
Aliases: ServerRelativeUrl, SiteRelativeUrl

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-AsMemoryStream

Type: SwitchParameter
Parameter Sets: Return as memorystream

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Path

Local path where the file should be saved

Type: String
Parameter Sets: Save to local path

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Force

Overwrites the file if it exists.

Type: SwitchParameter
Parameter Sets: Save to local path

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Folder

The destination library in the site

Type: FolderPipeBind
Parameter Sets: (UPLOADTOSHAREPOINT)

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

RELATED LINKS

Microsoft 365 Patterns and Practices
Convert files to PDF using Graph API
I

@KoenZomers
Copy link
Collaborator

Really nice addition @NishkalankBezawada . Looks good to me. What do you think @gautamdsheth ?

@gautamdsheth gautamdsheth self-assigned this Sep 26, 2023
@gautamdsheth gautamdsheth added the in review PR or issue is currently being reviewed label Sep 26, 2023
src/Commands/Files/ConvertFileToPdf.cs Outdated Show resolved Hide resolved
src/Commands/Files/ConvertFileToPdf.cs Outdated Show resolved Hide resolved
src/Commands/Files/ConvertFileToPdf.cs Outdated Show resolved Hide resolved
@gautamdsheth
Copy link
Collaborator

gautamdsheth commented Oct 19, 2023

Hey @NishkalankBezawada - is it ok with you if I make changes here ? I actually found a different way to do this

@NishkalankBezawada
Copy link
Contributor Author

Hey @NishkalankBezawada - is it ok with you if I make changes here ? I actually found a different way to do this

Hey @gautamdsheth, Sure thing, You may indeed 💯. But, I will also check-in my changes in resolving the comments, and you can compare those as well, if it is neccesary

Thanks,
Nishkalank

@gautamdsheth
Copy link
Collaborator

@NishkalankBezawada - Actually, the way it will work is that it will support conversion of different files to different formats not just PDF, so if you haven't made the changes, don't start 😊

Sorry about this.

@NishkalankBezawada
Copy link
Contributor Author

@NishkalankBezawada - Actually, the way it will work is that it will support conversion of different files to different formats not just PDF, so if you haven't made the changes, don't start 😊

Sorry about this.

Hey Again @gautamdsheth, Thats true, its just the parameter we pass for the conversion. However, I have almost completed my changes though. I was sick back then, so couldnt complete it before. Will send you out the review mostly by tomorrow.

Thanks,
Nishkalank

@NishkalankBezawada
Copy link
Contributor Author

@NishkalankBezawada - Actually, the way it will work is that it will support conversion of different files to different formats not just PDF, so if you haven't made the changes, don't start 😊
Sorry about this.

Hey Again @gautamdsheth, Thats true, its just the parameter we pass for the conversion. However, I have almost completed my changes though. I was sick back then, so couldnt complete it before. Will send you out the review mostly by tomorrow.

Thanks, Nishkalank

Hello @gautamdsheth

I have done the neccessary changes as suggested. Kindly review

Thanks,
Nishkalank

@NishkalankBezawada
Copy link
Contributor Author

Hello @KoenZomers & @gautamdsheth, Any update on this PR.

Thanks,
Nishkalank

@gautamdsheth
Copy link
Collaborator

hi @NishkalankBezawada , sorry will have to close this PR.
It will be a part of this one , #3616 .

The mentioned PR takes care of quite a lot of different formats including PDF.

Will be crediting you for sure.

@NishkalankBezawada
Copy link
Contributor Author

NishkalankBezawada commented Dec 20, 2023

hi @NishkalankBezawada , sorry will have to close this PR. It will be a part of this one , #3616 .

The mentioned PR takes care of quite a lot of different formats including PDF.

Will be crediting you for sure.

That was my idea #3616.

I would have expected a help or may be you might have modified it later by enhancing it, adding new properties. I heard MVPs and Maintainers help out other enthusiasts, and I am sorry I am not at all satisified, @gautamdsheth @KoenZomers

//Nishkalank

@gautamdsheth gautamdsheth reopened this Dec 21, 2023
@gautamdsheth
Copy link
Collaborator

hi @NishkalankBezawada , sorry about this.
Totally my bad, it is not my intention at all to override your code.

How do I fix this ? The code right now , as it is, looks good and we can merge it.
I can improve it later on.

Or , we can work together via review comments and improve it ?
Sorry again about this 🥹🙏

@NishkalankBezawada
Copy link
Contributor Author

NishkalankBezawada commented Dec 21, 2023

as it i

Hello @gautamdsheth

I really appreciate for re-opening and saying that you will merge it.

I didnt mean that you have overwritten the code. Its just the strategy, I got this idea first to use GraphAPI, and it should be welcomed. However, You later you got another idea, to get file and convert it to desired format using PnP, which is again brilliant and can be enhanced on top of the actually PR. I do understand your time and effort but would be really nice if you have discussed this without closing this PR.

However, thanks once again for re-opening, you may merge it and probably enhance it later with your idea on saving a file in different formats.

Thanks,
Nishkalank Bezawada

I meant to say that, the scope for improvement should be seen.

@gautamdsheth
Copy link
Collaborator

Hi @NishkalankBezawada !

You are correct.
This was not the correct way to go about with this PR, I should have at least had a conversation before.

My mistake totally , will discuss first before doing anything.

Regards,
Gautam

@gautamdsheth gautamdsheth merged commit bcdd552 into pnp:dev Dec 22, 2023
3 checks passed
@NishkalankBezawada NishkalankBezawada deleted the feature-3422 branch December 22, 2023 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in review PR or issue is currently being reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Convert a file in SharePoint to PDF.
3 participants