コード例 #1
0
ファイル: PDFSplitForm.cs プロジェクト: lutz/PDFSplitAddon
        void BtnOk_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (var wrapper in lbReferences.CheckedItems.Cast <ReferenceWrapper>())
                {
                    var tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetRandomFileName() + ".pdf");

                    var minPage = Math.Min(wrapper.StartPage, wrapper.EndPage);
                    var maxPage = Math.Max(wrapper.StartPage, wrapper.EndPage);

                    using (var newDoc = new pdftron.PDF.PDFDoc())
                    {
                        using (var sdfDoc = newDoc.GetSDFDoc())
                        {
                            newDoc.InsertPages(0, _document, minPage, maxPage, pdftron.PDF.PDFDoc.InsertFlag.e_insert_bookmark);

                            var index = minPage - 1;

                            for (int i = minPage; i <= maxPage; i++)
                            {
                                var pos = i - index;

                                var currentLabel = _document.GetPageLabel(i);

                                if (!currentLabel.IsValid())
                                {
                                    continue;
                                }

                                var newPageLabel = pdftron.PDF.PageLabel.Create(sdfDoc, currentLabel.GetStyle(), currentLabel.GetPrefix(), i);

                                newDoc.SetPageLabel(pos, newPageLabel);
                            }
                        }

                        newDoc.Save(tempPath, pdftron.SDF.SDFDoc.SaveOptions.e_linearized);
                    }

                    var proposeLocalFilePath = wrapper.Reference.ProposeLocalFilePath(tempPath);
                    System.IO.File.Move(tempPath, proposeLocalFilePath);

                    wrapper.Reference.Locations.Add(LocationType.ElectronicAddress, proposeLocalFilePath);
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(this, exp.ToString(), Properties.Resources.MessageBox_Title_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DialogResult = DialogResult.OK;
        }
コード例 #2
0
        public IActionResult Read()
        {
            try
            {
                bool xfaChecked  = false;
                bool containsXFA = false;

                //string filePath = Path.Combine(_environment.ContentRootPath, "acrobat_pdfl_api_reference.pdf");
                string filePath       = Path.Combine(_environment.ContentRootPath, "bookmark_remote.pdf");
                string linearFilePath = Path.Combine(_environment.ContentRootPath, "linearDocument", "bookmark_remote.pdf");

                if (!System.IO.File.Exists(linearFilePath))
                {
                    var dir = System.IO.Path.GetDirectoryName(linearFilePath);
                    System.IO.Directory.CreateDirectory(dir);

                    using (pdftron.PDF.PDFDoc doc = new pdftron.PDF.PDFDoc(filePath))
                    {
                        doc.InitSecurityHandler();
                        pdftron.SDF.SDFDoc.SaveOptions saveOptions = 0;

                        Obj acro_form = doc.GetAcroForm();
                        if (acro_form != null)
                        {
                            var xfaForm = acro_form.FindObj("XFA");
                            xfaChecked  = true;
                            containsXFA = (xfaForm != null);
                        }

                        // Linearize the pdf document to support for incremental download.
                        if (!doc.IsLinearized())
                        {
                            saveOptions = pdftron.SDF.SDFDoc.SaveOptions.e_linearized;
                        }
                        else
                        {
                            saveOptions = pdftron.SDF.SDFDoc.SaveOptions.e_incremental;
                        }

                        doc.Save(linearFilePath, saveOptions);
                    }
                }

                return(PhysicalFile(linearFilePath, "application/octet-stream", true));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex));
            }
        }