你将如何以编程方式在PDF中嵌入SWF? [英] How would you programmatically embed a SWF in a PDF?

查看:122
本文介绍了你将如何以编程方式在PDF中嵌入SWF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以以编程方式将SWF嵌入到来自C#应用程序的PDF中?

可以使用c#端口的iText库。它叫做iTextSharp。



http://itextsharp.com/



一个例子,代码可能是这样的:

  //创建一个输出文件流,用来捕获生成的文件
string outputFileName =output.pdf;
FileStream outputFile = new FileStream(outputFileName,FileMode.Create);

//将原始PDF文件作为PdfReader
打开PdfReader reader = new PdfReader(inputfile.pdf);

//以pdf格式打开输出pdf文件
PdfStamper stamper = new PdfStamper(reader,outputFile);

//在文档开始处插入一个空白页面
stamper.InsertPage(1,PageSize.A4);

//将flash文件作为注释添加到输出文档中
PdfFileSpecification fs = PdfFileSpecification.FileEmbedded(stamper.Writer,flashFileTextBox.Text,flashFileTextBox.Text,null);
PdfAnnotation flashInsert = PdfAnnotation.CreateScreen(stamper.Writer,new Rectangle(50f,791f,545f,420f),Flash Insert,fs,application / x-shockwave-flash,true);

stamper.AddAnnotation(flashInsert,1);

stamper.Close();
reader.Close();


Is it possible to programmatically embed a SWF in a PDF from a C# application?

解决方案

You can use the c# port of the iText library. It's called iTextSharp.

http://itextsharp.com/

An example of what the code could look like:

 // create an output file stream which will be used to capture the generated file 
    string outputFileName = "output.pdf"; 
    FileStream outputFile = new FileStream(outputFileName, FileMode.Create); 

    // open the original pdf file as a PdfReader 
    PdfReader reader = new PdfReader("inputfile.pdf"); 

    // open the output pdf file as a PdfStamper 
    PdfStamper stamper = new PdfStamper(reader, outputFile); 

    // inserts a blank page at the start of the document 
    stamper.InsertPage(1, PageSize.A4); 

    // add the flash file to the output document as an annotation 
    PdfFileSpecification fs = PdfFileSpecification.FileEmbedded(stamper.Writer, flashFileTextBox.Text, flashFileTextBox.Text, null); 
    PdfAnnotation flashInsert = PdfAnnotation.CreateScreen(stamper.Writer, new Rectangle(50f,791f,545f,420f),"Flash Insert",fs, "application/x-shockwave-flash", true); 

    stamper.AddAnnotation(flashInsert,1); 

    stamper.Close(); 
    reader.Close(); 

这篇关于你将如何以编程方式在PDF中嵌入SWF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