使用itextsharp和c#在pdf模板中设置PDF文本字段RunDirection

时间:2017-11-27 10:58:09

标签: c# pdf itext

我正在尝试使用C#将PDF文本字段上的RunDirection设置为RTL,但我没有找到如何操作。 相反,我试图将RunDirection设置为整个页面,但我的代码不起作用。我到目前为止尝试的代码在这里:

public static string GeneratePDF(string pdfTemplatePath, string pdfOutPutFile, Dictionary<string, object> formFieldMap, string fullPathSignature, Stopwatch stopWatch)
    {
        PdfReader reader = null;
        FileStream output = null;
        PdfStamper stamper = null;
        AcroFields formFields = null;

        try
        {
            reader = new PdfReader(pdfTemplatePath);
            output = new FileStream(pdfOutPutFile, FileMode.Create);

            stamper = new PdfStamper(reader, output);
            stamper.Writer.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
            formFields = stamper.AcroFields;

            // Set Field value by Fields mapping
            foreach (var fieldName in formFieldMap.Keys)
            {
                formFields.SetField(fieldName, formFieldMap[fieldName].ToString());
            }

        }
        catch (Exception ex)
        {
        }

        stamper.FormFlattening = true;
        stamper.Close();
        reader.Close();
        output.Close();

        return pdfOutPutFile;
    }

0 个答案:

没有答案