asp.net - C# iTextSharp PdfCopy to MemoryStream 复制整个文档和单页
问题描述
我正在尝试使用内存流从 3 页 PDF 文档制作一页 PDF。但是当下面的代码执行时,所有 3 页都会被添加,而不仅仅是第一页。
我在这里想念什么?请帮忙。注意:我使用的是 iTextSharp v5.5.13
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
MemoryStream ms = new MemoryStream();
byte[] fileToBeEncrypted = null;
string sSourcePDF = "C:\\my3pageFile.pdf;
PdfReader pdfReader = new PdfReader(sSourcePDF);
Document document = new Document();
PdfCopy copy = new PdfCopy(document, ms) {CloseStream = false};
document.Open();
copy.AddPage(copy.GetImportedPage(pdfReader, iPage));
document.Close();
fileToBeEncrypted = ms.ToArray(); //returns the ENTIRE DOCUMENT AND NOT JUST PAGE 1
任何人都可以帮忙吗?
谢谢
汤姆
解决方案
上面的代码 pdfCopy.GetImportedPages 确实有效,我在自己的代码中发现了一个错误。
推荐阅读
- javascript - 无法在 javascript 上传递变量,它传递的是 html 元素而不是引用的变量?
- node.js - 如何从 GetStream 以下 API 获取关注用户的详细信息
- html - 从映射驱动器添加 img src
- android - 如何让我的 android 手机始终处于显示状态,以便随时查看我的巴士应用时间?
- mongodb - 匹配最接近搜索值的文档键
- r - 如何将文本添加到germ-rect和ggplotly?
- javascript - 无限循环保护
- c# - 在 SQL 语句中使用 ComboBox 选择
- javascript - 通过类名的一部分查找类
- python - 如何在 SocketCAN 或 Python-can 中发送和接收文件?