Add Page Number Stamp in a PDF File in VB - Aspose.PDF for .NET - Out of memory Error

please send me the vb.net code for the full procedure for my requirement.

Can you please respond to my query ASAP?

Hi Rajsingh,

Please try using the following code snippet to accomplish your requirement.

[VB.NET]

' instantiate Document Object

Dim doc As Document =  New Document("c:/pdftest/1.pdf")

Dim doc2 As Document =  New Document("c:/pdftest/ChartsandGraphs.pdf")

' concatenate the page of PDF documents

doc.Pages.Add(doc2.Pages)

' create page number stamp

Dim pageNumberStamp As New PageNumberStamp()

' whether the stamp is background
pageNumberStamp.Background = False

pageNumberStamp.Format = "Page # of " & doc.Pages.Count

pageNumberStamp.BottomMargin = 10

pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Center

pageNumberStamp.StartingNumber = 1

' set text properties

pageNumberStamp.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Arial")

pageNumberStamp.TextState.FontSize = 14.0F

pageNumberStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold

pageNumberStamp.TextState.FontStyle =  Aspose.Pdf.Text.FontStyles.Italic

pageNumberStamp.TextState.ForegroundColor = Color.Aqua

Dim page_counter As Integer = 1

For Each page As Page In doc.Pages
    ' add stamp to particular page
    doc.Pages(page_counter).AddStamp(pageNumberStamp)
    page_counter += 1
Next

doc.Save("c:/pdftest/StampAdded.pdf")

Thank for this but when we do doc.Pages.Add(doc2.Pages) it will again have issue of out of memory.

Hi Rajsingh,


In this scenario, I will suggest you to please split the large PDF into smaller size PDF files (i.e. 100 pages PDF) and then use individual small files to generate the single resultant file. In order to create smaller size documents, you may consider extracting the pages from large file and saving them separately. For further details, please visit Concatenate PDF Files.

In case you encounter any issue while concatenating the PDF files, please share the resource files so that we can test the scenario at our end.

I have created small files and now i want to give stamp like pdf 1 has got 1000 page and pdf 2 got 800.i have also got total number of pages count as 1800 in variable.now when i am giving stamp to individual file first file is getting 1 of 1800, 2 of 1800 and so on.but 2nd file is also getting 1 of 1800 , 2 of 1800 and so on.but i want to give second file as 1001 of 1800,1002 of 1800 and so on.meaning i want to pass value of # for the below syntax whichi should increment.

pageNumberStamp.Format = "Page # of " & i

rajsingh85007:

I have created small files and now i want to give stamp like pdf 1 has got 1000 page and pdf 2 got 800.i have also got total number of pages count as 1800 in variable.now when i am giving stamp to individual file first file is getting 1 of 1800, 2 of 1800 and so on.but 2nd file is also getting 1 of 1800 , 2 of 1800 and so on.but i want to give second file as 1001 of 1800,1002 of 1800 and so on.meaning i want to pass value of # for the below syntax whichi should increment.

pageNumberStamp.Format = "Page # of " & i

Hi Rajsingh,

In order to start the page count for second file (800 pages file) from 1001, use the starting number as PageCount of first PDF + 1 (i.e. new Document("1000PagePDF.pdf").pages.count + 1) and use this value as starting number for second PDF file.

With 6000 page file which is of size 31 mb i am getting out of memory error.i cannot further break this file. also i am unable to attach this file over here.please let me know how to send that file so that you can replicate this issue.

In my below code i get out of memory when i try to add stamp for page 630.

doc10 = New Document"\\ysiinvgs3Reports70rel\Demo\temp\OG\MINTRA_42430010_0.pdf")
For Each page As Page In doc10.Pages
pageNumberStamp.Format = "Page" & total_page_counter & " of " & i
doc10.Pages(page_counter).AddStamp(pageNumberStamp)
page_counter += 1
Next
doc10.Save("\\ysiinvgs3\Reports70rel\Demo\temp\OG\MINTRA_424300010_S.pdf")

