Hi.
Have been working on this for a bit and figured some direction may save some time at this point. I have existing Word documents that need to be rendered into PDF with watermark and multi-column headers and footers (including page numbers).
Your documentation has helped me get each of these things done individually but I can’t seem to make it all come together. I can build a new PDF with my headers and footers exactly like I want them, but I cannot seem to merge pages from the Word doc (saved as pdf) into it and keep my headers and footers and watermark.
Perhaps I’m going about this the wrong way? What is the recommended process for this? Some investigation leads me to believe that I cannot insert a table into the header/footer section of an existing PDF which seems to eliminate the idea that I just add them to the SavedAsPDF document…but the merging is not doing the correct thing either as it all seems page based so the append, insert, concatenate operations always keep the original content in the original style as new pages and the header/footer page is just sitting around looking stupid.
I’ve attached a sample of the header/footer formatting I need to apply. The watermark seems like it can be applied after the fact to all pages with few problems…Any ideas?
Need to add watermark- page numbers- multi-column headers and footers to Word doc and convert to PDF
Hi Dave,
I’m afraid, I couldn’t completely understand your requirement. Could you please share some more details? Are you trying to add the header and footer in the Word document or you’re adding them in the PDF files converted from the Word documents? Or you’re trying to merge the header and footers from a separate file and main contents from other PDF files into a single file? Please elaborate your requirement in detail.
We’re sorry for the inconvenience and looking forward to help you out.
Regards,
Shahzad,
Thanks for the response. The requirement is as follows:
Customer has Word documents that have no header/footer or watermark. They must be kept in this format for the primary purpose. As a secondary requirement, the same documents must rendered into PDF’s with all of the header/footer and watermark information on all pages. It doesn’t matter where in the process these stamps are applied, but the end result is that we should have any document be marked up with the header/footer/watermark information as shown in the attached PDF. The attachment shows ALL of the information that needs to be attached to any Word document in the final PDF output.
In fact, after much trial and error I was able to get exactly what I needed - but the process is anything but optimal as I have to apply each item individually as a stamp and then save the file to the filesystem and then re-open to add the next stamp.
Here is the process that I am using now which seems like it should be able to be streamlined…
- Get Word document and save as a PDF file on the filesystem (if I save to stream I get an error when trying to open the stream in PDF.Kit - seems like a common Aspose defect which has been reported but not fixed)
- Open tempFile1 PdfFileInfo to get number of pages from the pdf
- Open tempFile1 PdfFileStamp and AddPageNumber in upper righthand corner
- Close tempFile1 to save changes - new output file is tempFile2
- Open tempFile2 PdfFileStamp and add Title information to header (could not add both page number in upper right and the title in the header using the same PdfFileStamp object because one would overwrite the other - only option is to add one stamp and close, then reopen and add the next stamp!)
- Close tempFile2 to save - new output file is tempFile3
- Open tempFile3 PdfFileStamp and add a footer with copyright and disclaimer (these can be done together as one long string with spaces separating since they are static except for year which is always 4 characters)
- Close tempFile3 to save - new output file is tempFile4
- Open tempFile4 PdfFileStamp and add approved date text in bottom right - NOTE: had to use AddPageNumber method because adding an additional footer/header would blow away earlier stamp but AddPageNumber and AddFooter/AddHeader will not overwrite each other
- Close tempFile4 to save - new output file is tempFile5
- Open tempFile5 PdfFileStamp and add the watermark image (not shown in the sample)
- Close tempFile5 saving output to final path
- Delete all interim files from filesystem
So this is a pretty elaborate process to do something that would have been easily achievable if I could have added a table in the header/footer of the PDF. I attempted to add this to the Word document first but the issue there was that the header/footer would always be limited to the margins and the customer’s margins on their documents are non-standard to allow for their watermark image on the left side of the document text. If I could have expanded the header and footer region in the document I could have used a table in the Word doc and THEN converted to PDF.
Anyway, it is working but I feel that this could be streamlined with some improvements in the API.
Thanks,
Dave
Hi Dave,
As far as I understand, you’re able to achieve your goal using Aspose.Pdf.Kit; however, the main concern is to add header, footer, page number etc. in one go. Please correct me if I’m wrong.
I’m afraid, currently Aspose.Pdf.Kit doesn’t allow you to perform multiple operations at the same time; however, we’re working on a new version which will allow you to open and close a PDF document only once and do all the other operations between these two actions. I’m sure your concerns will be catered in our new release. It will take some time before this new version is available. We’ll announce the release through our blogs.
If you have any further questions or concerns, please do let us know.
Regards,
That is part of the problem. It could be solved a couple different ways.
- Fix the bug which prevents doing these multiple tasks using Stream objects instead of files on the filesystem.
- Allow tables in PDF header/footer of existing documents.
- Allow inserted content/pages to get the header/footer/watermark of the destination document
I can add a header/footer table using Pdf object but this is only seemingly for a new document I’m creating from scratch. I spent hours trying to use this functionality but I could not get it to insert content or pages from another PDF into the new one I created with the proper headers/footers.
The real issue to me is that there seems to be several ways that I could have accomplished my goal but none of them worked and the end result is I had to come up with something that seems like a hack (e.g. using AddPageNumber to put custom text because I could not have a table in the footer). Why only allow a table in the header for a new document? Why not be able to insert pages into a new document with header and have the header also apply to the inserted pages?
Hi Dave,
All of your other concerns will be handled appropriately in our new version; however, the following issue is concerned with a bug in the current version.
irmsdev:
- Fix the bug which prevents doing these multiple tasks using Stream objects instead of files on the filesystem.
Could you please share the input PDF file along with the code snippet, highlighting the area(s) where you’re having problem(s) while working with Streams? We’ll look into this issue and try to provide you the resolution the earliest possible. Moreover, the newer version will also allow you to add the tables in the header and footer in an existing file as well.
We’re sorry for the inconvenience.
Regards,