Rank: Member
Groups: Registered
Joined: 4/15/2018(UTC) Posts: 24   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?
|
|
|
|
|
|
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.htmOverloading 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.htmMy assumption is that the problem might be here.
|
|
|
|
|
|
Rank: Member
Groups: Registered
Joined: 4/15/2018(UTC) Posts: 24   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);
}
}
}
|
|
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,138
Thanks: 10 times Was thanked: 133 time(s) in 130 post(s)
|
|
|
|
|
|
|
Rank: Member
Groups: Registered
Joined: 4/15/2018(UTC) Posts: 24   Location: Sydney Thanks: 2 times
|
|
|
|
|
|
|
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?
|
|
|
|
|
|
Rank: Member
Groups: Registered
Joined: 4/15/2018(UTC) Posts: 24   Location: Sydney Thanks: 2 times
|
We are using the WPF viewer. Thanks.
|
|
|
|
|
|
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
|
|
|
|
|
|
Rank: Member
Groups: Registered
Joined: 4/15/2018(UTC) Posts: 24   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!
|
|
|
|
|
|
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.
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close