Adjusting Text Size Depending on Width

I recently used an online converter to transform a PDF into HTML. Check out the result here: http://www.example.com/pdf-to-html-converted-file

The conversion did a decent job, but I'm wondering if it's feasible to have the content scale to 100% width for better mobile usability. While resizing the image width is straightforward, I've encountered issues with getting the text to scale proportionately. I've explored font scaling options, but they disrupt the text layout which is crucial. Both the image and text need to resize simultaneously. I've experimented with using "transform: scale(X)" which achieves the desired effect, but it's not ideal since the PDF width can vary. Is there a way to make this scaling dynamic? Any insights would be greatly appreciated.

Answer №1

To adjust the page scale using JavaScript, you can implement the following approach:

var targetPage = document.querySelector('#pf1');

var calculateScaleRatio = function(element){
    return document.body.offsetWidth / element.offsetWidth;
};

targetPage.style.transformOrigin = 'center top';

var applyZoomEffect = function(){
    targetPage.style.transform = 'scale(' + calculateScaleRatio(targetPage) + ')';
}

Ensure to trigger this function on events such as document ready, resize, and orientation change:

document.addEventListener('DOMContentLoaded', () => applyZoomEffect());
window.addEventListener('resize', () => applyZoomEffect());
window.addEventListener('orientationchange', () => applyZoomEffect()); // may not be necessary

Answer №2

One potential solution could involve incorporating the ONRESIZE event within your PDF's container:

<div id="PDFbox" onresize="DoScale();"></div>




 function DoScale(){

 // Retrieve the new dimensions of your container...

 var W=PDFbox.outerWidth;

 var H=PDFbox.outerHeight;  

 // Then, based on your chosen logic, dynamically adjust and scale accordingly...


AnotherID.style.transform='scale(2,2)';
}

I trust that I have grasped your query accurately.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting: Problems with AngularJS $http.get functionality not functioning as expected

I have a user list that I need to display. Each user has unread messages and has not created a meal list yet. I want to make two http.get requests within the main http.get request to retrieve the necessary information, but I am facing an issue with asynchr ...

What is the best method for storing a variety of HTML form data in a database?

I am currently working on developing a survey system that includes the feature of creating various types of questions through a drag & drop HTML form builder. The idea is for a client to create their survey form, which will then be stored in a database tab ...

Error: Access Denied - discord.js bot command cannot be executed due to lack of authorization

Every time I initiate the bot and try to execute my "ping" command, an error occurs: js:350 throw new DiscordAPIError(data, res.status, request); ^ DiscordAPIError: Missing Access at RequestHandler.execute (C: ...

My Tailwind CSS toggle button disappears in dark mode, why is that happening?

<button aria-label="Toggle Dark Mode" type="button" className="lg:inline-flex lg:w-40 md:w-screen p-3 h-12 w-12 order-2 md:order-3" onClick={() => setTheme(theme === 'dark' ? &ap ...

During server and browser builds, NextJs encounters a 404 error when trying to access files named _ssgManifest.js and _buildManifest.js. Additionally, the file named _

I recently deployed a NextJs application on a digitalocean droplet running Ubuntu 22.04. "next": "12.2.3", "react": "18.2.0", Encountering a 404 error for the following files: _ssgManifest.js, _buildManifest.js, an ...

What is the best method for retrieving text from elements designated by class?

I am currently using BeautifulSoup to scrape data from a website, but I am facing an issue with extracting only the text I need. The specific part of the website data that I want to grab is: <div content-43 class="item-name">This is the te ...

Customizing Bootstrap Navbar: Ensuring the External Search Bar is displayed correctly within the expanded navbar

In my Bootstrap 5 navbar, I have a search bar, notifications dropdown, and collapsible buttons. How can I ensure that the search bar is visible in the expanded version of the navbar and hidden when the navbar is collapsed, while keeping the notifications d ...

Connecting a Kendo Dropdown menu to external data sources for seamless integration

I need help with binding data to a dropdown list for my local service. Whenever I try to download the data, I keep getting an error message: Uncaught SyntaxError: Unexpected token: Does anyone have any ideas on how to resolve this issue? This is my JS ...

Learn how to dynamically update a user's profile picture in the navbar when clicked using Angular

When I have a navbar (see code below) and set *ngIf = "user", I attempt to display the user's avatar in the navbar but only see a placeholder. However, after refreshing the page, the user avatar appears. Therefore, I am curious about how I can refresh ...

I'm trying to figure out how to incorporate types for utilizing Intl.ListFormat in node v12. Can

I am currently working with nodeJS version 12.10.0, which now includes support for Intl.ListFormat. I am also using Typescript version 3.6.3. However, when compiling my code with Typescript, I encounter the following error: Property 'ListFormat' ...

Encounter a Config validation error while trying to utilize Nest.js ConfigService within e2e tests

I'm encountering an error despite having the NODE_ENV=development variable in my .env file. The error message reads: ● Test suite failed to run Config validation error: "NODE_ENV" must be one of [development, production] 11 | imports ...

My Ajax script is not recognizing the select tag value?

I am struggling with an ajax script that is supposed to send data from a contact form to a PHP script. The main issue I'm facing is that I can't seem to retrieve the value from the "select" tag. My knowledge of JavaScript/ajax is limited, so plea ...

Currently, I'm developing a Django project and integrating django_bootstrap_icons. Despite successfully installing it with pip and completing all necessary steps, the icons are not displaying on the website

configurations.py INSTALLED_APPS = [ ... 'myapp', 'django_bootstrap_icons', ] ... STATIC_URL = '/static/' MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR,'static,'media') STATIC_ ...

How can I use jQuery to vertically align an element?

Here's my website: Take a look here! I have a menu on the left column that I want to center. Take a look at the image below for a better understanding of what I'm trying to achieve. https://i.stack.imgur.com/ZzprT.png Here is the JavaScript c ...

Changing pages in Django with a single click of a line: A step-by-step guide

As a beginner in Django, I am looking to create views that change when a line in an HTML tag is clicked. The idea is to open a new view named after the hash inside the <code>Hash tag. {% load staticfiles %} <!DOCTYPE html> <html lang="fr"&g ...

Discovering the Sum of K with Node JS Value Mapping

Imagine you have a list of numbers like this: const arr = [{ key1: 10 }, { key2: 5 }, { key3: 7 }, { key4: 17 }];, and also a number k which is represented by const k = 17;. Your task is to determine if any two numbers from the list can be added up to equa ...

What is the purpose of using the "::before" CSS modifier to display the fontawesome chevron in the specified Bootstrap accordion code?

I stumbled upon a great example of adding arrows to the Bootstrap accordion on CodePen. Check it out: https://codepen.io/tmg/pen/PQVBGB HTML: <div class="container"> <div id="accordion"> <div class="card"& ...

What is the best way to showcase content using Chakra-ui SideBar in a React Application?

After exporting the SideBar, I imported it into my App.jsx SideBar.jsx 'use client' import { IconButton, Avatar, Box, CloseButton, Flex, HStack, VStack, Icon, useColorModeValue, Text, Drawer, Draw ...

Is there a way to utilize jQuery to redirect to the href included in the HTML attachment?

I am looking to add a redirection feature to my website using the href provided in the code by jQuery. This will be done after playing an animation for better user experience. $(document).ready(function(){ $("a").click(function(event){ event.prev ...

Align two containers centrally using absolute positioning inside a division

I am looking for a way to centrally align two "boxes" within a div using CSS. These boxes are positioned absolutely. For reference, here is the JSFiddle link: http://jsfiddle.net/p4sA3/8/ Is there a method to achieve this alignment without specifying spe ...