Мне нужно объединить PDF-файлы с ItextSharp. Просто поищите в Google и получите приведенное ниже решение, но оно все равно не работает с альбомными документами. Файлы ландшафта потеряют право на страницу.
using System.Collections.Generic;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
static void Main (string[] args) {
string outputFilePath = @"D:\csharp\final.pdf";
string[] inputFilePaths = { @"D:\csharp\1.pdf", @"D:\csharp\2.pdf"};
MergePDFs(outputFilePath, inputFilePaths);
}
static void MergePDFs (string outPutFilePath, params string[] filesPath) {
List<PdfReader> readerList = new List<PdfReader> ();
foreach (string filePath in filesPath) {
PdfReader pdfReader = new PdfReader (filePath);
readerList.Add (pdfReader);
}
//Define a new output document and its size, type
Document document = new Document (PageSize.A4, 0, 0, 0, 0);
//Create blank output pdf file and get the stream to write on it.
PdfWriter writer = PdfWriter.GetInstance (document, new FileStream (outPutFilePath, FileMode.Create));
document.Open ();
foreach (PdfReader reader in readerList) {
for (int i = 1; i <= reader.NumberOfPages; i++) {
PdfImportedPage page = writer.GetImportedPage (reader, i);
document.Add (iTextSharp.text.Image.GetInstance (page));
}
}
document.Close ();
}