We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How do you clone the object/document

Hi All
I am using ReplaceOnlyFirstOccurrenceOfThePhrase to replace text in many files
what i am doing right now is opening one pdf and changing text to many different new text and saving to multiple output pdfs. for example: 1pdf x 10 new texts
I was just trying to reduce time per file. currently its take around 0.7sec per file. as we have millions of files

		Document pdfDocument = new Document(absPath);
        for (int i = 0; i < data.length; i++) {
                // I want to clone the object here for each iteration.                                  
        	   Document pdfDocumentClone = (Document) pdfDocument.Clone();


         }

for clone i get error The method clone() from the type Object is not visible.

Any suggestion would be appreciated

@ahmedsunny

Unfortunately, Aspose.PDF does not provide APIs to clone the Document. We have logged this feature request as PDFNET-51487 in our issue tracking system. You will be notified via this forum thread once this feature is available. We apologize for your inconvenience.

As a workaround, you can use streams to copy Document. In this case, you need to initialize the document using file path and in each iteration of loop, copy the document stream. Hope this helps you.

FileStream DocumentStream = new FileStream(SourcePath, FileMode.Open);
for (int i = 0; i < data.length; i++)
{
	MemoryStream ms = new MemoryStream();
	DocumentStream.CopyTo(ms);
	Document doc = new Document(ms)
 	// Your code....
 	// Your code....
}