Rank: Advanced Member
Groups: Registered
Joined: 4/30/2019(UTC) Posts: 48   Location: Raisio Thanks: 11 times Was thanked: 3 time(s) in 2 post(s)
|
Moved from this thread https://forum.patagames....ateContent-is-SLOW/page2Thank 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? Edited by moderator Thursday, February 4, 2021 5:50:59 PM(UTC)
| Reason: Moved from other thread
|
|
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,138
Thanks: 10 times Was thanked: 133 time(s) in 130 post(s)
|
Most likely it is possible. For this you need to use this method. https://pdfium.patagames...PDFOBJ_SetIsModified.htmThe 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.
|
|
|
|
|
|
Rank: Advanced Member
Groups: Registered
Joined: 4/30/2019(UTC) Posts: 48   Location: Raisio Thanks: 11 times Was thanked: 3 time(s) in 2 post(s)
|
Originally Posted by: Paul Rayman  Most likely it is possible. For this you need to use this method. https://pdfium.patagames...PDFOBJ_SetIsModified.htmThe 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!!!
|
|
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,138
Thanks: 10 times Was thanked: 133 time(s) in 130 post(s)
|
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);
}
}
|
 1 user thanked Paul Rayman for this useful post.
|
|
|
|
Rank: Advanced Member
Groups: Registered
Joined: 4/30/2019(UTC) Posts: 48   Location: Raisio Thanks: 11 times Was thanked: 3 time(s) in 2 post(s)
|
Originally Posted by: Paul Rayman  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!
|
|
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,138
Thanks: 10 times Was thanked: 133 time(s) in 130 post(s)
|
|
|
|
|
|
|
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