If my array goes over a certain length:
const List hts = [200, 195, 190, 185, 180, 175, 170, 165, 160, 155, 150, 145];
VSCode formats it like this:
const List hts = [
200,
195,
190,
185,
180,
175,
170,
165,
160,
155,
150,
145,
140
];
I'd rather it didn't since it makes a short array take up half the page. How can I change this?
Also I get even weirder formatting like this which means if I comment out a line it only comments out half the line:
This:
Text('RESULTS', style: kMainText),
Text('Additional', textAlign: TextAlign.center, style: kSmallText),
Gets formatted as this:
Text('RESULTS', style: kMainText),
Text('Additional',
textAlign: TextAlign.center, style: kSmallText),
The second line is one line but I have to comment it out as two lines. It seems like there's some kind of 'length' setting somewhere that I could alter to avoid this. How can I edit all this behaviour?
The Dart VS Code extension uses dart_style for formatting, which ships in the Dart SDK.
There is a setting called "maximum line length" which can be configured in your VS Code settings in the Dart section which will allow lines to be longer before they wrap (though note that this applies to all lines, not just lists).
There's an issue requesting an alternative (more customisable) formatter in VS Code here:
https://github.com/Dart-Code/Dart-Code/issues/914
Please add a 👍 to the issue if it's something you'd like to see.
The dart formatter will preserve line breaks in an list if there's a comment line at the head of this list.
For example, to format a very long list in Dart:
[
// yeah
a,b,c,
d,e,f,
];
See the test case (link) from official dart style repository (https://github.com/dart-lang/dart_style)
Related
(Rails 6.0.2.2, ruby 2.7.1, combine_pdf 1.0.18)
I'm currently trying to write some text to an existing PDF with the CombinePDF gem. Unfortunately I'm running in some encoding problems.
I'm loading the existing PDF:
pdf = CombinePDF.load "#{Rails.root}/public/pdf/base.pdf"
Then I'm adding text to it:
pdf.pages[0].textbox "Straße", height: 20, width: 160, y: 527, x: 215, font_size: 12, box_color: nil, text_align: :left, text_padding: 0
When generating a new pdf out of it:
send_data pdf.to_pdf, filename: "output.pdf", type: "application/pdf"
the string gets displayed as StraˆŸe, so the ß isn't displayed correctly.
I also tried to replace it with unicode literals (\xc3\x9f) without any effect.
Anybody has an idea what else to try?
If you use HexaPDF you could do something like this:
require 'hexapdf'
require 'stringio'
doc = HexaPDF::Document.open("#{Rails.root}/public/pdf/base.pdf")
doc.pages[0].canvas.font("Helvetica", size: 12).text("Straße", at: [215, 527])
outio = StringIO.new(''.b)
doc.write(outio)
Just make sure that you use a font that contains glyphs for all characters you want to use. So better use a TrueType font instead of the builtin Helvetica (you can just provide the path to a TrueType font to the #font method).
I'm generating a PDF with TCPDF. When a user opens the file, I'd like to open the PDF on page 3 instead of page 1.
I seem to recall this being possible in other PDF libraries, but I haven't been able to find anything in the API documentation for TCPDF.
Is this possible?
It's possible, if file open in browser.
Use setDestination(); for create link:
$pdf->AddPage();
$pdf->setDestination('chapter1', 0, '');
$pdf->Cell(0, 10, 'Chapter 1', 0, 1, 'L');
$pdf->AddPage();
$pdf->setDestination('chapter2', 0, '');
$pdf->Cell(0, 10, 'Chapter 2', 0, 1, 'L');
And open file on selected page by link:
http://www.path.to/Your/file/name.pdf#chapter2
Tcpdf example;
I have a blog page on my website and some posts have images and some don't. If there wasn't an image it was showing an error so I changed the code to only show if an image is present
.post_body
= #post.body.html_safe
- if #post.image
= filepicker_image_tag #post.image, w: 208, h: 208, fit: 'clip'
On my localhost, this worked well to solve the problem and nothing was displayed if I hadn't added an image to the post. But when I push it to heroku, my code changes haven't made any difference. If there is no image on the post it shows a broken image icon.
Does anyone know why this would be fine in localhost but not online?
Thanks
Add condition, like this
filepicker_image_tag #post.image, w: 208, h: 208, fit: 'clip' unless #post.image.blank?
or
.post_body
= #post.body.html_safe
- if #post.image.present?
= filepicker_image_tag #post.image, w: 208, h: 208, fit: 'clip'
I am using the ruby on rails axlsx gem to render my excel.
Now I want to style the text so that it shows up diagonally as shown in the sample image attached.
I am not sure where or how to set this alignment feature in the code.
Any help is appreciated!
alignment: {:textRotation => 60}
That did it for me.
I managed to find a similar issue from the axlsx github page:
https://github.com/randym/axlsx/issues/110
I wasn't able to locate it in the docs.
The complete code can be implemented as follows:
my_style {
alignment: {:textRotation => 60, horizontal: :center, vertical: :center, wrap_text: true},
}
sheet.add_row(headers, style: styles[:my_style], height: height)
I would like to have the user upload a file inside a form and upon submission, open the file and read each line in order to grab information from it to store in the database. So far I am only able to make an object and extract bytes from it.
def uploadedFile = request.getFile('name_of_file')
This gets me a commonsMultipartFile, but I am not sure if I need to stream the file into a buffer, or save the file into a temp folder and then try to open it that way.
uploadedFile.getbytes() will give me an array [71, 101, 110, 101, 114, 97, 108, 13, 10, 45, 45, 45, 45, 45, 45, 45, 13, 10, 83, 116....] which is not in a form I can do anything with.
I need to be able to open the file and read it line by line. Can I do that with the commonsMultipartFile - its options seem kind of limited.
The CommonsMultipartFile has a getInputStream() method which will return an InputStream on which you can call any Groovy enhancements, for example:
request.getFile('name_of_file').inputStream.eachLine { line ->
/* Parsing logic */
}
Save it to a dir first. Then parse and do what you need done.