please help me in solve this issue as its very urgent now.

Hi Rajsingh,


Please upload the file to some free FTP (i.e. GoogleDrive, SkyDrive, DropBox etc) and share the link with us. We will test the scenario and will share our findings.

Here is the file.
https://drive.google.com/file/d/0B0VMx4LFjvKoRHk0eDhEWWJac0U/edit?usp=sharing

please take it and let me know ASAP as this is super urgent.

rajsingh85007:
Here is the file. https://drive.google.com/file/d/0B0VMx4LFjvKoRHk0eDhEWWJac0U/edit?usp=sharing

please take it and let me know ASAP as this is super urgent.

Hi Rajsingh,

Thanks for sharing the resource file. However it looks like file is protected and I have sent a request to access this file. Please allow the privileges to download the file.

I have given access of file.
please investigate and let me know ASAP.

Hi Rajsingh,

Thanks for granting the permissions. I have tested the scenario using the following code snippet with the latest release of Aspose.Pdf for .NET 9.5.0 and I am unable to notice any problem when using a Visual Studio 2010 project with the target platform as .NET Framework 4.0, running over a Windows 7 (x64) machine. My system configurations are Intel Core i5, 2.5 Ghz with 4 GB of RAM.

Can you please try using the latest release version and see if it resolves your problem? For your reference, I have also attached the resultant PDF generated on my end. Please access the file over this link.

[VB.NET]

'instantiate Document Object
Dim doc As Document = New Document("c:/pdftest/AAMINTRA_42430011_0.pdf")

'Dim doc2 As Document = New Document("c:/pdftest/ChartsandGraphs.pdf")

' concatenate the page of PDF documents
'doc.Pages.Add(doc2.Pages)

'create page number stamp

Dim pageNumberStamp As New PageNumberStamp()

'whether the stamp is background

pageNumberStamp.Background = False

pageNumberStamp.Format = "Page # of " & doc.Pages.Count

pageNumberStamp.BottomMargin = 10

pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Center

pageNumberStamp.StartingNumber = 1

'set text properties

pageNumberStamp.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Arial")

pageNumberStamp.TextState.FontSize = 14.0F

pageNumberStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold

pageNumberStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Italic

pageNumberStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Aqua

'Dim page_counter As Integer = 1'

' For Each page As Page In doc.Pages

'    'add stamp to particular page

'    doc.Pages(page_counter).AddStamp(pageNumberStamp)

'    page_counter += 1'

' Next'

doc.Save("c:/pdftest/AAMINTRA_42430011_0_StampAdded.pdf")

Can you try with framework 2 target platform as I am having that.

Hi Rajsingh,


I have again tested the scenario with .NET Framework 2.0 and I am unable to notice any issue. Can you please share some sample application so that we can again try replicating the issue at our end.

HI,

I tried with latest apse.pdf dll and its working fine.

can you pelase try once with 7.3.0.0 version dll?

Hi Rajsingh,


There are many releases between 7.3.0 and 9.5.0 and during all this time, we have made many improvements in our API and it looks like some of the recent enhancements has also fixed this problem. Even if we are able to reproduce the issue with 7.3.0, I am afraid we might not be able to resolve it in older release. So it is highly recommended to please try using the latest release and in case you still face the same issue or you have any further query, please feel free to contact.

i cannot use latest dll jsut like that. all i am asking is to try once at your end with 7.3.0 dll and see if you get the stamped pdf or not. i am not asking to resolved in this version. jsut test and let me know.

I cant even test fully as its putting stamp only on 4 pages and if i add my license then get this error. how do u expect me to test?

The subscription included in this license allows free upgrades until 25 Jun 2014, but this version of the product was released on 31 Jul 2014. Please renew the subscription or use a previous version of the product.

Hi Rajsingh,

I have tested the scenario using Aspose.Pdf for .NET 7.3.0 and have managed to notice the OutOfMemory Exception.

Now concerning to testing 9.5.0 without any limitations, you may consider requesting a 30 days temporary license. For further information, please visit Get a temporary license