Write some text on top of an existing PDF

The PDF Creator .NET Library enables you to create secure PDF documents on the fly and to view, print and process existing PDF documents. If you have any questions about PDF Creator .Net, please post them here.
Post Reply
lp
Posts: 66
Joined: Mon Dec 12 2005
Location: Italy

Write some text on top of an existing PDF

Post by lp »

Hi

I'm using PDF Creator .NET 4.0.1.1 and trying to open an existing PDF (think of it as a "model"), write some text over it at given places and finally save it back to PDF with a given name.

I don't get errors, all seems to work, but what I wrote appears "behind" the existing elements.

The "source" file is a PDF1.5 and appears not to be encrypted.
I've also tried to print it through a PDF driver so to get a PDF1.4, but I get to the same unhappy ending.

What am I missing?
Is there something I can try to get around this strange issue?
Is there a way to set some kind of "z-index" (like you could do in CSS, for instance) for my newly inserted text elements?

Thanks in advance for the help!
Luca

PS: what I did, in short:

Code: Select all

acPDFCreatorLib.Initialize ();
acPDFCreatorLib.SetLicenseKey("name","0123....789");
IacDocument document = new IacDocument(null);

FileStream file1 = new System.IO.FileStream(....);
document.Open(file1, "");
document.ReportState = IacReportState.acReportStateDesign;

IacPage page = document.GetPage(2);
using (IacObject frame = page.CreateObject(IacObjectType.acObjectTypeText, "Partita IVA"))
{
frame.AttributeByName("Text").Value = "sample text";
frame.AttributeByName("Left").Value = 500;
frame.AttributeByName("Top").Value = 500;
frame.AttributeByName("Right").Value = 2200;
frame.AttributeByName("Bottom").Value = 600;
}

using (FileStream file2 = new FileStream(...))
{
file2.Close();
}
acPDFCreatorLib.Terminate ();
Last edited by lp on Thu Nov 11 2010, edited 1 time in total.
lp
Posts: 66
Joined: Mon Dec 12 2005
Location: Italy

Re: Write some text on top of an existing PDF

Post by lp »

Well..
I found by accident that
[*] turning TemplateMode on
[*] loading the document
[*] turning it off after it
does the trick and lets me write the text the way I need :)

for instance:

Code: Select all

[...]
document.TemplateMode = true;
document.Open(filestream, "");
document.TemplateMode = false;
[...]
Is it correct?
Thank you!
Post Reply