Create template for PDF creation in Cocoa / Objective C - objective-c

I am coding a Mac application. I want to give the user the opportunity to create a template for PDF creation. The PDF should be created from different NSTextFields where the users types in. So, the PDF creation should be dynamic. For example for an invoice. The format stays while the information on the PDF changes.
I use a NSTextView with a ruler which is always shown. Now I want to write for example <TextField1> in some point of the Sheet and where this TextField1 is, the input from TextField1 should be. I thought about getting the position of TextField1 and using it in the PDF creating process. But I am still not sure if its the right way. The PDF should always be for A4 format. Is it even possible to set the PDF View (on the screen) to an A4 view, so the user can see how the PDF will look in a printed version ?
The ruler is shown by using [textView setRulerVisible:YES];

Related

Creating a custom diploma from a designer template, filling in data

I need to be able to create PDFs with printable diplomas for sports events (10K runs etc).
A graphic designer creates a beautiful diploma with placeholder texts (name of participant, finish time) - and I need to get from that to a finished PDF (on the fly), which the participant can download.
What output should I get from the designer (file format, prepared in any special way)?
How do I take that file, fill in data and generate PDF?
How can this be accomplished using IText?
I have done a lot of generating PDFs from HTML and Word docs, but this is something new to me, so I am can't figure out where to start.
My best idea right now is to have the designer export as PDF without placeholder text, but with x/y coordinates and font on where to input name, time etc... But I would prefer to not have to store the x/y coordinates, font etc - and just be able to fill in a "template"...
There are several possibilites e.g:
Let your designer create a diploma PDF
Add form fields at the places you want to add name and event etc. This can be done by you or the designer or a PDF lib like openPdf / PdfBox / iText
Fill in the data using openPdf / PdfBox / iText and afterwards make the field readonly
You could even sign the PDF afterwards (and thus "protect" it from changes)
OR
2a) You could also add text to an existing PDF but this is a bit trickier since you need to know the coordinates and need to care about length issues etc.

Printing pdf document on paper with predifned layout

We need to print a pdf document on the page which has predefined fields on it, a formular basically, which fields needs to be filled.
We are using iTextSharp to create pdfs and we use absoulte positioning for elements based on the formular fields positioning. For instance, if the field starts 20mm from left and 20 mm from top I will put data to start at 21mm from the left and 21 mm from top so it fits inside that field. And it works well on my printer.
But my question is, can different printers mess up positioning because of different margins, font sizes, etc... Maybe it will be the same, I am not aware of what differences can different printers bring.
Is it important that user chooses Actual size option when printing pdf?
I need to know what difficulties I can expect, better to know it now then waiting customers calling when this is in production.
The problem you anticipate, exist. It can be avoided by setting a viewer preference.
See How to prevent the resizing of pages in PDF?
You have to set the print scaling to none:
writer.addViewerPreference(PdfName.PRINTSCALING, PdfName.NONE);
That's the line you'll need if you are using iText 5 (writer is an instance of PdfWriter). If you are using iText 7, you can define the viewer preferences like this:
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
PdfViewerPreferences preferences = new PdfViewerPreferences();
preferences.setPrintScaling(PdfViewerPreferencesConstants.NONE);
pdf.getCatalog().setViewerPreferences(preferences);
See Handling events; setting viewer preferences and printer properties.
Of course, end users can always overrule the print scaling in their PDF viewer, but that's their responsibility, not yours.

Determine the Text that can Display in Multiline PDTextField

Is there a way to determine the text that will actually display in a PDTextField when the PDF prints? If I call setValue and then getValue, it returns all of the text even though it will not all display.
I am trying to fill out a form with a limited size multiline text field that has the notation to attach another page for more details. I would like to limit the text to that which will display and generate the added detail page.
Thanks for indulging a PDFbox newbie.
There is no direct way to find that out as the details of the text layout such as line breaks, padding, line spacing are hidden inside the non public class PlainTextFormatter inside the org.apache.pdfbox.pdmodel.interactive.formpackage. So you'd need to replicate that code.
PDFBox tries to resemble the calculations done by Adobe Acrobat and Adobe Reader but the details of such calculations are not part of the PDF specification. So doing your calculation is only valid for a similar layout model. Other form filling applications might have a slightly different layout model and as a result your results will not apply to these.
In addition to that Acrobat (and PDFBox) place text although it might be partially clipped. Look at the results of the AlignmentTest.javaunit test to see what I mean. So one might have a different expectation to what 'fitting' really means.
As I've thought about passing the information about which text fitted back to the calling application anyway I've opened an enhancement request https://issues.apache.org/jira/browse/PDFBOX-3413 for that.

create pdf with a template pdf and add image, text, barcode, and complete field form , objective c, OS X

I am a newbie at Objective-C. I'm working on a project for a OSX. I have a pdf template file with form fields, and I need to use it to generate a new pdf adding some images, text, barcode, and complete form fields.
I've been researching for working with PDFs, I'm trying to use Quartz 2D, CGPDFContext, and at this moment I managed to fill a new pdf with the page template, but I donĀ“t know how to do to write on the fields forms and add other images.
How can I draw at specific point, text or image? or exist any library to manage pdf? and for generate barcode128? Thank you so much!
Once you have a CGPDFContext you can draw whatever you want into it as you would with any other context. A simple solution is to create a CALayer (or a view and then access its layer) with the content you want and then to draw that layer into your PDF context.
Getting the editable text fields isn't so easy, this might help.
If you can do away with the PDF template and do the whole thing as a view that you render into a PDF context that would be easier, but the process is generally the same once you know where you need to draw your additional text / graphics.

iText - PDF file displaying message at the top about fillable form

Here is what I did:
1. I have a template WORD file that can be used to fill an application for some stuff. Assigned pre-defined tags to fillable fields.
2. Converted that word file to PDF file using CenoPdf
3. Used iText to fill the fields in generated PDF file.
4. Now when user downloads that filled file, they see a nice purple at the bar saying "Please fill out the following form. You can not save data typed into this form. Please print your completed form if you would like to copy for your records".
how can i get rid of this purple bar and the message? I am assuming i need to set some bits through iText to turn this off??
Thanks
You can't edit the purple bar at the top. This is a flaw with Acrobat. Whenever your PDF contains form fields, the message is automatically displayed by force and you cannot edit it. Adobe feels that it's users are more important than it's developers, and forces the bar and message whenever form fields are present.