Rank: Newbie
Groups: Registered
Joined: 7/25/2018(UTC) Posts: 7  Location: Sherwood Park, Alberta Thanks: 1 times
|
Code:private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
var location = @"c:\testform.pdf";
pdfViewer1.LoadDocument(location);
var rand = new Random();
foreach (var field in pdfViewer1.Document.FormFill.InterForm.Fields)
{
if (field.FieldType == Patagames.Pdf.Enums.FormFieldTypes.FPDF_FORMFIELD_TEXTFIELD)
{
field.Value = $"This is a magical field: {rand.Next()}";
}
}
// maybe some other modification...
// attach a file perhaps?
pdfViewer1.Document.Save(location, Patagames.Pdf.Enums.SaveFlags.NoIncremental);
}
That little "save the document" line is not a happy camper. complaining about the pdf being used by another process... the viewer, I imagine. So then, how to go about saving user supplied modifications? Does the PdfViewer component have a "save" method?
|
|
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,138
Thanks: 10 times Was thanked: 133 time(s) in 130 post(s)
|
You should save to another file, because the original file is blocked for writing. This is because PdfDocument.Load loads the file when needed, so it cannot be modified unless the original document is closed. Probably you noticed how even a very large PDF document with hundreds thousands of pages loads very fast. This becomes possible because there is not need to parse the entire document body. At first, only the cross-reference table is read and all the rest of data is loaded when needed. This is by design behavior. So you may save to byte array, close original file, next save byte array to the file. https://forum.patagames....-locked-pdf-file-problemEdited by user Tuesday, August 21, 2018 10:57:53 PM(UTC)
| Reason: Not specified
|
 1 user thanked Paul Rayman for this useful post.
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 7/25/2018(UTC) Posts: 7  Location: Sherwood Park, Alberta Thanks: 1 times
|
Alrighty then.
Just wanted to make sure I wasn't off the proverbial rocker.
Thank you.
|
|
|
|
|
|
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