Welcome Guest Search | Active Topics | Sign In | Register

EO.PDF Modify an existing PDF Document Options
markw
Posted: Monday, May 30, 2016 5:41:44 PM
Rank: Member
Groups: Member

Joined: 11/12/2007
Posts: 27
Hi,
I hope you can help:-

I need to add some text at the top of page 1 in an existing PDF Document sort of a watermark text line - I have managed todo this with the code below. The problem is I need to be able to update the text when the customer wants in the future - so be able to remove the old text before adding some different text?

Thank you
Mark

Dim texthtml As String = "<div style=""text-align: Right; padding-top: 6px; letter-spacing: 5px;\""><span style=\""padding-right: 60px;\"">" & TEXT TEXT & "</span></div>"
'Set options to control where the text gets placed
Dim options2 As EO.Pdf.HtmlToPdfOptions = New EO.Pdf.HtmlToPdfOptions()
options2.FooterHtmlPosition = 10.0F
options2.FooterHtmlFormat = texthtml
options2.ZoomLevel = 0.85F
options2.OutputArea = New RectangleF(1.0F, 1.0F, 6.5F, 9.0F)
EO.Pdf.HtmlToPdf.ConvertHtml(texthtml, eo1.Pages(0), options2)
eo_support
Posted: Tuesday, May 31, 2016 10:33:35 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

You won't be able to remove the text once you put it in. The only way you can do this is to keep a copy of the original "template" document so that you can re-add something different every time.

Thanks!
markw
Posted: Tuesday, May 31, 2016 10:37:06 AM
Rank: Member
Groups: Member

Joined: 11/12/2007
Posts: 27
Okay :(

Is it possible maybe to add a form text field with the text in therefore be able to locate the field id and just update the form field when a text change is needed?
Is it possible to add a form field to an existing document.

Regards
Mark
eo_support
Posted: Tuesday, May 31, 2016 11:01:34 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

Yes. You can do that. You can check the sample code in Demos/Acm/Interactive Features/FillInForm in the EOPdfDemo sample project for more details.

Thanks
markw
Posted: Tuesday, May 31, 2016 3:09:54 PM
Rank: Member
Groups: Member

Joined: 11/12/2007
Posts: 27
Sounds possible then - but can I add the text form field with eo.pdf if it doesn't exist already in the pdf?
eo_support
Posted: Tuesday, May 31, 2016 3:57:05 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Yes. You can do it. You would just load the existing PDF file into a PdfDocument object and then pass that to the AcmRender.
markw
Posted: Tuesday, May 31, 2016 4:43:41 PM
Rank: Member
Groups: Member

Joined: 11/12/2007
Posts: 27
good.... don't mean to be a pain but I cannot find an example on how to add a form field to an existing document - I can see the example to fill a form field in can you help?

Thank you
Mark
eo_support
Posted: Tuesday, May 31, 2016 4:48:54 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

The sample in the sample project mentioned above has the following code:

Code: C#
PdfDocument doc = new PdfDocument();

//Create a new AcmRender object
AcmRender render = new AcmRender(doc);


You just need to change it to:

Code: C#
PdfDocument doc = new PdfDocument(your_existing_pdf_file_name);

//Create a new AcmRender object
AcmRender render = new AcmRender(doc);


Note that you would pass your existing PDF file name to the PdfDocument's constructor. Without this it would be blank new PdfDocument. This is the only difference between generating a form into a blank new document or adding it to an existing PDF file.

You may also want to set the field's ReadOnly to true since otherwise user will be able to edit it.

Thanks!
markw
Posted: Tuesday, May 31, 2016 5:32:25 PM
Rank: Member
Groups: Member

Joined: 11/12/2007
Posts: 27
Yes but after checking that a text form field does not exist already how would I add a new one inside the pdf document the first time instead of changing the text when it has been already added?

Thank you
eo_support
Posted: Tuesday, May 31, 2016 5:38:30 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Can you read the sample source code in the sample project first? That sample (Demos/Acm/Interactive Features/FillInForm) creates a number of form fields with a blank new PDF document. No where in that sample has anything to do with changing the text of an existing field.
markw
Posted: Tuesday, May 31, 2016 6:28:25 PM
Rank: Member
Groups: Member

Joined: 11/12/2007
Posts: 27
Ahh ok sorry I will do tomorrow I didn't realise it created the form fields. I will let you know outcome

much appreciated!
markw
Posted: Wednesday, June 1, 2016 10:46:49 AM
Rank: Member
Groups: Member

Joined: 11/12/2007
Posts: 27
Hi,
First off thank you for your help so far working really well and nearly complete - last issue setting the field to readonly does not work seems am I still able to type text into it snippet below I am using:
I have updated to the latest build .98 incase that was it.

'Process the PDF File
Try
Dim eo1 As New EO.Pdf.PdfDocument(ffile)
Dim ffield As EO.Pdf.PdfTextField = eo1.Fields("GKNWM")
If IsNothing(ffield) Then
Dim render As New EO.Pdf.Acm.AcmRender(eo1)
Dim root As New EO.Pdf.Acm.AcmContent

Dim tbFirstName As New EO.Pdf.Acm.AcmTextBox()
If RadioButton2.Checked Then tbFirstName.Style.ForegroundColor = Color.Red

tbFirstName.Style.Left = 0
tbFirstName.Style.Top = 0
tbFirstName.Style.Width = 7.0F
tbFirstName.Style.Height = 0.3F
tbFirstName.Style.Padding.Left = 0.1F
tbFirstName.Style.OffsetY = -1.0F
tbFirstName.Style.OffsetX = -1.0F
tbFirstName.Name = "GKNWM"
tbFirstName.Text = pdfText
tbFirstName.Style.FontName = "Arial"
tbFirstName.Style.FontSize = 10
root.Children.Add(tbFirstName)
render.Render(root)
ffield = eo1.Fields("GKNWM")
Else
ffield.Value = pdfText
ffield.Color = Color.Black
If RadioButton2.Checked Then ffield.Color = Color.Red
End If

ffield.ReadOnly = True

eo1.Save(ffile)
eo1 = Nothing
Catch ex As Exception
'Error Processing PDF File
End Try
eo_support
Posted: Wednesday, June 1, 2016 5:31:31 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

We tested this here and it seems to work fine. Can you send a test project to us so that we can try your code/file? See here for more details on how to send test project to us:

http://www.essentialobjects.com/forum/test_project.aspx

Thanks!
markw
Posted: Wednesday, June 1, 2016 5:47:25 PM
Rank: Member
Groups: Member

Joined: 11/12/2007
Posts: 27
TYPICAL - problem solved

I selected a pdf file that had javascript embedded to loop all textbox controls and set them read only or not depending on a status field value!!!

You support on this issue has been excellent - thank you for such fast response and informative replies - I can release the damn thing and move on to other bugs :)

