gpt4 book ai didi

ios - 使用Podofo更新PDF中的小部件

转载 作者:行者123 更新时间:2023-12-01 19:10:31 32 4
gpt4 key购买 nike

我正在使用PdfAnnotation.SetContents设置注释的值。如果注释的类型为FreeText,则只有此方法可以正常工作,并且该值会显示在PDF上(使用PDF Reader)。如果类型是Widget,则该值被设置为pdf词典中的内容但未显示。是否可以设置小部件的值?

最佳答案

我找到了解决方案,为了显示内容,必须设置外观(“AP”)词典。

这可以用于:

void PdfField::CreateFieldAppearance(PdfMemDocument *memDoc, const PdfString &value)
{
if( !m_pWidget->HasAppearanceStream() )
{
PdfRect pageRect;
PdfPainter painter;

PoDoFo::PdfRect rect = this->GetWidgetAnnotation()->GetRect();
unsigned int width = rect.GetWidth();
unsigned int height = rect.GetHeight();

PdfRect pdfRect(0, 0, width, height);

PdfXObject xObj(pdfRect, memDoc);
painter.SetPage(&xObj);
painter.SetClipRect(pdfRect);

painter.Save();
painter.SetColor(221.0/255.0, 228.0/255.0, 1.0);

painter.FillRect(0, 0, width, height);
painter.Restore();

// make rotation

painter.Save();

/***********************************************************************************/

// Rotation Logic

double angle = this->GetPage()->GetRotation();

if (angle) {
double radAngle = angle * M_PI / 180;

int cosA = (int)cos(radAngle);
int sinA = (int)sin(radAngle);

double translateY = rect.GetWidth(); // The View goes out of the bound, sits on top
painter.SetTransformationMatrix(cosA, sinA, -sinA, cosA, translateY, 0);
}
/***********************************************************************************/


PdfFont *font = memDoc->CreateFont("Helvetica", true, false);
font->SetFontSize(15);

// Do the drawing
painter.SetFont(font);
painter.BeginText(10, 5);
painter.SetStrokeWidth(20);
painter.AddText(value);
painter.EndText();

painter.FinishPage();

// This is very important. Not only does it disable the editing.
// Also it does correct the appearance issue on Adobe Readers.
this->SetReadOnly(true);

// The Stream Object has to be saved to the annotation
PoDoFo::PdfDictionary dict;
dict.AddKey( "N", xObj.GetObject()->Reference() );
this->GetFieldObject()->GetDictionary().AddKey( "AP", dict );
}

}

关于ios - 使用Podofo更新PDF中的小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16843057/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com