logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
matt.smokeball  
#1 Posted : Tuesday, May 1, 2018 6:28:16 PM(UTC)
Quote
matt.smokeball

Rank: Member

Groups: Registered
Joined: 4/15/2018(UTC)
Posts: 24
Man
Australia
Location: Sydney

Thanks: 2 times
Hi

I'm currently using the Trial version of the software. Everything so far has been very good.

Just having some small issues. We need to save the pdf documents, including any field mappings/values.

I'm using the viewer to display the documents. however, when I call document.Save(), it doesn't seem to be saving the file at all. I have to call document.Save(new temp file path) to get it to work.

Also, it never saves the field values into the document. The mappings save in the document, but not the values.

Hoping this is possible and I'm not doing it correctly?
Paul Rayman  
#2 Posted : Tuesday, May 1, 2018 7:27:43 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Hi,

Quote:

I'm using the viewer to display the documents. however, when I call document.Save(), it doesn't seem to be saving the file at all. I have to call document.Save(new temp file path) to get it to work.


Pdfium does not load the entire contents of the document into memory, but reads the necessary portion of data from the file as needed. For this reason, a write lock is set on the file. Thus, there are only the methods to saving a copy of the documents, but not saving the document to the same file.
All overloads of the Save method saves the copies of the document in a different location.
https://pdfium.patagames...92-4c9c-3fb58a2dd2e6.htm

Overloading without specifying where to store the copy can be used to save the document in any different from the standard way. Calling the Save function without specifying the path, the engine fires the WriteBlock event. You can hadle it and implement your own save to whatever destination you want (to the database for example).

Quote:

Also, it never saves the field values into the document. The mappings save in the document, but not the values.

Could you please clarify that you mean under "mappings" and "values"
Also please do not forget to call ForceToKillFocus before saving
https://pdfium.patagames...40-cf1b-502be7b41983.htm
My assumption is that the problem might be here.

matt.smokeball  
#3 Posted : Tuesday, May 1, 2018 8:10:12 PM(UTC)
Quote
matt.smokeball

Rank: Member

Groups: Registered
Joined: 4/15/2018(UTC)
Posts: 24
Man
Australia
Location: Sydney

Thanks: 2 times
Hi Paul

Thanks for the quick reply! I understand about the save, thanks for clearing that up.

In regards to the mapping/field values, what I need to be able to do is save the value a user enters into the document, with the document. So a text field for example, should save the entered text when the document is saved to the file path.

Currently, it's not doing that when I call the save methods.

I have the code below, which will save a "mapping" to the field. The mapping is just a string value that is used as a way to identify what value to place into the field, from our own databases (essentially trying to automate the form fill).

When calling save, this mapping value is saved into the document ok. However the actual field value is not (i.e: Field.Value = "some string").

Hope this helps to clarify a little. Thanks again!

Code:

 public static class PdfFieldExtensions
    {
        public static void SetMapping(this PdfField field, string mapping)
        {
            var tm = PdfTypeString.Create();
            tm.AnsiString = mapping;

            if (field.Dictionary.ContainsKey("TM"))
            {
                field.Dictionary["TM"] = tm;
            }
            else
            {
                field.Dictionary.Add("TM", tm);
            }
        }
    }
Paul Rayman  
#4 Posted : Tuesday, May 1, 2018 8:20:05 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Are you using latest version?
https://forum.patagames....released-on-Apr-16--2018
Also please make sure you are using NoIncremental flag.
If so, could you please provide the document, where the forms cannot be saved?
matt.smokeball  
#5 Posted : Tuesday, May 1, 2018 8:59:25 PM(UTC)
Quote
matt.smokeball

Rank: Member

Groups: Registered
Joined: 4/15/2018(UTC)
Posts: 24
Man
Australia
Location: Sydney

Thanks: 2 times
Yeah sure. The PDF document I'm testing with is attached. We're using the latest version. Thanks!

Bank of Melbourne Discharge Authority.pdf (110kb) downloaded 25 time(s).
Paul Rayman  
#6 Posted : Tuesday, May 1, 2018 9:16:07 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Are you using WinForms or WPF PDFViewer?
matt.smokeball  
#7 Posted : Tuesday, May 1, 2018 9:17:02 PM(UTC)
Quote
matt.smokeball

Rank: Member

Groups: Registered
Joined: 4/15/2018(UTC)
Posts: 24
Man
Australia
Location: Sydney

Thanks: 2 times
We are using the WPF viewer. Thanks.
Paul Rayman  
#8 Posted : Tuesday, May 1, 2018 9:34:20 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Looks like I did not understand the problem.
Everything looks fine.


if you are using PdfDocument.Load instead of PdfViewer.LoadDocument then you need to do that in the following manner
Code:

public void LoadDocument()
{
    var f = new PdfForms();
    var doc = PdfDocument.Load(@"d:\32\Bank of Melbourne Discharge Authority.pdf", f);
    pdfViewer1.Document = doc;
}

public void SaveDocument()
{
    pdfViewer1.Document.FormFill.ForceToKillFocus();
    pdfViewer1.Document.Save(@"d:\32\Bank of Melbourne Discharge Authority - saved.pdf", SaveFlags.NoIncremental);
}

Edited by user Tuesday, May 1, 2018 9:52:45 PM(UTC)  | Reason: Not specified

matt.smokeball  
#9 Posted : Wednesday, June 13, 2018 3:37:04 PM(UTC)
Quote
matt.smokeball

Rank: Member

Groups: Registered
Joined: 4/15/2018(UTC)
Posts: 24
Man
Australia
Location: Sydney

Thanks: 2 times
Apologies, I forgot to update this post! The issue was that I was not using the NoIncremental flag, and also not calling ForceToKillFocus() before saving. Thanks for you support with this!
Quick Reply Show Quick Reply
Users browsing this topic
Guest (2)
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.