|
|
|
|
|
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!
|
|
|
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);
}
}
|
|
|
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!!!
|
|
|
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.
|
|
|
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?
|