PDF.js - How can I get currently visible page(s)? - pdf.js

At an event that occurs after the PDF is loaded I load in drawings to put on the canvas. I need to know which page(s) are currently rendered so as to get the correct drawings.
How can I detect which page(s) are currently rendered (ie, visible, possibly more than one because of user scrolling between pages)?

You can use the following code to achieve it:
function getCurrentPage() {
let pdfViewer = PDFViewerApplication.pdfViewer;
let pageIndex = pdfViewer.currentPageNumber - 1;
let pageView = pdfViewer.getPageView(pageIndex); //Give you the pageView object
let domElement = pdfViewer.getPageView(0).div; // Give you the reference to page dom element
return pageView;
}
Hope this helps

Related

Swift iOS disable keyboard autocomplete and top part

Is there a way in Swift to force the iOS keyboard to not have the top part? By saying the top part I mean the autocomplete and the input field switcher tools that appear at the top.
Some of my views have embedded webViews that run local js and I want the keyboard for the inputs in webView to not have that top part of the keyboard. If it`s not possible to disable these for webView specifically, any other method should be fine as well.
Please take a look at this screenshot to see exactly what part of the keyboard I am talking about.
You can try running the below JS in the webview every time you load the web page
var textFields = document.getElementsByTagName('input');
if (textFields) {
var i;
for( i = 0; i < textFields.length; i++) {
var txtField = textFields[i];
if(txtField) {
txtField.setAttribute('autocomplete','off');
txtField.setAttribute('autocorrect','off');
txtField.setAttribute('autocapitalize','off');
txtField.setAttribute('spellcheck','false');
}
}
}
Additionally write this code to hide the done button accessory view from keyboard
class CustomWebView: WKWebView {
var accessoryView: UIView?
override var inputAccessoryView: UIView? {
return accessoryView
}
}
And use CustomWebView in place of WKWebView wherever this functionality is needed.
Let me know if you need any more help.
Happy Coding :)

Drawing static full screen images using DirectX11

My question is as follows. In most tutorials that I've seen there is a setup part of DirectX11 where you do something like this:
// Set the refresh rate of the back buffer.
if(m_vsync_enabled)
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
}
else
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
}
Which either sets the refresh to be as fast as possible or synched with the monitor.
However in the application that I need I only want to refresh the screen when I tell the system to do it. Is there any way to do this?
These numbers have nothing to do with the actual refreshing, which happens when you invoke Present. You can call it once per second and screen will be refreshed just once.

ARKit API by example

I'm trying to wrap my head around Apple's ARKit API and I have pushed their example ARKitExample project up to GitHub.
In this demo/sample project, you move your phone camera around your environment, and it appears to automatically detect flat surfaces and place a set of "focus squares" over where your camera is centered over that surface. If you then press a "+" UI button and select from one of several objects (lamp, cups, vase, etc.) and it will render that virtual object in place of the focus squares. You can see all of this in action right here which is probably better than me trying to explain it!
I'm trying to find the place in the code where the virtual object is actually invoked and rendered onscreen. This would be just after it is selected, which I think takes place here:
#IBAction func chooseObject(_ button: UIButton) {
// Abort if we are about to load another object to avoid concurrent modifications of the scene.
if isLoadingObject { return }
textManager.cancelScheduledMessage(forType: .contentPlacement)
performSegue(withIdentifier: SegueIdentifier.showObjects.rawValue, sender: button)
}
But essentially, the user selects a virtual object and then it gets rendered wherever the focus square are currently located at -- I'm looking for where this happens, any ideas?
It adds the virtualObject instance (which is a subclass of SCNNode) as a child of the SCNScene's root node:
func virtualObjectSelectionViewController(_: VirtualObjectSelectionViewController, didSelectObjectAt index: Int) {
guard let cameraTransform = session.currentFrame?.camera.transform else {
return
}
let definition = VirtualObjectManager.availableObjects[index]
let object = VirtualObject(definition: definition)
let position = focusSquare?.lastPosition ?? float3(0)
virtualObjectManager.loadVirtualObject(object, to: position, cameraTransform: cameraTransform)
if object.parent == nil {
serialQueue.async {
self.sceneView.scene.rootNode.addChildNode(object)
}
}
}

Cycle through array in iOS

In this app I save an NSOrderedSet of cards to a "Subject" entity in core data so that users can quiz themselves. The card flips and drags in tinder like fashion well but in the update card method I'm having some trouble. The current card displays fine as I set that in view did load (the first card of the NSOrderedSet's array property). When I drag and update however it immediately goes to the last card, for example if I have 5 cards in a deck it will start with the first then immediately go to the fifth. What would be the best way to update this method so that it will cycle through as desired?
I suppose I should pass it an index property like a tableViewDelegate method but if someone has done something like this before and has a better way that's greatly appreciated.
Thanks for the help like always.
func updateCard() {
//cycle through questions here
for var i = 0; i < (self.subject.cards?.count)!; i++ {
self.currentCard = self.subject.cards?.array[i] as? Card
self.draggableView.questionLabel.text = self.currentCard?.question
self.draggableView.answerLabel.text = self.currentCard?.answer
}
}
Currently, when you call updateCard the for loop is computing at computer-speed and you only get to see the last index.
Here's one option:
In your class, set a stored variable called selectedCardIndex as an implementation detail and then just increment and update the view in updateCard.
var selectedCardIndex = 0
func updateCard() {
self.selectedCardIndex += 1
self.currentCard = self.subject.cards?.array[self.selectedCardIndex] as? Card
self.draggableView.questionLabel.text = self.currentCard?.question
self.draggableView.answerLabel.text = self.currentCard?.answer
}

How to show selected node on content picker to front page

I want to create a selection of banner with Content Picker' to select node to use other banner. http://screencast.com/t/3gb6TeAe
Now I wonder how to show the selected banner on Content Picker and show it in front page. Any idea to make it in easy way.
I have tried already to get the Url of selected node.
var nodeId = Model.Content.GetPropertyValue("selectBanner");
var node = Umbraco.TypedContent(nodeId);
#node.Name
If my understanding is correct you first need to get the banner node:
// This gets the node selected by your content picker
var bannerNode = Umbraco.TypedContent(Model.Content.GetPropertyValue<int>("selectBanner"));
You then need to get the image specified on the banner node:
// This gets you the image/media set on the banner nodes media picker property
var img = Umbraco.Media(bannerNode.GetPropertyValue("mediaPickerPropertyAlias")).Url
You can then access either the bannerNode url:
#bannerNode.Url
or the image specified on the banner node:
#img.Url
From what I can understand you have a Media Picker in your Banner document type. So you need to access banners image Url... you can do following
var node = Model.Content; // Your content of type banner
var imgUrl = Umbraco.Media(node.GetPropertyValue("selectBanner")).Url // getting property for image and then its url
#node.Name
or if you want to show just image
<img src="#imgUrl"/>

Resources