I have used Cells.Net and Words.Net for many years, but PDF.Net is giving me a hard time. Firstly there is confusion about using “Generator” DOM or just the main DOM. Examples exist using both which are incompatible with each other and some examples only exist in one or the other!
I’ve realised that there really is no such things as headers and footers. Sections seems to exist in generator but not the core DOM. Here is a simple VB.Net example which first creates a table and fills with lots of rows which make the table wrap onto more than one page. Next I create a top left header, top right header and bottom left footer and bottom right page number footer. As soon as I try to wrap the text in the top left header, it simply moves down the page for no reason! Then I try to add the stamps to each page in the document and find that only two pages exist despite the fact that the table has created extra pages! Right now can’t seem to loop through all pages and add headers/footers. This is driving me crazy! Any help most appreciated.
Dim doc As New Aspose.Pdf.Document()
Dim PageInfo As Aspose.Pdf.PageInfo = doc.PageInfo
Dim marginInfo As Aspose.Pdf.MarginInfo = PageInfo.Margin
marginInfo.Left = 36
marginInfo.Right = 36
marginInfo.Top = 48
marginInfo.Bottom = 48
'PageInfo.IsLandscape = True
Dim curPage As Aspose.Pdf.Page = doc.Pages.Add()
Dim paragraphs As Aspose.Pdf.Paragraphs = curPage.Paragraphs
Dim dt As DataTable = New DataTable(“Employee”)
dt.Columns.Add(“Employee_ID”, GetType(Int32))
dt.Columns.Add(“Employee_Name”, GetType(String))
dt.Columns.Add(“Gender”, GetType(String))
For i As Integer = 1 To 150
dt.Rows.Add(i, “John Smith”, “Male”)
Next
Dim table1 As Aspose.Pdf.Table = New Aspose.Pdf.Table()
table1.ColumnWidths = “100 100 100”
table1.ImportDataTable(dt, True, 0, 0)
'table1.IsInNewPage = True
paragraphs.Add(table1)
'now try to add a header (known as a stamp)
Dim TLHeaderStamp As New Aspose.Pdf.TextStamp(“Expenses for Brown C (341) that were processed by Atkinson C (18) - 2017-02-21 11:32”)
TLHeaderStamp.VerticalAlignment = VerticalAlignment.Top
TLHeaderStamp.HorizontalAlignment = HorizontalAlignment.Left
TLHeaderStamp.TextState.FontSize = 12
TLHeaderStamp.LeftMargin = 36
TLHeaderStamp.Width = 288
TLHeaderStamp.WordWrap = True
TLHeaderStamp.TopMargin = 24
Dim TRHeaderStamp As New Aspose.Pdf.TextStamp(Now.Date.ToString(“dd-MMM-yy”))
TRHeaderStamp.VerticalAlignment = VerticalAlignment.Top
TRHeaderStamp.HorizontalAlignment = HorizontalAlignment.Right
TRHeaderStamp.TextState.FontSize = 12
TRHeaderStamp.TopMargin = 24
TRHeaderStamp.RightMargin = 36
Dim BLFooterStamp As New Aspose.Pdf.TextStamp(“Manager”)
BLFooterStamp.VerticalAlignment = VerticalAlignment.Bottom
BLFooterStamp.HorizontalAlignment = HorizontalAlignment.Left
BLFooterStamp.TextState.FontSize = 10
BLFooterStamp.BottomMargin = 24
BLFooterStamp.LeftMargin = 36
Dim BRFooterStamp As New Aspose.Pdf.PageNumberStamp()
BRFooterStamp.VerticalAlignment = VerticalAlignment.Bottom
BRFooterStamp.HorizontalAlignment = HorizontalAlignment.Right
BRFooterStamp.TextState.FontSize = 10
BRFooterStamp.BottomMargin = 24
BRFooterStamp.RightMargin = 36
'Now add another page and see what happens to stamps
curPage = doc.Pages.Add()
For Each currPage As Aspose.Pdf.Page In doc.Pages
currPage.AddStamp(TLHeaderStamp)
currPage.AddStamp(TRHeaderStamp)
currPage.AddStamp(BLFooterStamp)
currPage.AddStamp(BRFooterStamp)
Next
doc.Save(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "" & “programaticallyproducedpdf.pdf”)
System.Diagnostics.Process.Start(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "" & “programaticallyproducedpdf.pdf”)
Hi Martin,
I bought this component so that I could quickly produce PDF files within a few weeks. Can you give me some clue as to how long these fixes will take please so that I can continue my work or seek another component elsewhere. Thanks
Hi Martin,
“Still pending for review” is not very encouraging! I can’t wait 6 weeks for a resolution to this - I must produce my software within two weeks. Being able to do a multi-page table and then add headers/footers is such a basic requirement that I would have to describe your PDF dot net component as seriously flawed. Will you allow a refund for the license in this case please?
Hi Martin,
It is now nearly a month since you added this bug. When will a new version be released please?
Hi Martin,
Another week goes by…component must be more broken that I imagined. Still can’t believe that I’m the first to create a PDF from scratch, then add a multi-page table and then add headers and footers to each page. My customer is getting fed up to be honest and wishes that I had tested your component before purchase. Seriously though, how could I imagine that something so basic wouldn’t actually work?
Hi Martin,
Two months now since I purchased this component for £1,585.00 and still can’t generate a multi-page PDF from scratch with a multi-page table and headers/footers in the correct position. I don’t doubt that lots of other users are using it quite successfully in other ways, but surely being able to create a basic PDF with a multi-page table and headers that stay at the correct position is not asking too much?
I’ve already lost 2 months of updates of this component and my customer is totally un-impressed that I can’t yet provide what they need. This reflects badly on me. I have always been impressed with Words/Cells, so this is why I went with your PDF component. Come on Aspose!
Hello Martin,
Hi Martin,
Thanks for your patience.
We have further investigated earlier reported issues and as per our observations, the generation of the table is executed when document is saved. That is why stamps are added only on 1st and 4th page (2nd and 3rd are added during generator processing)
Therefore it is enough to save document into stream and reload back and add stamps after this.
Please take a look over following code snippet.
Dim doc As Aspose.Pdf.Document = New Document()
Dim curPage As Aspose.Pdf.Page = doc.Pages.Add()
Dim paragraphs As Aspose.Pdf.Paragraphs = curPage.Paragraphs
Dim dt As DataTable = New DataTable("Employee")
dt.Columns.Add("Employee_ID", GetType(Int32))
dt.Columns.Add("Employee_Name", GetType(String))
dt.Columns.Add("Gender", GetType(String))
For i As Integer = 1 To 150
dt.Rows.Add(i, "John Smith", "Male")
Next
Dim table1 As Aspose.Pdf.Table = New Aspose.Pdf.Table()
table1.ColumnWidths = "100 100 100"
table1.ImportDataTable(dt, True, 0, 0)
paragraphs.Add(table1)
' Now try to add a header (known as a stamp)
Dim TLHeaderStamp As New Aspose.Pdf.TextStamp("Expenses for Brown C (341) that were processed by Atkinson C (18) - 2017-02-21 11:32")
TLHeaderStamp.VerticalAlignment = VerticalAlignment.Top
TLHeaderStamp.HorizontalAlignment = HorizontalAlignment.Left
TLHeaderStamp.TextState.FontSize = 12
TLHeaderStamp.LeftMargin = 36
TLHeaderStamp.Width = 288
TLHeaderStamp.WordWrap = True
TLHeaderStamp.TopMargin = 24
Dim TRHeaderStamp As New Aspose.Pdf.TextStamp(Now.Date.ToString("dd-MMM-yy"))
TRHeaderStamp.VerticalAlignment = VerticalAlignment.Top
TRHeaderStamp.HorizontalAlignment = HorizontalAlignment.Right
TRHeaderStamp.TextState.FontSize = 12
TRHeaderStamp.TopMargin = 24
TRHeaderStamp.RightMargin = 36
Dim BLFooterStamp As New Aspose.Pdf.TextStamp("Manager")
BLFooterStamp.VerticalAlignment = VerticalAlignment.Bottom
BLFooterStamp.HorizontalAlignment = HorizontalAlignment.Left
BLFooterStamp.TextState.FontSize = 10
BLFooterStamp.BottomMargin = 24
BLFooterStamp.LeftMargin = 36
Dim BRFooterStamp As New Aspose.Pdf.PageNumberStamp()
BRFooterStamp.VerticalAlignment = VerticalAlignment.Bottom
BRFooterStamp.HorizontalAlignment = HorizontalAlignment.Right
BRFooterStamp.TextState.FontSize = 10
BRFooterStamp.BottomMargin = 24
BRFooterStamp.RightMargin = 36
' Now add another page and see what happens to stamps
curPage = doc.Pages.Add()
' Save and load the document
Dim ms As New MemoryStream()
doc.Save(ms)
ms.Seek(0, SeekOrigin.Begin)
doc = New Document(ms)
For Each currPage As Aspose.Pdf.Page In doc.Pages
currPage.AddStamp(TLHeaderStamp)
currPage.AddStamp(TRHeaderStamp)
currPage.AddStamp(BLFooterStamp)
currPage.AddStamp(BRFooterStamp)
Next
doc.Save("c:/pdftest/programaticallyproducedpdf.pdf")
Thank you. Using doc.ProcessParagraphs() has successfully forced all pages to be generated prior to document save. This leaves the issue with the top left stamp which does not appear in the correct position when aligned top and left. This is still a major problem for my customer
Hi Martin,msutherland25:Thank you. Using doc.ProcessParagraphs() has successfully forced all pages to be generated prior to document save. This leaves the issue with the top left stamp which does not appear in the correct position when aligned top and left. This is still a major problem for my customer
Yes, the stamp appears much further down the page when rendered and thus overwrites important information underneath. This only happens to the top left stamp - all others appear correctly…
Hi Martin,