Modifying font size in Gitbook - gitbook

I'm editing the book.json file to change the size of the pdf font in Gitbook but it won't accept my code and keeps asking me to correct the error.
This is what I have entered:
{
// Options for PDF generation
"pdf":
{
// Font size for the fiel content
"fontSize": 15,
}
}
I refer to a previous SO question # How to modify the font size in GitBook?
This code snippet seems simple but I cannot get it to work despite several editing attempts!
I'm grateful for help and look forward to advice to fix this, many thanks

The json is not valid. You can valid json online at http://jsonlint.com
The correct json is:
{
"pdf": {
"fontSize": 15
}
}
In the new version (2.0.0), you can instead of using this option extend the css used in your pdf by creating a file: styles/pdf.css.

Related

I am having problems trying to display a RTF data file in a rich text edit control in a MFC dialog

I saw a discussion here about displaying a RTF file in a rich text edit control. Maybe what I am trying to do it too much.
In my dialog class I define a static method:
static DWORD CALLBACK MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb)
{
std::ifstream* pFile = (std::ifstream*)dwCookie;
pFile->read((char*)pbBuff, cb);
return 0;
}
In my dialog OnInitDialog class I try to display the data:
std::ifstream File("d:\\RevisionHistoryTest.rtf");
EDITSTREAM es = { 0 };
es.dwCookie = (DWORD)&File;
es.pfnCallback = MyStreamInCallback;
::SendMessage(m_rtfEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
Now, here is a link to a sample project. I don't know where I can put this project in the long term, but my DropBox will do for now. The project does not include the RTF file. This is how I created it:
I went to the following URL in a browser.
I selected all the Revision History content and pasted it into a Microsoft Word file.
I copied the Microsoft Word content and pasted it into a WordPad session and saved it.
Example:
Interestingly, when I subsequently open my RTF file in WordPad I get a popup message:
If I select Unblock then it still opens in the editor. I assume that is because all of the images must still be linked to those on my website. And I think this is related to the issue with my test project, because this is what I see:
I get no errors or anything. It just reads the first line and stops.
I am trying to find the easiest way to display my HTML history in a RTF window.
My original intention was to use a CHtmlView control instead (makes sense to do that) and directly read my Revision History file from the internet. But my help system is designed to permanently show the contents pane on the left. This is why I thought that RTF might be a suitable alternative. But struggling with it.
Update
Based on the comments made about 64 bit builds I located this tutorial which works for both 32 bit and 64 bit. They both display "Revision History" only.
BOOL FillRichEditFromFile(HWND hwnd, LPCTSTR pszFile)
{
BOOL fSuccess = FALSE;
HANDLE hFile = CreateFile(pszFile, GENERIC_READ,
FILE_SHARE_READ, 0, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
EDITSTREAM es = { 0 };
es.pfnCallback = MyStreamInCallback;
es.dwCookie = (DWORD_PTR)hFile;
if (SendMessage(hwnd, EM_STREAMIN, SF_RTF, (LPARAM)&es) && es.dwError == 0)
{
fSuccess = TRUE;
}
CloseHandle(hFile);
}
return fSuccess;
}
And in OnInitDialog:
FillRichEditFromFile(m_rtfEdit.GetSafeHwnd(), _T("d:\\RevisionHistoryTest.rtf"));
But my initial issue still remains.
Update
I had forgotten to set the control to multiline! That was part of the issue:
At least all of the text is visible now. Just not the images. And I don't like the way some of the links are displayed.
I have been able to edit the file and bring the indents over to the left to make it look better. But images still won't show.
Update
As a workaround to this I realised that I could simply duplicate my HTML Revision History as a standalone page. Then I can use CHtmlView:
The benefit is that the display is consistent wit what the user sees in the help system.

Using Fonts in an Azure-Function

I try to get PdfSharp working in an Azure Function
But I have some problems with fonts
// Create a new PDF document
PdfDocument document = new PdfDocument();
document.Info.Title = "Created with PDFsharp";
// Create an empty page
PdfPage page = document.AddPage();
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);
// Create a font
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
// Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height),
XStringFormats.Center);
This is also the code from the PDFSharp sample page...
At the font line he gives me the following error...
Exception while executing function: Functions.PDFGenerationFunction. PdfSharp: Internal error. Font data could not retrieved.
Do I need to reference something special? Or is it just not possible to do this in an Azure function?
PDFSharp version --> "PDFsharp" : "1.32.3057"
And/Or another solution to generate a PDF document in an Azure Function...
This is likely an issue with the sandbox that Azure Functions and webapps run in.
Check out this list for known PDF libraries that will work in the sandbox.
https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks
PDF Sharp is unable to find an appropriate font for the function and also for Web APIs/Apps. Because they are not provided with the standard fonts.
To resolve this one needs to code and provide a font resolver based on the PDFSharp interface IFontResolver to PDF Sharp. That resolver will actually acquire the font and return it as a stream.
The below example is a resolver I wrote to extract from the current assemblies embeded fonts such as:
PdfSharp.Fonts.GlobalFontSettings.FontResolver = new EmbeddedFontResolver();
The best example on how to create such a resolver on Stack Overflow is this answer (it is not my answer, but I have modified it to provide a better understanding of what happens)
Azure PDF Sharp not using Unicode font
If the function won't allow you to use embeded fonts, you can load them most likely from an Azure Blob.

Leaflet geojson layer with customized divIcon for each feature

