A few questions regarding dynamic PDF generation capabilities of PDFNet.

Q:

I have a couple of questions regarding PDFNet. We have an application
that generates dynamic pdf reports based on user input.

- Can you output text at a given coordinate position?
- Can you output multiline text at a given coordinate position that
word wraps automatically? Can you set the alignment of the text?
- Can you add security to the pdf file?
- We need to take an existing pdf file and mark it up and merge it
into the dynamically created pdf file. Is this possible with your
library?
- Can you add images to the dynamic pdf file.
----

A:

Can you output text at a given coordinate position?

You can use PDFNet to output text at a given coordinate. As a starting
point you may want to take a look at ElementBuilderTest sample
project: (http://www.pdftron.com/net/samplecode/
ElementBuilderTest.cs).

// Create a new page
Page page = doc.PageCreate(new Rect(0, 0, 612, 794));
// or use an existing page to add new content...
page=pdfdoc.PageFind(1).Current();

ElementBuilder eb = new ElementBuilder();
ElementWriter writer = new ElementWriter();
writer.Begin(page);

// Begin writing a block of text
element = eb.CreateTextBegin(Font.Create(doc,
Font.StandardType1Font.e_times_roman), 12);
writer.WriteElement(element);

element = eb.CreateTextRun("Hello World!");

// Position and scale the text. The fist argument in Matrix2D is
// horizontal scale. The fourth argument is vertical scale.
// The fifth argument is horizontal offset (i.e. translation) and the
// last argument specifies the vertical offset.
element.SetTextMatrix(new Matrix2D(10, 0, 0, 10, 40, 600));
element.GetGState().SetLeading(15); // Set the spacing between lines
writer.WriteElement(element);

// Finish the block of text
writer.WriteElement(eb.CreateTextEnd());
writer.End(); // save changes to the current page

// If the page is new, add it to the document..
doc.PagePushBack(page);

Can you output multiline text at a given coordinate position that
word wraps automatically? Can you set the alignment of the text?

Since there are so many ways to wrap the text, PDFNet does not provide
automatic word wrapping at the moment. We are in the process of adding
some utility functions that would allow the user to flow the text
using a number of different algorithms and adjustable parameters to
control the text flow. In the meantime, you can wrap the text as
illustrated in ElementBuilder sample project (you can also search PDF
Knowledge Base [http://groups.google.com/group/pdfnet-sdk] for
keywords such as "wrap text").

You can align/justify the text by taking into account the length of
the text run (returned by element.GetTextLength()). For example:

In C#
writer.WriteElement(element_builder.CreateTextBegin(Font.Create(doc,
font), font_size));
Element element = element_builder.CreateTextRun("My text");

// To right justify
element.SetTextMatrix(1, 0, 0, 1, box_width - element.GetTextLength(),
pos_Y);

// To 'center' justify
// element.SetTextMatrix(1, 0, 0, 1, (box_width -
element.GetTextLength())/2, pos_Y);

writer.WriteElement(element);
writer.WriteElement (element_builder.CreateTextEnd())

In C++:
writer.WriteElement(element_builder.CreateTextBegin(Font::Create(doc,
font), font_size));
Element* element = element_builder.CreateTextRun("My Text");

// To right justify
element->SetTextMatrix(1, 0, 0, 1, box_width - element-

GetTextLength(), pos_Y);

// To 'center' justify
// element->SetTextMatrix(1, 0, 0, 1, (box_width - element-

GetTextLength())/2, pos_Y);

writer.WriteElement(element);
writer.WriteElement(element_builder->CreateTextEnd())

---

Can you add security to the PDF file?

For an example of how to encrypt existing PDF documents please take a
look at EncTest sample project (http://www.pdftron.com/net/
samplecode.html#EncTest). For example, you can secure an existing (or
new) PDF document in C# as follows:

StdSecurityHandler new_handler = new StdSecurityHandler();

// Set a new password required to open a document
string my_password = "test";
new_handler.ChangeUserPassword(new
System.Text.UTF8Encoding().GetBytes(my_password));

// Set Permissions ...
// new_handler.SetPermission(SecurityHandler.Permission.e_print,
true);
//
new_handler.SetPermission(SecurityHandler.Permission.e_extract_content,
false);

pdfdoc.SetSecurityHandler(new_handler);
...
pdfdoc.Save(...);
pdfdoc.Close();

We need to take an existing pdf file and mark it up
and merge it into the dynamically created pdf file.

You can split and merge PDF pages and documents as illustrated in
PDFPage sample project:
  http://www.pdftron.com/net/samplecode.html#PDFPage.

For more information, you may also want to consult the following
resources:
  http://www.pdftron.com/net/usermanual.html#page_manip
  http://www.pdftron.com/net/faq.html#merge_01
  http://www.pdftron.com/net/faq.html#content_merge_00
  http://www.pdftron.com/net/faq.html#how_watermark

Can you add images to the dynamic pdf file.

Using PDFNet you can add images to dynamic or existing PDF documents.
As a starting point you may want to take a look at AddImage
(www.pdftron.com/net/samplecode.html#AddImage) and ElementBuilder
sample projects.