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
cjansen  
#1 Posted : Tuesday, August 21, 2018 8:17:30 AM(UTC)
Quote
cjansen

Rank: Newbie

Groups: Registered
Joined: 7/25/2018(UTC)
Posts: 7
Canada
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?
Paul Rayman  
#2 Posted : Tuesday, August 21, 2018 8:26:36 AM(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)
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

Edited by user Tuesday, August 21, 2018 10:57:53 PM(UTC)  | Reason: Not specified

thanks 1 user thanked Paul Rayman for this useful post.
cjansen on 8/21/2018(UTC)
cjansen  
#3 Posted : Tuesday, August 21, 2018 8:40:39 AM(UTC)
Quote
cjansen

Rank: Newbie

Groups: Registered
Joined: 7/25/2018(UTC)
Posts: 7
Canada
Location: Sherwood Park, Alberta

Thanks: 1 times
Alrighty then.

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

Thank you.
Quick Reply Show Quick Reply
Users browsing this topic
Guest
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.