Free Support Forum - aspose.com

iText to Aspose PDF

Hi,

I have recently purchased Aspose pdf license. Previously, I was just iText for PDF manipulations as mentioned in the below snippet. Is it possible to convert the method to Aspose? I have tried but as I’m not that well versed with Aspose pdf I’m unable to solve it?

Can you please provide a solution for the same.

Thanks,
Aditya

private void creatingFile(FormFile file, String number) {

	Document document = new Document(PageSize.A4, 50, 50, 50, 50); 
	
	
	try {
		PdfReader pdfReaderTemp;
		PdfWriter writer = PdfWriter.getInstance(document,
				new FileOutputStream(new File(file.getFileName() + number+ ".pdf")));
	
		document.open();
		PdfContentByte cb = writer.getDirectContent();
		PdfImportedPage page;

		pdfReaderTemp = new PdfReader(file.getFileName() + number+ ".pdf");
		int pages = 0;

		while (pages < (pdfReaderTemp.getNumberOfPages())) {
			pages++;
			document.newPage();
			page = writer.getImportedPage(pdfReaderTemp, pages);
			cb.addTemplate(page, 0, 0);
			
		}
		pdfReaderTemp.close();

		document.close();
		writer.close();

	} 
	
	catch (Exception e) {
		e.printStackTrace();
		document.close();
	} 
	
	finally {

		try {
			File pdfFile = new File(file.getFileName() + number+ ".pdf");
			
			if (pdfFile.exists()) {
				pdfFile.delete();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		

	
	}
}

@AdityaSingh,

Can you please share source files along with generated result and environment details so that we may further investigate to help you out.