void SetupUserInterface() { mPdfViewCtrl = new pdftron.PDF.PDFViewCtrl(); string path = System.IO.Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "sample.pdf"); pdftron.PDF.PDFDoc doc = new pdftron.PDF.PDFDoc(path); mPdfViewCtrl.SetDoc(doc); mPdfViewCtrl.SetPagePresentationMode(pdftron.PDF.PDFViewCtrlPagePresentationMode.e_single_page); mToolManager = new pdftron.PDF.Tools.ToolManager(mPdfViewCtrl); mToolManager.EnablePopupMenuOnLongPress = true; mToolManager.IsPopupMenuEnabled = true; mToolManager.PanToolTextSelectionMode = pdftron.PDF.Tools.ToolManager.TextSelectionBehaviour.AlwaysPan; mToolManager.TextMarkupAdobeHack = true; mAnnotationToolbar = new pdftron.PDF.Tools.Controls.AnnotationCommandBar(mToolManager); var stackPanel = new StackPanel(); stackPanel.Children.Add(mAnnotationToolbar); stackPanel.Children.Add(mPdfViewCtrl); page = new Page(); page.Content = stackPanel; }
void SetupUserInterface() { activity = this.Context as Activity; view = activity.LayoutInflater.Inflate(Resource.Layout.ViewerLayout, this, false); mPdfViewCtrl = view.FindViewById <pdftron.PDF.PDFViewCtrl>(Resource.Id.pdfviewctrl); AppUtils.SetupPDFViewCtrl(mPdfViewCtrl, PDFViewCtrlConfig.GetDefaultConfig(this.Context)); var file = Utils.CopyResourceToLocal(this.Context, Resource.Raw.sample, "sample", ".pdf"); mPdfDoc = mPdfViewCtrl.OpenPDFUri(Android.Net.Uri.FromFile(file), ""); FragmentActivity fragmentActivity = null; if (activity is FragmentActivity) { fragmentActivity = activity as FragmentActivity; } mToolManager = ToolManagerBuilder.From().Build(fragmentActivity, mPdfViewCtrl); mToolManager.SetCanOpenEditToolbarFromPan(true); mToolManager.OpenEditToolbar += (sender, e) => { mAnnotationToolbar.Show(AnnotationToolbar.StartModeEditToolbar, null, 0, e.Mode, !mAnnotationToolbar.IsShowing); }; mAnnotationToolbar = view.FindViewById <AnnotationToolbar>(Resource.Id.annotationtoolbar); mAnnotationToolbar.Setup(mToolManager); mAnnotationToolbar.SetButtonStayDown(true); mAnnotationToolbar.HideButton(AnnotationToolbarButtonId.Close); mAnnotationToolbar.Show(); mSeekBar = view.FindViewById <ThumbnailSlider>(Resource.Id.thumbseekbar); }
void SetupUserInterface() { var activity = this.Context as Activity; view = activity.LayoutInflater.Inflate(Resource.Layout.ViewerLayout, this, false); // init UI mPdfViewCtrl = view.FindViewById <pdftron.PDF.PDFViewCtrl>(Resource.Id.pdfviewctrl); mToolbarContainer = view.FindViewById <FrameLayout>(Resource.Id.annotation_toolbar_container); mPresetContainer = view.FindViewById <FrameLayout>(Resource.Id.preset_container); // setup PDFViewCtrl and ToolManager AppUtils.SetupPDFViewCtrl(mPdfViewCtrl, PDFViewCtrlConfig.GetDefaultConfig(this.Context)); if (activity is FragmentActivity) { mFragmentActivity = activity as FragmentActivity; } mToolManager = ToolManagerBuilder.From().Build(mFragmentActivity, mPdfViewCtrl); // setup toolbars SetupAnnotationToolbar(); var file = Utils.CopyResourceToLocal(this.Context, Resource.Raw.sample, "sample", ".pdf"); mPdfDoc = mPdfViewCtrl.OpenPDFUri(Android.Net.Uri.FromFile(file), ""); }
protected override void OnDetachedFromWindow() { base.OnDetachedFromWindow(); mPdfViewCtrl?.Destroy(); mPdfViewCtrl = null; mPdfDoc?.Close(); mPdfDoc = null; }
protected override void OnDetachedFromWindow() { base.OnDetachedFromWindow(); mSeekBar?.ClearResources(); mSeekBar = null; mPdfViewCtrl?.Destroy(); mPdfViewCtrl = null; mPdfDoc?.Close(); mPdfDoc = null; }
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; }
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)); } }
public PDFTronPage() { this.InitializeComponent(); pdftron.PDF.PDFViewCtrl myPDFViewCtrl = new pdftron.PDF.PDFViewCtrl(); myPDFViewCtrl.SetupThumbnails(false, true, false, 250, 100 * 1024 * 1024, 0.1); myPDFViewCtrl.SetPagePresentationMode(pdftron.PDF.PDFViewCtrlPagePresentationMode.e_single_page); myPDFViewCtrl.SetBackgroundColor(Windows.UI.Colors.DarkGray); myPDFViewCtrl.SetPageSpacing(3, 3, 1, 1); myPDFViewCtrl.SetRelativeZoomLimits(pdftron.PDF.PDFViewCtrlPageViewMode.e_fit_page, 0.7, 5); myPDFViewCtrl.SetPageRefViewMode(pdftron.PDF.PDFViewCtrlPageViewMode.e_zoom); PDFViewBorder.Child = myPDFViewCtrl; var document = new pdftron.PDF.PDFDoc(Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "tiger.pdf")); myPDFViewCtrl.SetDoc(document); }
/// <summary> /// extract pdf table data /// </summary> /// <param name="doc"></param> /// <param name="tablePos"></param> /// <returns></returns> public static FreeTable Extract(pdftron.PDF.PDFDoc doc, TablePos tablePos) { PageTextExtractor pdfPageProcess = new PageTextExtractor(doc.GetPage(tablePos.PageNum)); var vLines = new List <System.Windows.Rect>(tablePos.VerticalLines.Count); var hLines = new List <System.Windows.Rect>(tablePos.HorizontialLines.Count); foreach (var kv in tablePos.VerticalLines) { var top = kv.Value.Min(n => n.StartPoint.y); var bottom = kv.Value.Max(n => n.EndPoint.y); vLines.Add(new System.Windows.Rect(kv.Key, top, 0, bottom - top)); } foreach (var kv in tablePos.HorizontialLines) { var left = kv.Value.Min(n => n.StartPoint.x); var right = kv.Value.Max(n => n.EndPoint.x); hLines.Add(new System.Windows.Rect(left, kv.Key, right - left, 0)); } if (vLines.Count == 0 || hLines.Count == 0) { throw new Exception("vertical or horizontal lines is empty"); } hLines.Reverse(); FreeTable freeTable = new FreeTable(); for (int i = 1; i < hLines.Count; i++) { var y = hLines[i].Y; var y2 = hLines[i - 1].Y; var prej = 0; var x = hLines[i - 1].Left; while (prej < vLines.Count) { if (vLines[prej].X > x - 5) { break; } prej++; } var x1 = vLines[prej].X; FreeTableRow row = new FreeTableRow(); for (int j = prej + 1; j < vLines.Count; j++) { var vline = vLines[j]; if (vline.Bottom - y > 5 || j == vLines.Count - 1) { int ii = i; for (; ii < hLines.Count - 1; ii++) { if (vline.X - hLines[ii].Left > 5) { break; } } var data = pdfPageProcess.SearchTextWithStrictMode( new System.Windows.Rect(x1, hLines[ii].Y, vline.X - x1, y2 - hLines[ii].Y)); row.Add(new FreeTableCell() { Value = data, ColSpan = j - prej, RowSpan = ii - i + 1 }); prej = j; x1 = vline.X; } } freeTable.Add(row); } return(freeTable); }