Private SPFolder GetFolder(SPFolder parentFolder, string folderName) ![]() In fact these I could just use this method for both and check for null instead of true/false This code is almost identical to Does folder exist, except instead of return true/false it returns the folder or null. If(f.Name.Equals(folderName, StringComparison.InvariantCultureIgnoreCase)) Throw new ArgumentNullException("folderCollection") Private bool FolderExistsImplementation(SPFolderCollection folderCollection, string folderName) ![]() Var exists = FolderExistsImplementation(folderCollection, folderName) Var folderCollection = parentFolder.SubFolders Throw new ArgumentException("folderName") Private bool DoesFolderExist(SPFolder parentFolder, string folderName) Pass in folder and folder we are looking for. I have pinched this method and converted to work on an on-premise code from the OfficeDevPnP code. I used a helper method to check if folder exists and another method to return the found folder. SPFile newFile = ("combined.pdf", result, true) Create a new file in the Merged folder called combined.pdf from the byte array. Convert the final memory stream into a byte array. Import the page to the PDF document in the memory stream.Ĭopy.AddPage(copy.GetImportedPage(reader, page)) Loop through each page in the current PDF file PdfReader reader = new PdfReader(li.File.OpenBinaryStream()) Convert the BinaryStream of the file to a ITexSharp PdfReader Open the document before any changes can be made. Using (PdfCopy copy = new PdfCopy(document, ms)) Using the ITextSharp PdfCopy to create a PDF document in the memory stream Using (Document document = new Document()) Using (MemoryStream ms = new MemoryStream()) ![]() Check that there are any documents to merge SPListItemCollection listItems = library.GetItems(query) Include all subfolders so include Recursive Scope CAML Query to return all pdf file types. Merged = GetFolder(library.RootFolder, "Merged") Using helper method (explained further down, Get folder called Merged) If (!DoesFolderExist(library.RootFolder, "Merged")) Using helper method (explained further down, look for folder called Merged) Protected void btnPDFMerge_Click(object sender, EventArgs e) Select the Deployment Target as GlobalAssembl圜ache and the location is itextsharp.dllīelow is the code and comments explaining what is happening at different stages of the code. Navigate down through the folder to Packages\iTextSharp.5.5.4\lib\itextsharp.dll. You will find the dll sitting in a package folder at the same location you find the. Then click the Add to add Existing assemblies. Double Click on the Package.Package file in your project. All that remains is to ensure that this dll is deployed to the GAC. This will add the itextsharp reference to your project. Just click the Install button, and accept the License Acceptance. Type in the Search Online Box for ITextSharp, the top result should be ITextSharp. This will open the Manage NuGet Packages dialog. Right click your project and select Manage NuGet Packages… The Shared Document library for my site, I already have pdf’s files from my previous demos.įirst thing we need to do is add the itextsharp to the Visual Studio project. Unfortunately, I’m not showing you how to do this in this demo. The advantage of using ITextSharp dll, is that you could create a provider hosted SharePoint App, and therefore create this merge functionality in Office 365. Looping through each file, copies each pdf to a memory stream, once it have completely looped through each file, it then saves the file back to the SharePoint library. įollowing on from my last Farm Solution, I have extended the solution by adding another button that when clicked, it looks up the document library and grabs all pdf files. iTextSharp is a port of the iText open source java library for PDF generation written entirely in C# for the. In this post I’m going to show you how to use ITextSharp to merge your PDF’s together. In the last couple of posts I’ve shown you how to convert Word and PowerPoint documents into PDF.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |