How to add dynamic text to PDF toolbar using ITEXTSHARP - c#

Hi All,
I am creating a PDF document using ITEXTSHARP. I need to add some content to PDF toolbar while creating the PDF document. How can i achieve this using C#. Please see the attached image for reference.
Thanks in advance.

iTextSharp is used to generate PDF files, not modifying the PDF viewer. If you need to modify toolbars and stuff like this in Adobe Reader this definitely is not something that you could achieve with iTextSharp.

eh...
Ok so how to do it.
Make template in Word.
eg of Word
Name <FirstName>
Surname <LastName>
Job <JobType>
Salary <Salary>
When generating:
Open word and replace and other marks
Then makepdf (pdfcreator for example)
Edit:
Okay Ill show u schema, no ready code cuz little busy
1) Create word template and
store it in safe place. 2) Copy
template to temp folder 3) Open in
programicaly in C# and replace
"" with ur data
.Replace('', 'Voon') 4)
Programiticaly print to PDF and save
it.

Only a plugin can modify the acrobat/reader toolbar. There might be C# bindings for the acrobat API these days, but I wouldn't count on it.
PS: You can make Acrobat plugins for free. To "Reader Enable" a plugin requires Adobe's direct intervention, and $$$. They sign a version of the plugin, and only that signed version will run in Reader.
Your best bet is to go looking for some third-party PDF viewer. I still wouldn't count on this feature being available, but it's better odds than "0".

Related

Is it at all possible to convert a document to PDF or edit a PDF in C# using only free software?

I had this stupid idea of creating a template as a .docx or .rtf or .pdf and then replacing the text in that document to generate reports. This seemed like a better way of doing it than using paid reporting software.
Well, I believe I've tried just about everything now and I'm amazed at how impossible it is to do anything with pdfs.
Try 1
HTML -> PDF
A lot harder to design the template. It doesn't look the same when you print it. Never got it working outside of a command line example (not sure how well, say, iTextSharp-LGPL would even work or if it could handle base64 strings as I'm not sure how else you are going to tell it about images). In any case, doing it this way makes it too hard to design the template.
Try 2
OpenXml -> PDF
I stupidly assumed that because Word could save as PDF that OpenXml could to. I was wrong. It cannot save as a PDF.
Try 3
OpenOffice/LibreOffice (docX -> PDF)
It can't read OpenXml which is a problem because I was editing the template as OpenXml and then saving that result (as a .docx) but it can't read that saved document.
Try 4
iTextSharp LGPL
This one just doesn't work, lol. And apparently even though when you google "convert rtf to pdf" the ONLY thing that comes up is iText and its derivatives it doesn't convert rtf documents to pdf documents. I verified this myself (it only saves the text not the formatting) and later found this post to convince me I wasn't doing something wrong.
Try 5
PDF -> PDF
Since converting ANYTHING to a PDF seems to be impossible maybe I can save the template as a PDF and just do a text replace on that. Nope, lol, that is apparently a very difficult thing to do.
Try 6
Pandoc (.odt/.docx -> pdf), (.rtf -> .pdf not supported)
pandoc mockup2.odt -s -o mockup2.pdf
link to the files in the picture. *note, it messes up in the same way if you try converting .odt/.docx to .tex.
What do I do here? Buy software so that I can save a file as PDF? Is that the only option?
I have a solution. I'm not saying it's the best solution. LibreOffice (or possibly OpenOffice if you are so inclined) accepts command line arguments that will do the switch.
soffice.exe --headless --convert-to pdf mockup.odt
*note - this is after I added libreoffice to my path (C:\Program Files\LibreOffice\program). idk why it's called soffice.exe instead of libreoffice.exe.
where i found the answer
relevant documentation
I might have a working solution for you, if you are stuck with the docx-file for the template.
I found one free solution for docx to pdf conversions, without using microsoft.interop, etc.: See first answer in this stack overflow post
It uses two tools: The open xml power tools and DinkToPdf (Which is essentially a wkhtmltopdf wrapper). The html to pdf part works just fine, but the docx to html part looks like a catastrophe at first. You can fix this with custom css (There are some resources online).
Powertools-.NetStandard
DinkToPdf-GitHub
There are more possibilities for proprietary software, like Asposes.Words and Syncfusion file-formats. Most of the proprietary solutions are pretty expensive...
If you are just working on a Windows Environment, where MS-Office is installed, you can use Microsoft.Interop. It is by far the easiest solution (In this post, Interop is mentioned several times Stackoverflow Word to PDF
If you found another (better) working solution, please let me know. I still have not decided if I will use a proprietary or a free solution. :-)

Fill Embedded PDF from values in Windows Form - C#

So I've embedded a PDF in one of my windows forms. It works great, but is there a way for me to populate the pdf with values from another form?
For example, I'd wanna take a comboBox.Text value and place that in one of the PDF's Textboxes.
I was just wondering if there was any solution for me to do this programmatically with C#.
Thanks for any feedback.
How exactly are you integrate the PDF into your form?
which library you are use?
I'm asking because it depends how to achieve you goals.
For example, yo can use aspose pdf for .net, patagames pdfium.net sdk, debenu quick pdf library or something else. iText sharp pdf or ghost library

Is it possible to generate .docx files without having MS Word installed?

I want to use "OLE automation" (or whatever it's called now) to generate a Word document.
I assume that it's possible to perform the following programmatically:
Set page size (height, width, margin vals)
Set font type/name, style, and size
Add page numbering
Add pages
Insert page breaks
What I'm not sure of is if I need to have MS Word on my system to do this (to have the necessary DLLs, perhaps)? I use Open Office (I like it, and it's free), but I reckon controlling the creation of docs programmatically is probably easier/better documented for MS Word than it is for Open Office and/or Libre Office - that's why I'm strongly considering making this "rendezvous with Redmond."
This question is tangentially related to this one
If Google Docs is a possibility here, I'd be willing to have a "meeting with Mountain View" but I know nothing about that file format or whether it can be "automated" etc.
I need to end up with something that I can either convert to a PDF file or a DOCX file. Open Office can open DOCX and convert files to PDF, but I don't know about Google Docs.
I've found https://docx.codeplex.com/ to be very useful in dynamically building docx documents.
Yes,
it is possible. Check this link: http://www.microsoft.com/en-us/download/details.aspx?id=30425
this is a library for open xml documents (*.docx, *.xlsx and powerpoint files)
yes you can Use Openxml , also with openXml you can create Excel Pdf and ...
Check This out
You can use this library to generate document by template:
https://github.com/StasClick/DocumentGenerator
'DocumentGenerator' can generate one leaflet, multiple leaflets in one document or registers.

iTextSharp or XSL-FO to create a PDF dynamically with fillable forms?

This is my first stackoverflow question.
After days of research, I am still lost on how this can be done, if its even possible.
I am trying to create a PDF document using either iTextSharp or XSL-FO (FO.NET is what I am using currently). Creating the documnet is no problem. I need this documnet to have fields that the user can still fill in.
I am aware of the ability to create a PDF form using acrobat, then using iTextSharp to fill in those fields. This can then be saved and the user can open the document and edit it.
The problem with this is, anytime the PDF "template" needs to be changed, someone has to edit the PDF document, then change the backend logic to handle the new field.
I am looking for a 100% dynamic solution.
Ideally I would use XSL and FO to create this document without the need for an exisiting PDF document. I have found no way to create a fillable form using FO.NET, or even iTextSharp, without already having an exisiting PDF "template".
Thanks in advance.
I believe both the RenderX XEP and Antenna House FO processors support PDF Forms. They aren't free and additional output modules may be required for PDF Forms.

Replacing contents inside docx and pdf file using asp.net c#

In my application I am using some templates in docx and pdf format. I am storing this docs to DB as Bytes.
Befor showing/sending this docs back to user or application I need to replace some contents inside the doc. eg:if the doc contain ##username## I need to replace this with the exact username of the customer. I am not getting a proper solution for this. Any good ideas?
For the docx file, your best bet is to use OpenXML, and instead of having special text like ##username##, replace it with a content control that you can fill in.
Since you specified docx, you can use OpenXML, which is great, it's an API. If it has to work with older doc files, then you'll have to automate Word (which should be avoided if at all possible).
For the PDF, your best bet is to create a PDF form, and fill it in a runtime (using a tool like itextsharp).
HTH,
Brian
For DOC / DOCX:
You should use the MSWord object model through MSWord assembly reference (will work only on machines which have msoffice installed.. or else you can use something like ASPOSE word libraries which wont need msoffice installation on server). You can programmatically trigger the Find-Replace context of word through the library's API.
For PDF: You will need a third party library for editing pdf files.. 3rd party libraries like ABCpdf are available.. (not sure whether Adobe itself has something for this)
The same mechanism like for word library.. but I am not sure whether you will be able to trigger the Find-replace context here or do something else... I have not used a pdf generation library.

Categories

Resources