I have a fillable PDF form which needs to be programatically filled for each member and added to a single pdf document.
I am able to use pdfstamper to read the existing pdf, and change the data, but I cant seem to figure out how to create multiple instances of the pdfstamper with different data in the same pdf doc.
You don't. One PDF stamper->1 document OUTPUT. You didn't give a lot of detail, but your workflow will probably need to be something like this:
For Each PDF form:
* Open it with a Stamper
* Fill it in
* turn on flattening
* Save it (to memory or disk)
Create a PdfCopy (or SmartCopy)
For each intermediate PDF
* Insert it into Pdf*Copy
Save your final doc.
None too efficient, but that's how it works with iText.
PS: You really do need to flatten your forms when merging multiple forms together, PARTICULARLY when you have multiple copies of the same form. In a PDF, fields that share a name also share a value.
Related
I need to create a .pdf file so it 'mimics' a Department of Treasury document.
I was wondering if it's best to use tables to display non db info, or should I simply add a paragraph at a time ?
My plan was to save non-configurable parts of the Treasury document in separate image files and load them into my .pdf at their correct location, but I was wondering if it's better to save these parts in their own .pdf files instead of image files ?
I should create a new pdf , for example a offer. At the end of the new pdf i have to import several existing pdfs, these pdf has form fields and i must fill up this fields.
One problem is that the different existing PDF has all the same form fields e.g txtNAME.
Is there a possibility to add existing PDF in a open document and fill up formfields directly?
Thank for help or ideas
Just keep in mind that fields with the same name will have the same value.
This can be a boon (if you did some thinking ahead when you planned the forms), but it also can be a hindrance.
One possibility you may have, if the number different additional pages is not too high: You might prepare a "master form", which contains the subsequent pages as hidden Templates, and then when you create your document, you will spawn the according pages with the option to make unique field names.
I would like to embed one Word document (call it "hidden.docx") into another Word document (call it "host.docx"). The document hidden.docx would not be visible at all when host.docx is opened in Word by an end-user. Document hidden.docx would only be carried inside host.docx, sort of as unstructured cargo data.
All research I have done points me to the use of something called altChunk offered by the Open XML SDK. I have installed Open XML SDK and got a sample working: http://msdn.microsoft.com/en-us/library/gg490656%28v=office.14%29.aspx
My question: In order to insert an altChunk into a docx, do I really need the Open XML SDK? Can this not be accomplished using VSTO? If so, how?
[PS: My ultimate goal is, for a pair of documents where one document is the original text and the other is its translated version in another language, to be able to preserve the original document within the translated document, so as not to lose it. For any document pair, there's always the risk that the two documents become separated through misplacement of one of them.]
Yes and No.
1.) That's not what AltChunks do. AltChunks are a way to embed one document into another document such that they get merged together. They are not hidden. If you create a docx package with an AltChunk in it, and then open up Word, Word will immediately merge that AltChunk into the document. (If that AltChunk is another Word document that also contains child AltChunks they will be recursively merged into the parent as well.) Basically, it's an easy way to merge content together without having to reconsolidate all their styles, rIDs, etc. -- if you save the document and examine it, the AltChunk will be gone, and you will notice that Word has merged the document back together into a single document again.
2.) Range.InsertXML, if provided a valid Flat Package for a full Word document will, under the hood, invoke that same merge functionality (down to having the same bugs, etc.) that you would get from an AltChunk. The two behave identical, and you can even create a document package with the OpenXML SDK that contains embedded AltChunks, and insert those (I've done this in Word 2007, 2010, and 2013) -- of course, as I mentioned above, the AltChunks are never persisted, they're immediately merged into the document.
If you want to save hidden data in a document, I recommend using Custom XML (take a look at Document.CustomXMLParts). Keep in mind though, at least in Word 2010, Undo does not revert changes to CustomXML parts.
If you simply want to include some file into the Open XML package, then the simplest way is to use API from the System.IO.Packaging namespace (First obtain the reference to the main document part of the host part):
EmbeddedPackagePart hiddenDocumentPart = mainDocumentPart.AddEmbeddedPackagePart(#"application/vnd.openxmlformats-officedocument.wordprocessingml.document");
hiddenDocumentPart.FeedData(File.Open(hiddenDocumentFile, FileMode.Open));
Just to be sure, this way the hidden document will be in no way part of the host document content. It will only be part of its file (package). You can later extract it with a similar method: Get the main part of the host document, find the embedded (hidden) part and get/read the data from it.
I have 4-5 PDFs have that could have 2-3 pages each. I then merge all the pdf together using iTextSharp. So it looks like 1122233444555 (each set of # represents a pdf. The duplicating represents the pages) The whole set is the new PDF.
We have a requirement where after the pdfs have merged, we may need to insert another PDF (2 pages) in between 2 & 3. How would I go about inserting after the last page of 2 and before the first page of 3? So it should now look like 1122266633444555.
We are not storing the # of pages so I don't want to rely on passing in the page numbers. Can I write some hidden file names in each page and use itextsharp to read the hidden information? Then I can say add pdf 666 after the last page of 222.
One way to do this is by marking page 2 for post-processing using a PdfPageLabels object. Some sample code. See the links in the first paragraph of the link to the sample code for another way to do this by adding hidden fields to the document.
I am using Open XML SDK and altchunk to merge multiple documents in a winforms application, after merging I want to manipulate paragraphs, the problem that until a document that contains altChunk elements is opened and saved in Office, it still contains the altChunk parts, and not normal WordprocessingML markup of paragraphs, runs, and text elements. So I need to proceed to chunk importation to get the WordprocessingMl and to be able to manipulate paragraphs, runs, texts... The solution with SharePoint 2010 is that you can use Word Automation Services to update the documents that contains altChunk elements. After Word Automation Services processes it, the document will contain paragraphs, runs, and text elements, but here I am using winforms application. Is there a solution for this problem?
Regards.
An altChunk approach to merging word documents relies on the consuming application (the application which opens the resulting document) to do the actual merging, like Word or Word Automation Services.
See: http://blogs.msdn.com/b/ericwhite/archive/2009/04/19/comparison-of-altchunk-to-the-documentbuilder-class.aspx
I don't think you will be able to reference the runs, paragraphs etc of the inserted document (altChunk) using the OpenXML API until this merging has been done. Maybe if you open the altChunk data and load that into a new WordprocessingDocument. But then maybe you could just make the changes to the documents before you merge them with altChunks?
As a workaround, I make copies for the merged documents, I proceed the changes on this copies, when the merged document is opened the altchunks are imported, in this way I keep the original merged documents content unchanged