Every plugin takes its source document in the constructor, either as a file path or as a Stream.
Load a Document from a File Path
Pass the path of the source document. A relative path is resolved against the current directory. The following example splits out the first two pages of a PDF document loaded from a file.
usingSystem;usingGroupDocs.Merger.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Load the source document from a file pathvarsplitter=newSplitPdf("business-plan.pdf",new[]{1,2});// Save one document per pagesplitter.Save("output/page.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)' Load the source document from a file path
DimsplitterAsNewSplitPdf("business-plan.pdf",{1,2})' Save one document per page
splitter.Save("output/page.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)// Load the source document from a file path
letsplitter=SplitPdf("business-plan.pdf",[|1;2|])// Save one document per page
splitter.Save("output/page.pdf")0
Pass a Stream that contains the source document. The plugin reads the stream from the beginning, regardless of its current position, so pass a stream whose content starts at offset 0. The stream stays open after Save; disposing of it remains your responsibility.
usingSystem;usingSystem.IO;usingGroupDocs.Merger.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Open the source document as a streamusingvarstream=File.OpenRead("business-plan.pdf");// Load the source document from the streamvarsplitter=newSplitPdf(stream,new[]{1,2});// Save one document per pagesplitter.Save("output/page.pdf");
ImportsSystemImportsSystem.IOImportsGroupDocs.Merger.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Open the source document as a stream
Usingstream=File.OpenRead("business-plan.pdf")' Load the source document from the stream
DimsplitterAsNewSplitPdf(stream,{1,2})' Save one document per page
splitter.Save("output/page.pdf")EndUsingEndSubEndModule
openSystemopenSystem.IOopenGroupDocs.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)// Open the source document as a stream
usestream=File.OpenRead("business-plan.pdf")// Load the source document from the stream
letsplitter=SplitPdf(stream,[|1;2|])// Save one document per page
splitter.Save("output/page.pdf")0
The merge plugins (JoinPdf, JoinDocx, and JoinPptx) accept the source document as a path or a stream, but the documents to append are always file paths.
usingSystem;usingSystem.IO;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);// Open the source document as a streamusingvarstream=File.OpenRead("chapter-1.pdf");// The documents to append are file pathsvarmerger=newJoinPdf(stream,new[]{"chapter-2.pdf","chapter-3.pdf"},newJoinOptions());// Save the merged documentmerger.Save("output/merged-chapters.pdf");
ImportsSystemImportsSystem.IOImportsGroupDocs.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)' Open the source document as a stream
Usingstream=File.OpenRead("chapter-1.pdf")' The documents to append are file paths
DimmergerAsNewJoinPdf(stream,{"chapter-2.pdf","chapter-3.pdf"},NewJoinOptions())' Save the merged document
merger.Save("output/merged-chapters.pdf")EndUsingEndSubEndModule
openSystemopenSystem.IOopenGroupDocs.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)// Open the source document as a stream
usestream=File.OpenRead("chapter-1.pdf")// The documents to append are file paths
letmerger=JoinPdf(stream,["chapter-2.pdf";"chapter-3.pdf"],JoinOptions())// Save the merged document
merger.Save("output/merged-chapters.pdf")0
Each plugin checks that the source document has the format named in the plugin: JoinPdf expects a PDF document, SplitDocx a DOCX document, and so on. A file is checked by its extension, and a stream by its content. When the format doesn’t match, the plugin throws FileTypeNotSupportedException before doing any work. See Handling Errors.
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.