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

Notification

Icon
Error

Post a reply
From:
Message:

Maximum number of characters in each post is: 32767
Bold Italic Underline   Highlight Quote Choose Language for Syntax Highlighting Insert Image Insert an existing Attachment or upload a new File... Create Link   Unordered List Ordered List   Left Justify Center Justify Right Justify   Outdent Indent   More BBCode Tags
Font Color Font Size
Security Image:
Enter The Letters From The Security Image:
  Preview Post Cancel

Last 10 Posts (In reverse order)
cjansen Posted: Tuesday, August 21, 2018 8:40:39 AM(UTC)
 
Alrighty then.

Just wanted to make sure I wasn't off the proverbial rocker.

Thank you.
Paul Rayman Posted: Tuesday, August 21, 2018 8:26:36 AM(UTC)
 
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-problem
cjansen Posted: Tuesday, August 21, 2018 8:17:30 AM(UTC)
 
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?