I'm trying to set a different divIcon for each point on a leaflet geoJson layer. I have tried everything under the sun but it just doesn't work for me. This is what I'm doing
geoJsonLayer = L.geoJson(null, {
pointToLayer: function(feature, latlng) {
var smallIcon = L.DivIcon.extend({
options: {
iconSize: [27, 27],
html: "<div>" + feature.properties.FEATURE_STYLE.SVG_ELEMENT + "</div>"
}
});
return L.marker(latlng, {icon: new smallIcon()});
},
style: getLayerStyle,
onEachFeature: setFeatureProperties,
});
geoJsonLayer.addTo(baseMap);
feature.properties.FEATURE_STYLE.SVG_ELEMENT is an html <svg> containing the icon.
The icons are displayed ok, but every feature display the same icon.
I've also tried doing the following:
using L.Icon with different .png in iconUrl for each feature
using L.circleMarker with different colors for each feature
They both works as expected (different color / icon per feature). But I can't seem to get the divIcon to display differently for each feature.
Anyone have idea why this is the case?
Thanks in advance.
UPDATE:
This is what feature.properties.FEATURE_STYLE.SVG_ELEMENT looks like
Your code to instantiate a new L.divIcon is more complicated than really necessary, but it works, not considering the SVG part:
https://jsfiddle.net/3v7hd2vx/236/
That being said, please note that:
style option is used for vector layers. Therefore in the case of Point features that are rendered as L.divIcon's, it is not used.
onEachFeature option is applied after the pointToLayer one, because the latter is needed to create the layer that is fed to onEachFeature. Therefore if you build the feature.properties.FEATURE_STYLE.SVG_ELEMENT in there (as the name of your function setFeatureProperties suggests), it is too late.
If you need further help, you would very probably need to share more code, e.g. the style and onEachFeature options, and some sample data, in particular with feature.properties.FEATURE_STYLE.SVG_ELEMENT.

jspdf and addHTML / blurry font

I generate pdf file from a HTML-page via jspdf plugin addHTML.
It works but the rendered text / font is really blurry, the original HTML page is not. Rendered images are fine, only text is the problem (see attached images).
original_image: http://111900.test-my-website.de/stackoverflow/orig.jpg
blurry_image: http://111900.test-my-website.de/stackoverflow/blurry.jpg
I read all google results the last three days - maybe I am the only person in the world I have exact this problem?!?! :/
I added the following scripts in my code:
spdf.js
jspdf.plugin.from_html.js
jspdf.plugin.split_text_to_size.js
jspdf.plugin.standard_fonts_metrics.js
pdf generation code:
pdf.addHTML(document.getElementById("container"),10,15,function() {
var string = pdf.save(filename);
});
Is there a quality option in jspdf I missed?
How can I render the font?
Thanks for reply,
Thomas
I found that when creating a PDF and the text was blurred when using addHtml this was because of the width of the web page. Try using it with the browser not maximised as a test.
My solution was to add some styles to adjust the width before calling addHTML with a width parameter that matches the styles I added. I then remove the additional styles in the function that runs after addHTML.
I had the same problem and I resolved it.
Actually, the main issue here is to specify the 'dpi' to avoid having a blurred image. In addition to that, try to avoid any 'smoothening' features beacuse it may make it worse. I have taken a look around the API and other discussion about it and I came back with the following solution:
1- update your version of html2canvas : many blurring issues have been fixed after the 1.0.0-alpha release.
2- use the following properties :
const context = canvas.getContext('2d');
context.scale(2, 2);
context['dpi'] = 144;
context['imageSmoothingEnabled'] = false;
context['mozImageSmoothingEnabled'] = false;
context['oImageSmoothingEnabled'] = false;
context['webkitImageSmoothingEnabled'] = false;
context['msImageSmoothingEnabled'] = false;

Google Chrome: maximum of 4 chrome.commands allowed?

I have run into what I think is a hard maximum of 4 chrome.commands allowed, based on the following error I get in Google Chrome when trying to add 5 or more in the manifest.json file:
"Could not load extension from '[Extension Path]'. Too many commands specified for 'commands': The maximum is 4."
Is there any particular reason for this limit, or any way to get around it?
For context: I'm currently working on an extension that adds the current page as a bookmark to a specific folder based on a specific hotkey, currently along the lines of ctrl+alt+0, ctrl+alt+1, up to ctrl+alt+9.
I have looked at source code and figured out following lines of code.
constant declared for error message in extension_manifest_constants.cc
const char kInvalidKeyBindingTooMany[] =
"Too many commands specified for 'commands': The maximum is *.";
constant declared for maximum number of commands in extension.cc
// The maximum number of commands (including page action/browser actions) an
// extension can have.
const size_t kMaxCommandsPerExtension = 4;
and validation code in extension.cc looks for following check
if (commands - > size() > kMaxCommandsPerExtension) {
* error = ErrorUtils::FormatErrorMessageUTF16(
errors::kInvalidKeyBindingTooMany,
base::IntToString(kMaxCommandsPerExtension));
return false;
}
Google developers marked constant to 4, so you can not add more than 4 commands for now.
Work Around:
Star this issue and look for developers response, if you really want to go with commands, you have to create multiple extensions with commands set of 4 for each.
Let me know if you need more information.
This is a very old question but I had a hard time finding information anywhere and this question was the top google search result for a few of my searches, so I'll add some info here.
Despite the wordage of the error, you can have as many commands as you want. This error actually refers to the number of "suggested_key" objects you can have. Chrome's documents specify the following:
An extension can have many commands but only 4 suggested keys can be specified.
So in your manifest, while you can specify additional commands, you can only give 4 of them the "suggested_key" object
"commands": {
"contains-suggested-key": {
"suggested_key": {
"default": "Ctrl+Shift+Y",
"mac": "Command+Shift+Y"
},
"description": "Toggle feature foo"
},
"NO-suggested-key": {
"description": "user must specify shortcut keys for this from the extensions page"
}
}

Resources