Respected visitors , this is your area. Ask your queries, post your suggestions. If you know correct answers for other friend's questions, kindly reply them. Motivate One another . Your comments will be posted soon with a small moderation. Note:Please avoid sharing phone numbers, email Ids and posting abusive comments against the government and recruitment agencies.
//Generating PDF...';
loadingIndicator.style.position = 'fixed';
loadingIndicator.style.top = '50%';
loadingIndicator.style.left = '50%';
loadingIndicator.style.transform = 'translate(-50%, -50%)';
loadingIndicator.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
loadingIndicator.style.color = 'white';
loadingIndicator.style.padding = '20px';
loadingIndicator.style.borderRadius = '10px';
loadingIndicator.style.zIndex = '9999';
loadingIndicator.style.fontSize = '18px';
loadingIndicator.style.textAlign = 'center';
document.body.appendChild(loadingIndicator);
// Function to hide loading indicator
const hideLoading = () => {
const indicator = document.getElementById('pdf-loading-indicator');
if (indicator) indicator.remove();
};
try {
console.log('Starting PDF generation...');
// Select the post content
const selectors = ['.post-body', '.entry-content', '.post-content', 'div.post', '.post-body-inner', '.post-entry'];
let postContentElement = null;
for (let selector of selectors) {
postContentElement = document.querySelector(selector);
if (postContentElement) {
console.log('Found post content with selector:', selector);
break;
}
}
// Fallback if no content found
if (!postContentElement) {
console.error('No post content found. Tried selectors:', selectors);
hideLoading();
alert('Error: Could not find post content.');
return;
}
// Clone the element to avoid modifying the original page
const contentToCapture = postContentElement.cloneNode(true);
// Find the post title
let postTitle = "";
// Try different common selectors for post titles in Blogger
const titleSelectors = [
'h3.post-title', '.post-title', '.entry-title',
'h1.title', 'h1.post-title', 'h2.post-title',
'.post h1', '.post h2', '.post h3',
'header h1', 'header h2'
];
for (let selector of titleSelectors) {
const titleElement = document.querySelector(selector);
if (titleElement) {
postTitle = titleElement.textContent.trim();
console.log('Found post title:', postTitle);
break;
}
}
// If no title found, try to get it from document title
if (!postTitle) {
// Extract title from document title (usually "Post Title - Blog Name")
const docTitle = document.title;
if (docTitle.includes('-')) {
postTitle = docTitle.split('-')[0].trim();
} else if (docTitle.includes('|')) {
postTitle = docTitle.split('|')[0].trim();
} else {
postTitle = docTitle;
}
console.log('Used document title as post title:', postTitle);
}
// Create a temporary div to hold our content for capture
const captureContainer = document.createElement('div');
captureContainer.id = 'pdf-capture-container';
captureContainer.style.position = 'absolute';
captureContainer.style.left = '-9999px';
captureContainer.style.width = '800px'; // Fixed width for better control
// Apply styling for Tamil text rendering
captureContainer.style.fontFamily = '"Mukta Malar", "Noto Sans Tamil", "Latha", Arial, sans-serif';
captureContainer.style.fontSize = '16px';
captureContainer.style.lineHeight = '1.8';
captureContainer.style.color = '#000';
captureContainer.style.backgroundColor = '#fff';
captureContainer.style.padding = '40px'; // Increased from 20px to 40px for more space around content
captureContainer.style.paddingBottom = '60px'; // Extra padding at bottom to prevent text cut-off
document.body.appendChild(captureContainer);
// Remove elements we don't want in the PDF
contentToCapture.querySelectorAll('script, style, iframe, .print-pdf-button').forEach(el => el.remove());
// Create a heading element for the PDF
if (postTitle) {
const titleDiv = document.createElement('div');
titleDiv.className = 'pdf-title';
titleDiv.innerHTML = `
${postTitle}
`;
// Add date if available
const dateSelectors = ['.date-header', '.post-timestamp', '.post-date', '.date', '.published', '.post-meta time'];
let postDate = "";
for (let selector of dateSelectors) {
const dateElement = document.querySelector(selector);
if (dateElement) {
postDate = dateElement.textContent.trim();
break;
}
}
if (postDate) {
titleDiv.innerHTML += `
${postDate}
`;
}
// Add the title before the content
captureContainer.appendChild(titleDiv);
}
// Add our cleaned content to the capture container
captureContainer.appendChild(contentToCapture);
// Also apply Tamil font to all child elements
captureContainer.querySelectorAll('*').forEach(el => {
if (el.nodeType === 1) { // Element node
el.style.fontFamily = '"Mukta Malar", "Noto Sans Tamil", "Latha", Arial, sans-serif';
}
});
// Verify jsPDF is available
if (!window.jspdf || !window.jspdf.jsPDF) {
console.error('jsPDF not loaded.');
hideLoading();
alert('Error: jsPDF library failed to load.');
return;
}
// Initialize jsPDF with increased margins
const { jsPDF } = window.jspdf;
const doc = new jsPDF({
format: 'a4',
unit: 'mm',
compress: true
});
// Define Page Margins and dimensions - INCREASED MARGINS
const pageMargin = 25; // Increased from 15 to 25mm
const pageWidth = doc.internal.pageSize.getWidth();
const pageHeight = doc.internal.pageSize.getHeight();
const contentWidth = pageWidth - 2 * pageMargin;
const topMargin = pageMargin;
const bottomMargin = 30; // Increased from 25 to 30mm
const effectivePageHeight = pageHeight - topMargin - bottomMargin;
console.log(`PDF page dimensions: ${pageWidth}x${pageHeight} mm`);
console.log(`Content area: ${contentWidth}x${effectivePageHeight} mm`);
console.log(`Margins: top=${topMargin}mm, bottom=${bottomMargin}mm, left/right=${pageMargin}mm`);
// Function to add watermark to all pages
const addWatermark = () => {
const pageCount = doc.internal.getNumberOfPages();
for (let i = 1; i <= pageCount; i++) {
doc.setPage(i);
doc.setFontSize(80);
doc.setTextColor(220, 220, 220); // Lighter gray for less obstruction
doc.setFont('Helvetica', 'normal');
const watermarkX = pageWidth / 4;
const watermarkY = pageHeight / 1.8;
doc.text('www.tnpscportal.in', watermarkX, watermarkY, { angle: 45 });
}
};
// Function to add page headers (title) and footers (page numbers, blog name)
const addHeadersAndFooters = () => {
const pageCount = doc.internal.getNumberOfPages();
const blogName = document.querySelector('.Header h1')?.textContent ||
document.querySelector('#header h1')?.textContent ||
document.querySelector('.blog-title')?.textContent ||
window.location.hostname;
for (let i = 1; i <= pageCount; i++) {
doc.setPage(i);
// Add title as header on each page (except first page which already has the main title)
if (postTitle && i > 1) {
doc.setFontSize(10);
doc.setTextColor(80, 80, 80);
doc.setFont('Helvetica', 'bold');
// Center the title
const titleWidth = doc.getStringUnitWidth(postTitle) * 10 / doc.internal.scaleFactor;
const titleX = (pageWidth - titleWidth) / 2;
doc.text(postTitle, titleX, 10); // Position at top of page
// Add a horizontal line under the header
doc.setDrawColor(200, 200, 200);
doc.setLineWidth(0.5);
doc.line(pageMargin, 12, pageWidth - pageMargin, 12);
}
// Add page number to bottom right
doc.setFontSize(10);
doc.setTextColor(100, 100, 100);
doc.setFont('Helvetica', 'normal');
doc.text(`Page ${i} of ${pageCount}`, pageWidth - 35, pageHeight - 15);
// Add blog name to bottom left
if (blogName) {
doc.setFontSize(8);
doc.text(blogName, pageMargin, pageHeight - 15);
}
}
};
// Function to capture content in chunks if it's very large
const captureContentInChunks = async (element, chunkHeight = 1000) => {
const canvases = [];
const elementHeight = element.offsetHeight;
const chunks = Math.ceil(elementHeight / chunkHeight);
console.log(`Content height: ${elementHeight}px, will capture in ${chunks} chunks`);
// Add extra space at the bottom of the content to ensure proper margins
element.style.paddingBottom = '50px'; // Increased padding
for (let i = 0; i < chunks; i++) {
// Update loading message
const loadingIndicator = document.getElementById('pdf-loading-indicator');
if (loadingIndicator) {
loadingIndicator.innerHTML = `ஆவணத்தை உருவாக்குகிறது... Generating PDF... ${Math.round((i+1)/chunks*100)}%`;
}
try {
const canvas = await html2canvas(element, {
y: i * chunkHeight,
height: Math.min(chunkHeight, elementHeight - i * chunkHeight),
windowWidth: 800,
scale: 1.5,
useCORS: true,
allowTaint: true,
logging: false,
letterRendering: true
});
canvases.push({
canvas: canvas,
y: i * chunkHeight
});
console.log(`Captured chunk ${i+1}/${chunks}`);
} catch (err) {
console.error(`Error capturing chunk ${i+1}:`, err);
throw new Error(`Failed to capture content chunk ${i+1}: ${err.message}`);
}
}
return canvases;
};
// Use simpler method for small content, chunking for large content
captureContainer.style.visibility = 'visible'; // Make sure it's visible for html2canvas
// Simple approach: try with a single capture first
html2canvas(captureContainer, {
scale: 1.5,
useCORS: true,
allowTaint: true,
logging: true,
letterRendering: true
}).then(canvas => {
// Convert canvas to image data
const imgData = canvas.toDataURL('image/jpeg', 0.95); // Increased quality
// Calculate dimensions to fit within PDF - respecting margins
const imgWidth = contentWidth;
const ratio = canvas.height / canvas.width;
const imgHeight = imgWidth * ratio;
console.log(`Canvas dimensions: ${canvas.width}x${canvas.height}px`);
console.log(`Image dimensions in PDF: ${imgWidth}x${imgHeight}mm`);
// Add a single image to PDF with proper pagination
let heightLeft = imgHeight;
let position = topMargin;
let pageOffsetY = 0;
// Add first page - with proper margin
doc.addImage(imgData, 'JPEG', pageMargin, position, imgWidth, imgHeight);
heightLeft -= effectivePageHeight;
// Add additional pages if needed - with consistent margins
while (heightLeft > 0) {
doc.addPage();
pageOffsetY += effectivePageHeight;
doc.addImage(imgData, 'JPEG', pageMargin, position - pageOffsetY, imgWidth, imgHeight);
heightLeft -= effectivePageHeight;
}
// Add watermark and headers/footers
addWatermark();
addHeadersAndFooters();
// Add border on each page for better visual margin definition
const pageCount = doc.internal.getNumberOfPages();
for (let i = 1; i <= pageCount; i++) {
doc.setPage(i);
doc.setDrawColor(200, 200, 200);
doc.setLineWidth(0.5);
// Draw rectangle with margin offset
doc.rect(
pageMargin - 3, // 3mm inside the margin
topMargin - 3, // 3mm inside the margin
contentWidth + 6, // Add 6mm (3mm on each side)
effectivePageHeight + 6 // Add 6mm (3mm on each side)
);
}
// Clean up and save
hideLoading();
captureContainer.remove();
// Use post title in the filename if available
let filename = 'post_content.pdf';
if (postTitle) {
// Sanitize the title for use in a filename
const sanitizedTitle = postTitle.replace(/[^a-z0-9\s]/gi, '_').replace(/\s+/g, '_').substring(0, 50);
filename = sanitizedTitle + '.pdf';
}
console.log('Saving PDF:', filename);
doc.save(filename);
}).catch(err => {
console.error('Error in simple capture method, trying chunking approach:', err);
// If simple method fails, try chunking approach
captureContentInChunks(captureContainer).then(chunks => {
console.log(`Successfully captured ${chunks.length} chunks`);
// Add each chunk to the PDF
chunks.forEach((chunk, index) => {
const canvas = chunk.canvas;
// Convert to image data
const imgData = canvas.toDataURL('image/jpeg', 0.95); // Increased quality
// Calculate dimensions
const imgWidth = contentWidth;
const ratio = canvas.height / canvas.width;
const imgHeight = imgWidth * ratio;
// Add the title before the content
if (index > 0) {
doc.addPage();
}
// Add image to page with proper margins
doc.addImage(imgData, 'JPEG', pageMargin, topMargin, imgWidth, imgHeight);
});
// Add watermark and headers/footers
addWatermark();
addHeadersAndFooters();
// Add border on each page for better visual margin definition
const pageCount = doc.internal.getNumberOfPages();
for (let i = 1; i <= pageCount; i++) {
doc.setPage(i);
doc.setDrawColor(200, 200, 200);
doc.setLineWidth(0.5);
// Draw rectangle with margin offset
doc.rect(
pageMargin - 3, // 3mm inside the margin
topMargin - 3, // 3mm inside the margin
contentWidth + 6, // Add 6mm (3mm on each side)
effectivePageHeight + 6 // Add 6mm (3mm on each side)
);
}
// Clean up and save
hideLoading();
captureContainer.remove();
// Use post title in the filename if available
let filename = 'post_content.pdf';
if (postTitle) {
// Sanitize the title for use in a filename
const sanitizedTitle = postTitle.replace(/[^a-z0-9\s]/gi, '_').replace(/\s+/g, '_').substring(0, 50);
filename = sanitizedTitle + '.pdf';
}
console.log('Saving PDF (chunked method):', filename);
doc.save(filename);
}).catch(chunkErr => {
console.error('Error in chunking method:', chunkErr);
hideLoading();
captureContainer.remove();
alert('Failed to generate PDF: ' + chunkErr.message);
});
});
} catch (error) {
console.error('PDF generation failed:', error);
hideLoading();
alert('Error generating PDF: ' + error.message);
}
}
// Add button only on single post pages
function addPrintButton() {
try {
// Check if single post page (you can adjust this logic as needed)
const isSinglePost = document.querySelector('.post') &&
!window.location.href.includes('/search') &&
!window.location.href.includes('?updated-max') &&
(window.location.pathname.match(/\/\d{4}\/\d{2}\/.*\.html$/) ||
document.querySelector('.post-body') !== null);
if (!isSinglePost) {
console.log('Not a single post page. Skipping button.');
return;
}
// Find post content container to append button after
const selectors = ['.post-body', '.entry-content', '.post-content', 'div.post', '.post-body-inner', '.post-entry'];
let postContainer = null;
for (let selector of selectors) {
postContainer = document.querySelector(selector);
if (postContainer) {
console.log('Found post container with selector:', selector);
break;
}
}
// Fallback
if (!postContainer) {
console.warn('Post container not found. Using document.body.');
postContainer = document.body;
}
// Avoid duplicates
if (document.querySelector('button.print-pdf-button')) {
console.log('Button already exists.');
return;
}
// Create button
const button = document.createElement('button');
button.className = 'print-pdf-button';
button.innerHTML = 'Print as PDF 📄'; // Added icon for better visibility
button.style.margin = '20px 0';
button.style.padding = '12px 24px';
button.style.backgroundColor = '#4CAF50';
button.style.color = 'white';
button.style.border = 'none';
button.style.cursor = 'pointer';
button.style.display = 'block';
button.style.fontWeight = 'bold';
button.style.borderRadius = '5px';
button.style.fontSize = '16px';
button.style.boxShadow = '0 2px 5px rgba(0,0,0,0.2)';
// Add hover effect
button.onmouseover = function() {
this.style.backgroundColor = '#45a049';
};
button.onmouseout = function() {
this.style.backgroundColor = '#4CAF50';
};
button.addEventListener('click', printPostToPDF);
// Append button
const postElement = document.querySelector(selectors.find(sel => document.querySelector(sel)));
if (postElement && postElement.parentNode) {
postElement.parentNode.insertBefore(button, postElement.nextSibling);
console.log('Button added after post.');
} else {
postContainer.appendChild(button);
console.log('Button added (fallback method).');
}
} catch (error) {
console.error('Error adding button:', error);
}
}
// Add a Tamil font preloader to ensure it's available
function preloadTamilFonts() {
// Create a stylesheet that preloads Tamil fonts
const style = document.createElement('style');
style.textContent = `
@import url('https://fonts.googleapis.com/css2?family=Mukta+Malar:wght@400;700&display=swap');
/* Force Tamil font on elements */
[lang="ta"],
.ta,
.tamil {
font-family: "Mukta Malar", "Noto Sans Tamil", "Latha", Arial, sans-serif !important;
}
`;
document.head.appendChild(style);
// Preload the font
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'https://fonts.googleapis.com/css2?family=Mukta+Malar:wght@400;700&display=swap';
document.head.appendChild(link);
console.log('Tamil fonts preloaded');
}
// Run with retries
document.addEventListener('DOMContentLoaded', function() {
console.log('PDF generation script loaded...');
// Preload Tamil fonts first
preloadTamilFonts();
// Add the PDF button
addPrintButton();
let retryCount = 0;
const maxRetries = 5;
const retryInterval = setInterval(function() {
if (retryCount >= maxRetries) {
console.log('Max retries reached.');
clearInterval(retryInterval);
return;
}
if (!document.querySelector('button.print-pdf-button') && document.body.textContent.length > 1000) {
console.log('Retry ' + (retryCount + 1) + ': Attempting to add button...');
addPrintButton();
} else {
console.log('Button found or page too small, stopping retries.');
clearInterval(retryInterval);
}
retryCount++;
}, 1000);
});
//]]>
One year is equal to 365 1/4 days
பதிலளிநீக்குIn astronomy, the Julian year is a unit of time, defined as 365.25 days
one year equal to 365 1/4 solar days hence the ans for 10th question is C and not D
பதிலளிநீக்குanswer for 10th q is C and not D
பதிலளிநீக்குSSSSS
பதிலளிநீக்குfather moder phisics is EINSTENE
பதிலளிநீக்கு