Frequently Asked Question
How to merge two PDFs? (Windows)
Last Updated a year ago
The following example, shows how to merge the src.pdf to the end of dst.pdf:
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile srcFile = await localFolder.GetFileAsync("src.pdf"); StorageFile dstFile = await localFolder.GetFileAsync("dst.pdf");
IRandomAccessStream stream1 = await srcFile.OpenAsync(FileAccessMode.ReadWrite);
IRandomAccessStream stream2 = await dstFile.OpenAsync(FileAccessMode.ReadWrite); if (stream1 != null && stream2 != null) { PDFDoc docSrc = new PDFDoc();
PDFDoc docDst = new PDFDoc(); docSrc.Open(stream1, "");
docDst.Open(stream2, "");
docDst.SetCahce(localFolder.Path + "/cache.dat"); PDFImportCtx ctx = docDst.ImportStart(docSrc);
int dstno = docDst.PageCount;
int srccnt = docSrc.PageCount;
int srcno = 0; while (srcno < srccnt) {
docDst.ImportPage(ctx, srcno, dstno); dstno++;
srcno++; }
docSrc.Close(); docDst.Save();
docDst.Close(); }