Every plugin has one method, Save, which performs the operation and writes the result to the output path you pass. Missing folders in the output path are created, and existing files are overwritten.
Save a Document to a File
The merge plugins and RemovePagesPdf write one document. The following example saves a merged document to a folder that is created automatically.
usingSystem;usingGroupDocs.Merger.Domain.Options;usingGroupDocs.Merger.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Append the second chapter to the first onevarmerger=newJoinPdf("chapter-1.pdf",new[]{"chapter-2.pdf"},newJoinOptions());// Save to a folder that doesn't exist yetmerger.Save("output/merged/chapters-1-2.pdf");
ImportsSystemImportsGroupDocs.Merger.Domain.OptionsImportsGroupDocs.Merger.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Append the second chapter to the first one
DimmergerAsNewJoinPdf("chapter-1.pdf",{"chapter-2.pdf"},NewJoinOptions())' Save to a folder that doesn't exist yet
merger.Save("output/merged/chapters-1-2.pdf")EndSubEndModule
openSystemopenGroupDocs.Merger.Domain.OptionsopenGroupDocs.Merger.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Append the second chapter to the first one
letmerger=JoinPdf("chapter-1.pdf",["chapter-2.pdf"],JoinOptions())// Save to a folder that doesn't exist yet
merger.Save("output/merged/chapters-1-2.pdf")0
The split plugins write one document per part, and the output path determines the names of the parts:
A plain path. The part number is added to the file name, before the extension: output/business-plan.pdf produces output/business-plan_2.pdf, output/business-plan_4.pdf, and so on.
A {0} template. When the file name contains {0}, the part number replaces it: output/page-{0}.pdf produces output/page-2.pdf, output/page-4.pdf, and so on. A {1} in the template is replaced with the extension of the source document.
When you split out specific pages or a range of pages, each part is numbered after the source page it holds. When you split a document at specific pages with SplitMode.Interval, the parts are numbered from 0.
Add the Part Number to the File Name
usingSystem;usingGroupDocs.Merger.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Select pages 2 and 4varsplitter=newSplitPdf("business-plan.pdf",new[]{2,4});// Save business-plan_2.pdf and business-plan_4.pdfsplitter.Save("output/business-plan.pdf");
ImportsSystemImportsGroupDocs.Merger.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Select pages 2 and 4
DimsplitterAsNewSplitPdf("business-plan.pdf",{2,4})' Save business-plan_2.pdf and business-plan_4.pdf
splitter.Save("output/business-plan.pdf")EndSubEndModule
openSystemopenGroupDocs.Merger.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Select pages 2 and 4
letsplitter=SplitPdf("business-plan.pdf",[|2;4|])// Save business-plan_2.pdf and business-plan_4.pdf
splitter.Save("output/business-plan.pdf")0
usingSystem;usingGroupDocs.Merger.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Select pages 2 and 4varsplitter=newSplitPdf("business-plan.pdf",new[]{2,4});// Save page-2-of-business-plan.pdf and page-4-of-business-plan.pdfsplitter.Save("output/page-{0}-of-business-plan.pdf");
ImportsSystemImportsGroupDocs.Merger.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Select pages 2 and 4
DimsplitterAsNewSplitPdf("business-plan.pdf",{2,4})' Save page-2-of-business-plan.pdf and page-4-of-business-plan.pdf
splitter.Save("output/page-{0}-of-business-plan.pdf")EndSubEndModule
openSystemopenGroupDocs.Merger.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Select pages 2 and 4
letsplitter=SplitPdf("business-plan.pdf",[|2;4|])// Save page-2-of-business-plan.pdf and page-4-of-business-plan.pdf
splitter.Save("output/page-{0}-of-business-plan.pdf")0
Use an output path that contains a folder, as the examples in this documentation do, or an absolute path. A relative path that contains a folder, such as output/merged.pdf, is resolved against the current directory.
Note
When the output path is only a file name, such as merged.pdf, the plugins save the result to different places: the merge plugins and RemovePagesPdf save it to an Output folder in the application base directory (for example, bin/Debug/net8.0/Output/merged.pdf), while the split plugins save the parts to the current directory.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.