Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Created April 25, 2019 15:45
Show Gist options
  • Save GroupDocsGists/17c3111caf511725760bbd3db43beee3 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/17c3111caf511725760bbd3db43beee3 to your computer and use it in GitHub Desktop.
// For complete examples and data files, please go to https://github.com/GroupDocs-Merger/GroupDocs.Merger-for-Java
String sourceFile = CommonUtilities.sourcePath + fileName;
// Preparing.
String password = "SomePasswordString";
int pageNumber1 = 3;
int pageNumber2 = 6;
SwapOptions pagesOptions = new SwapOptions(pageNumber2, pageNumber1, FileFormat.One, password);
InputStream documentExample = new FileInputStream(sourceFile);
// Main method.
DocumentResult result = new DocumentHandler().swapPages(documentExample, pagesOptions);
OutputStream documentStream = result.getStream();
ByteArrayOutputStream byteArrayStream = (ByteArrayOutputStream) documentStream;
byte[] bytes = byteArrayStream.toByteArray();
FileOutputStream fos = new FileOutputStream(CommonUtilities.outputPath + fileName);
fos.write(bytes, 0, bytes.length);
fos.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment