I am trying to create a PDF using HTML content. Everything is fine but i have one problem where the page breaks on PDF get inserted between content and cause it to divide between pages.
Example:
A portrait image with height>width get a page break half way in between and causes half image to be on page 1 and the other half to be on page 2. This is just an example, the content on my PDF is dynamic, meaning the user has control over generating amount of content. Therefore its not necessary that image be always on page 1 it could be anywhere on the document.
I have tried to search for some libraries also but as per my understanding of how PDF files are rendered in iOS, I don't have any clue how to manage content that gets divided due to the page breaks.
Platform: iOS 10, xcode 8, Objective-C
Try to add something like the following to your css.
img {
page-break-inside:avoid
}
See also:
Print styles: How to ensure image doesn't span a page break
Related
We have some reports generated with JasperReports 6.2.0 that have this bizarre affect where as you get further into pages of the report the text gets more blurry as you go. The first page or two is crisp text, but get to page 30 or so and it becomes unreadable. In our scenario we are printing checks, so I can only post close up shots of some text. But the first image is the first page, and the second image is about page 28. Notice the difference.
We have two font extensions set up with Calibri and MICR fonts, They are added correctly and have the pdfEncoding set to Cp1250 and pdfEmbedded to true (I have tried other values).
How can we make the text not become blurry? Thanks
UPDATE: I am removing Jasper Reports from the equation/cause of the issue. And believe it might be in the component PDF.js that we are using that renders the PDF into the print preview.
My upcoming mobile web project requires viewing dynamically chosen pdf files inside the webpage. I am using iFrame to display the pdf file and the file can be scrolled using two-finger scrolling. But the problems I am facing are:
The first page of the file is not displayed completely on the iPad and gets cut off along the width unlike when I view it on the desktop browsers where the first page of the pdf is always entirely displayed although zoomed out to fit in the iFrame area.
There is no visual indication for the users that the pdf document can be scrolled, i.e., there is no scroll bar on the pdf document.
The controls (page navigation, zoom etc.) for the pdf viewer (Adobe reader) don't appear on the document unlike when I see it on the desktop browsers.
What is the best way to achieve what I am trying to do? Do any of you experts know any solutions/workarounds to the problems I am facing? An entirely different approach using anything other than iFrame can also be considered.
The reason why the pdf should be inside the html page is that, the list of pdf files will be on a menu bar on the left side of the page and the user can click on any of them to view on the same page. Ideally, they will have the capability to toggle between full screen view and that view.
Any help is appreciated.
I created a tiny JavaScript module that helps you to show a PDF inline and be able to scroll it. But I also couldn't figure out a way to make it fit the total width of the parent container.
Check it out: https://github.com/williamrjribeiro/ipdf-scroll
Cheers.
I came across this Recommended way to embed PDF in HTML? while researching on the web to find an answer.
The mentioned link discusses about some options that I can use and the google document viewer works for me though don't know if there is anything (like data limit) I need to be aware of before using it on the website. Also I have no idea if it is a good solution (though the full screen mode is not available, but zoom-in/zoom-out and next/prev page buttons are there are show up in the mobile safari on the iPad) to use for an web app that will be run on the iPad.
Anyway, I will keep researching for a better solution and if i don't find any, I'll stick to the google document viewer.
The issue appears to be a bug with Safari on the IPad.
I didn't find a solution for embedding the pdf in html but I did find this:
If you return FileStreamResult from your controller action instead of a view, the pdf will open in a new tab, it's not embedded html but at least your user is not having to download files and open them manually.
I had the same problem of the pdf not being displayed completely. The only thing I found to fix this was the change the size of the div containing the pdf.
For example if the element containing the pdf is a div then I change its width to any value and the rollback to the value it had before. Changing Width or height any one works.
Sometimes I had to wait a little using a setTimeout before calling my resizable method
I've got an app with a big 'help' page that describes how to use it. This page features a lot of text with some embedded images. Is there some way to 'link' or attach these images to the bottom of specific text boxes so things will lay out reasonably well for any localization we do? In other words, if the French translation of a block of text ends up being two lines longer than the English equivalent, I'd like the image that's placed below that text to be pushed downward by the appropriate amount without having to re-edit the layout of of the .xib file manually. Possible?
You can make HTML page. You can place any thing after your text and can do modification. As it is HTML page it can easily wrap and auto adjust itself. And show the html page in your webview by saving the HTML page in your local data storage
I've observed this on iOS 4.3 to 5.0. When you create a even a simple offline web app, meaning one HTML file + few assets such as CSS and JS (all present in the cache manifest), it works offline (I tested in Airplane Mode) – BUT, when you add such an app to your home screen and open it in fullscreen mode, it first displays initial content, then everything disappears (page becomes white) for half a second or more, then content reappears again.
You can see this by adding Glyphboard, a well-known and useful offline web app, to your iOS home screen and launching it a few times. You should see the white flash effect every time you load it.
This is a big problem because it gives away the non-nativeness of an app and gives the impression that the app is non-optimized for performance and buggy.
I've tried finding reports about this but all I can find is rumors and misconceptions about the iOS 4.3 JavaScript rendering engine fiasco, which doesn't need at all be related to this issue. But in iOS version 3 I distincly remember not ever seeing the white flash.
Clearing the screen and other artifacts while rendering is a common issue of HTML rendering due to the progressive nature of HTML. The concept is that the browser should draw as early and often as possible and render styles/scripts/content as they become available. It's possible the markup has an issue where all rendering is delayed until some content or a script is available. This could happen if:
You have dynamic heights based on image dimensions but you haven't
set the image dimensions in the markup or CSS.
Your layout is based on tables and you aren't using 'table-layout:fixed` in CSS.
Your HTML uses inline scripts with document.write().
You have some kind of onLoad() function that reveals/modifies content.
You link to an external stylesheet.
You're using uncacheable external content or you've disabled caching.
You're using external content that's returning 404 or isn't available offline.
Has your HTML/CSS changed between testing IOS versions?
I've found this to be caused by the use of:
<meta name="viewport" content="width=device-width initial-scale=1.0 maximum-scale=1.0 user-scalable=0">
With a minimal page, I get a white flash between the apple-touch-startup-image and the page contents if I use the viewport meta tag. If I take out the tag, no flash.
It's possible to work around the problem by setting the tag programatically.
I think what happens here is that iOS takes a screenshot from the page when it is added to the main menu. Then this screenshot is displayed during the application loads (WebKit loads). WebKit starts rendering the page and the page itself is constructed in such a way that the page content is not instantly available, leading to a white flash which is a rendered page when page content is not yet there,
You can avoid the problem to a certain level by building your JS/CSS so that it loads the initial HTML view fast and then lazily loads / builds the rest of the resources on the background. Also you can set a custom loading screen instead of the default screenshot iOS uses from the page.
Maybe if you can take yourself a screenshot of your app and then have something like this:
<body style="background: white url('my-initial-loading-screen.png')" />
... and make sure image is available and comes from manifest.
Or even better, have loading screen which does not require any external resources to show (just plain HTML) so you know the browser doesn't need to load anything.
I am loading files from an .epub into UIWebViews for display. At the moment, the .epub is divided into individual files for each chapter. To display the chapters, I am just loading these files into UIWebView. I am trying to figure out how to break these down into pages depending on font size, styling, etc. It's proving difficult, as iOS only accesses the UIWebView content indirectly. Is there a standard method for breaking it up?
I'm thinking about grabbing full chapter content out of a page with JS, then breaking each chapter down into pages based on line length and lines per page, but that seems sort of crazy, and I'm having trouble returning it to a UIWebView as valid html or javascript code. (The text contains single quotes, etc.)
Use UIWebView Pagination :)
myWebView.paginationMode = UIWebPaginationModeLeftToRight;
myWebView.paginationBreakingMode = UIWebPaginationBreakingModePage;
myWebView.gapBetweenPages = 50;
For font scaling, you need to inject css thru javascript for webkit's font scaling property
http://css-infos.net/property/-webkit-text-size-adjust