2

Whether I choose "Download as PDF" or I choose "Print" and "Save as PDF" Google Sheets messes up the formatting on the PDF it generates

Here's what it's supposed to look like and what it looks like in the browser before exporting.

enter image description here

And here was what it exports

enter image description here

If it's not clear it has separated every accent

enter image description here

Note: this appears to be a problem with the way the characters are entered. There are at least 2 ways

  1. A single character that contains the accent
  2. As 2 characters. The character without the accent and then the accent.

    Example: 基づき

If you copy the text above, paste it somewhere and press delete you'll see it goes

   基づき
   基づ
   基つ
   基

Where as this text 基づき will go

   基づき
   基づ
   基

Still, in order to be useful in Japanese it needs to export the first format correctly which it's not doing now.

As a test I put the same code in TextEdit on MacOS, used the delete test to check it was the first version, exported that to PDF and the result was correct.

NOTE: (actually you'll have to edit this message to get the 4 character version of the text above. In the editor pressing delete requires 4 presses where as if you copy and paste from the non-editor version you get the 3 character version)

  • Both are unicode. There are tons of documents in the first format. There are documents that use both formats. If Google wants Sheets to be used in Japan they need it to "just work", not tell users to go work around Google's bugs – gman Mar 15 '18 at 8:39
  • 1
    As pointed out above other apps don't have this problem exporting the same data to PDF so that it shows up correctly in PDF and also there is no Adobe involved here. – gman Mar 15 '18 at 16:06
  • Can I ask you about your situation? Such strings are in the cells of Spreadsheet? If it's so, how about converting them using Google Apps Script? If I misunderstand your situation, I'm sorry. – Tanaike Mar 16 '18 at 3:57
  • 2
    @I'-'I Yes. You are correct. So I created this. But because I was not sure about the situation, at first, I asked about it. I think that if gman uses spreadsheet, and the strings are in the cells, the script can be used for the situation. Is my understanding for your comment correct? – Tanaike Mar 16 '18 at 8:29
  • 2
    @I'-'I Thank you. When I could confirm that the script is useful for the situation, I would like to propose the script including the sample as an answer. – Tanaike Mar 16 '18 at 11:51
2

You can fix this by using NFKC normalization, which reduces sequences of combining characters to single unicode characters where possible. So it won't work on あ゛ but it will work on examples like that above.

In Python:

import unicodedata
a = '[bad text]'
fixed = unicodedata.normalize('NFKC', a)

If you search "nfkc normalization online" there are also some web forms you can paste into that will do it for you.

It's unfortunate you have to do this, but it's probably easier than waiting on Google to fix things.

I am curious how you ended up with documents with a lot of characters like that - while it's true that they won't normally cause problems in most Japanese applications, I would expect most documents to use composed characters by default.

  • 1
    I got this by downloading business forms off the internet in word or excel formats and loading them into Google Docs/Sheets to edit. I also got them by having a Japanese professional create some forms for me and loading those into Google Docs/Sheets as well. Running the forms though Python isn't a solution as I need the formatting, not just the text. – gman Mar 15 '18 at 16:13
  • @gman Not necessarily. You can access g.spreadsheet values inside python using Sheets API . – TheMaster Mar 15 '18 at 20:08
  • Looked into this more and seems like it's possibly related to creating the document on a Mac, which uses composing characters in some situations (mainly HFS+ filenames). Unfortunately while I found people having the problem outside Google Sheets, nobody had a good solution, so the best suggestion I have is to step through it cell by cell and convert. Sorry :/ Example problem: detail.chiebukuro.yahoo.co.jp/qa/question_detail/q11155503286 – polm23 Mar 16 '18 at 2:34
  • You can also download the file in Excel format, unzip it, and try using iconv on the whole thing, though I'm not sure that'll work either. qiita.com/knaka/items/48e1799b56d520af6a09 – polm23 Mar 16 '18 at 2:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.