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)
Paul Rayman Posted: Thursday, February 4, 2021 11:49:41 PM(UTC)
 
Thanks a lot.

By the way, the fix has already been published.
https://forum.patagames....on-Feb-05--2021#post2149
rhnatiuk Posted: Thursday, February 4, 2021 11:37:21 PM(UTC)
 
Originally Posted by: Paul Rayman Go to Quoted Post
Well, I think it is an architectural oversight that newly created fonts are not marked as modified. I think this will be fixed in future releases. I've already passed this issue over to the core development team.
Currently, you can use the following workaround.


OMG, Paul, you are GENIUS!!! :D It works!
Paul Rayman Posted: Thursday, February 4, 2021 5:40:42 PM(UTC)
 
Well, I think it is an architectural oversight that newly created fonts are not marked as modified. I think this will be fixed in future releases. I've already passed this issue over to the core development team.
Currently, you can use the following workaround.

Code:

using (var doc = PdfDocument.Load(@"e:\11\test.pdf"))
{
    var font = PdfFont.CreateEmbeddedFont(doc, fontData, FontCharSet.UNICODE_CHARSET, false);
    SetAsModifiedRecursively(font.Dictionary);

    doc.Pages[0].PageObjects.Add(PdfTextObject.Create("Test string", 50, 50, font, 15));
    doc.Pages[0].GenerateContent();
    doc.Save(@"e:\11\test_incremental.pdf", SaveFlags.Incremental);
}


Code:

private static void SetAsModifiedRecursively(PdfTypeDictionary dictionary)
{
    Pdfium.FPDFOBJ_SetIsModified(dictionary.Handle, true);
    foreach(var item in dictionary.Values)
    {
        if (item.Is<PdfTypeDictionary>())
            SetAsModifiedRecursively(item.As<PdfTypeDictionary>());
        else if(item.Is<PdfTypeArray>())
            SetAsModifiedRecursively(item.As<PdfTypeArray>());
        else
            Pdfium.FPDFOBJ_SetIsModified(Pdfium.FPDFOBJ_GetDirect(item.Handle), true);
    }
}
private static void SetAsModifiedRecursively(PdfTypeArray array)
{
    Pdfium.FPDFOBJ_SetIsModified(array.Handle, true);
    foreach (var item in array)
    {
        if (item.Is<PdfTypeDictionary>())
            SetAsModifiedRecursively(item.As<PdfTypeDictionary>());
        else if (item.Is<PdfTypeArray>())
            SetAsModifiedRecursively(item.As<PdfTypeArray>());
        else
            Pdfium.FPDFOBJ_SetIsModified(Pdfium.FPDFOBJ_GetDirect(item.Handle), true);
    }
}
rhnatiuk Posted: Thursday, February 4, 2021 6:24:07 AM(UTC)
 
Originally Posted by: Paul Rayman Go to Quoted Post
Most likely it is possible. For this you need to use this method.
https://pdfium.patagames...PDFOBJ_SetIsModified.htm

The question is which object to pass there as a parameter. Most likely it should be page’s resource dictionary.
With an incremental save, only the changed objects are saved. If the object for some reason is not marked as changed, then this can be done by the above function.


Well, using Pdfium.FPDFOBJ_SetIsModified(pdfPage.Dictionary.Handle, true) didn't help. But isn't embedded font stored somewhere on the document level? I have no idea, to be honest, how to make it work. I appreciate your help a lot!!!
Paul Rayman Posted: Thursday, February 4, 2021 5:55:45 AM(UTC)
 
Most likely it is possible. For this you need to use this method.
https://pdfium.patagames...PDFOBJ_SetIsModified.htm

The question is which object to pass there as a parameter. Most likely it should be page’s resource dictionary.
With an incremental save, only the changed objects are saved. If the object for some reason is not marked as changed, then this can be done by the above function.
rhnatiuk Posted: Thursday, February 4, 2021 5:21:33 AM(UTC)
 
Moved from this thread
https://forum.patagames....ateContent-is-SLOW/page2


Thank you for your effort!

It seems I might be able to overcome the limitations of the two above-mentioned methods (objects to stream, and annotations to page) by combining them. I might be able to do it because of the nature of our needs: we have to annotate existing texts, so these will be normal annotations, and then we have to add new texts, but only outside of the current page's content, so I can insert their stream to position 0 and avoid the problem of unbalanced matrices.

But, there is one last remaining problem. I need to add Unicode texts, and because of that, I need to embed a Unicode font into the document. I am doing it like this:

Code:
var pdfFont = PdfFont.CreateEmbeddedFont(this.pdfDocument, fontBytes, FontCharSet.UNICODE_CHARSET, false);
var pdfTextObject = PdfTextObject.Create(text, x, y, pdfFont, size);


Now, if I do

Code:
pdfDocument.Save(filename, SaveFlags.Incremental)


the saving is fast, the embedded font is gone. So, I need to do

Code:
pdfDocument.Save(filename, SaveFlags.NoIncremental)


which is saving the font, but is very slow.

Is there some trick to get embedded fonts working with the Incremental flag?