Regards
Mark W
eo_support
Posted: Thursday, June 2, 2016 9:28:26 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Great. Glad to hear that you got it working! Please feel free to let us know if there is anything else.
markw
Posted: Friday, June 3, 2016 8:53:15 AM
Rank: Member
Groups: Member

Joined: 11/12/2007
Posts: 27
Hello,
Client has come back with a requirement that raises 2 more questions please:-

1. is there a way to remove an existing Text Form Field?
2. How do I specify which page to write a form field to when rendering?

Thank again
Mark
eo_support
Posted: Friday, June 3, 2016 8:57:56 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

To remove a form field, you just call Remove on the Fields collection.

To specify the page to write the form field, pass the page (instead of the document) to AcmRender.

Thanks!
markw
Posted: Friday, June 3, 2016 9:12:15 AM
Rank: Member
Groups: Member

Joined: 11/12/2007
Posts: 27
Brilliant! Thank you

Quick question where the text needs to be the same on all pages of the pdf - Watermark text is it viable to add a form field on each page the same name or should they all be unique?

Thank you
eo_support
Posted: Monday, June 6, 2016 3:05:54 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

You should use an unique name for each field.

Thanks
markw
Posted: Wednesday, June 8, 2016 5:45:15 AM
Rank: Member
Groups: Member

Joined: 11/12/2007
Posts: 27
Thank you I have now made the field names unique on all pages. So close now but I have one new issue

is there a way to find out which page a acmtext field is on - I need to remove and update a field on a specific page only for the client but cannot seem to find a value to find out which page a form field is on to identify the correct field to remove?


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.