Exemplo n.º 1
0
        private void PDFExportPage(string basedName, Data.ONPage page)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }

            string fileName = Path.Combine(basedName, page.ID);

            fileName        += ".pdf";
            page.PDFFilePath = fileName;

            if (File.Exists(fileName))
            {
                if (File.GetCreationTime(fileName) == page.LastModifiedTime)
                {
                    // this page is not modified since last update
                    return;
                }
                else
                {
                    // delete existing file
                    File.Delete(fileName);
                }
            }
            Log.Verbose(string.Format("Exporting page [{0}] to PDF", page.Name));
            OneNoteApplication.Publish(page.ID, fileName, OneNote.PublishFormat.pfPDF, string.Empty);
            File.SetCreationTime(fileName, page.LastModifiedTime);
            File.SetLastWriteTime(fileName, page.LastModifiedTime);
        }
Exemplo n.º 2
0
        private void PDFCombinePage(PdfOutline parent,
                                    Data.ONPage page)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }

            PdfReader reader = new PdfReader(page.PDFFilePath);

            Log.Information(string.Format("Import file {0}", page.PDFFilePath));

            // we retrieve the total number of pages

            int             n  = reader.NumberOfPages;
            PdfContentByte  cb = pdfWriter.DirectContent;
            PdfImportedPage impportPage;
            int             rotation;
            int             i = 0;

            while (i < n)
            {
                i++;
                pdfDocument.SetPageSize(reader.GetPageSizeWithRotation(i));
                pdfDocument.NewPage();
                impportPage = pdfWriter.GetImportedPage(reader, i);
                rotation    = reader.GetPageRotation(i);
                if (rotation == 90 || rotation == 270)
                {
                    cb.AddTemplate(impportPage, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
                }
                else
                {
                    cb.AddTemplate(impportPage, 1f, 0, 0, 1f, 0, 0);
                }
                if (i == 1)
                {
                    // set outline action at first page
                    PdfAction  action   = PdfAction.GotoLocalPage(pdfWriter.CurrentPageNumber, new PdfDestination(PdfDestination.FITH, 806), pdfWriter);
                    PdfOutline gotoPage = new PdfOutline(parent, action, page.Name);
                    //TODO: fix this // pdfWriter.DirectContent.AddOutline(gotoPage,gotoPage.Title);
                }
            }
            pdfWriter.FreeReader(reader);
        }