PDF can't be created with NewCGPDFDocumentMBS

I’m creating PDFs with NewCGPDFDocumentMBS. The code is rather simple:

dim finalPDF as CGContextMBS = newPrintPath.NewCGPDFDocumentMBS(thePDFDoc.MediaBox(1), theSubject.Left(100), theMessageID, App.ApplicationNameMBS) if finalPDF = nil then globals.theerrorlog.DialogErrorProceed Replace(kErrorCreate, "<<subject>>", theSubject) globals.theerrorlog.logitem "print path: " + newPrintPath.NativePath else 'loop through pages and add header information end if

One user wants to save the result in Dropbox with Boxcryptor. There the creation of finalPDF fails and finalPDF = nil. In the session log I see:

[quote]2020-02-11, 14:03:10 Dialog: Es gab ein Problem beim Erzeugen des PDFs für den Betreff “Rechnung”.
2020-02-11, 14:03:13 print path: /Volumes/disk name/user name/Boxcryptor/Dropbox (Privat)/_save_data/mail_archive/Local Folders/Archiv/Freizeit/Boot/Mails/Rechnung/Rechnung.pdf[/quote]

Should that work for Boxcryptor? Can I find out why the PDF wasn’t created?

Xojo 2019r11, macOS 10.14.6, MBS 19.4.

So the folder is not writable?

Well, my app created the folders for /Freizeit/Boot/Mails/Rechnung/. So I’d assume that the folder is writable.

So if the plugin gets a correct URL for the folderitem, we call CGPDFContextCreateWithURL and if that fails, maybe look for a log message in console.app. Or run app in Terminal to see messages.

Okay, I’ll let the user try.

How do I do the verbose mode?

[quote]Last login: Wed Feb 12 13:01:31 on ttys002
/Applications/Mail\ Archiver\ X/Mail\ Archiver\ X.app/Contents/MacOS/Mail\ Archiver\ X ; exit;
MBP-Thomas:~ thomas$ /Applications/Mail\ Archiver\ X/Mail\ Archiver\ X.app/Contents/MacOS/Mail\ Archiver\ X ; exit;
2020-02-12 13:02:53.183 Mail Archiver X[4454:190050] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file.
Feb 12 13:02:54 Mail Archiver X[4454] : MessageTracer: load_domain_whitelist_search_tree:73: Search tree file’s format version number (0) is not supported
Feb 12 13:02:54 Mail Archiver X[4454] : MessageTracer: Falling back to default whitelist
CoreGraphics PDF has logged an error. Set environment variabe “CG_PDF_VERBOSE” to learn more.[/quote]

The Goggle only tells me how to do that in XCode.

run in Terminal before launching app:

export CG_PDF_VERBOSE=1

next line run the app directly in /Contents/MacOS/ folder

The user has tried that on his own. But there isn’t anything interesting in the result:

[quote]13:32:48.487558 +0100 Mail Archiver X trackMouse send action on mouseUp
13:33:46.948414 +0100 Mail Archiver X SecKeychainCopyDomainDefault
13:33:46.949048 +0100 Mail Archiver X SecTrustEvaluateIfNecessaryFastAsync
13:33:46.952600 +0100 Mail Archiver X SecKeychainCopyDomainDefault
13:33:46.952786 +0100 Mail Archiver X SecTrustEvaluateIfNecessaryFastAsync
13:33:46.972345 +0100 Mail Archiver X SecTrustReportTLSAnalytics
13:33:51.731316 +0100 Mail Archiver X PREPARE_ICON_IMAGE
13:33:51.733086 +0100 Mail Archiver X GET_ICON_IMAGE_NO_IO
13:33:51.733862 +0100 Mail Archiver X PREPARE_ICON_IMAGE
13:33:51.734007 +0100 Mail Archiver X GET_ICON_IMAGE_NO_IO
13:34:07.750262 +0100 Mail Archiver X PREPARE_ICON_IMAGE
13:34:07.751240 +0100 Mail Archiver X GET_ICON_IMAGE_NO_IO
13:34:07.751857 +0100 Mail Archiver X PREPARE_ICON_IMAGE
13:34:07.752153 +0100 Mail Archiver X GET_ICON_IMAGE_NO_IO
13:34:08.125417 +0100 Mail Archiver X PREPARE_ICON_IMAGE
13:34:08.125743 +0100 Mail Archiver X GET_ICON_IMAGE_NO_IO
13:34:08.126231 +0100 Mail Archiver X PREPARE_ICON_IMAGE
13:34:08.126425 +0100 Mail Archiver X GET_ICON_IMAGE_NO_IO
13:34:08.130988 +0100 Mail Archiver X PREPARE_ICON_IMAGE
13:34:08.131274 +0100 Mail Archiver X GET_ICON_IMAGE_NO_IO
13:34:08.131732 +0100 Mail Archiver X PREPARE_ICON_IMAGE
13:34:08.131935 +0100 Mail Archiver X GET_ICON_IMAGE_NO_IO
13:34:12.638087 +0100 Mail Archiver X trackMouse send action on mouseUp
13:34:12.906234 +0100 Mail Archiver X PREPARE_ICON_IMAGE
13:34:12.907213 +0100 Mail Archiver X GET_ICON_IMAGE_NO_IO
13:34:12.930486 +0100 Mail Archiver X PREPARE_ICON_IMAGE
13:34:12.930672 +0100 Mail Archiver X GET_ICON_IMAGE_NO_IO
13:34:14.726580 +0100 Mail Archiver X trackMouse send action on mouseUp
13:32:40.229521 +0100 Mail Archiver X Retrieve User by ID

/Applications/Mail\ Archiver\ X/Mail\ Archiver\ X.app/Contents/MacOS/Mail\ Archiver\ X ; exit;
MBP-Thomas:~ thomas$ /Applications/Mail\ Archiver\ X/Mail\ Archiver\ X.app/Contents/MacOS/Mail\ Archiver\ X ; exit;
2020-02-12 13:32:57.237 Mail Archiver X[4989:218703] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file.
Feb 12 13:32:58 Mail Archiver X[4989] : MessageTracer: load_domain_whitelist_search_tree:73: Search tree file’s format version number (0) is not supported
Feb 12 13:32:58 Mail Archiver X[4989] : MessageTracer: Falling back to default whitelist
CoreGraphics PDF has logged an error. Set environment variabe “CG_PDF_VERBOSE” to learn more.
logout
Saving session…
…copying shared history…
…saving history…truncating history files…
…completed.

[Prozess beendet][/quote]

What now?

Can reproduce it?
Did you log what parameters you passed?
What is in the media box.

Here is the information from the user:

[quote]2020-02-13, 11:18:26 reportPrinter.CreatePDF pdf file: /var/folders/jy/r76chkt918d9psvb_4mdqkqc0000gn/T/{1BA0336B-D11B-40DB-99A2-1FB3363B634C}
2020-02-13, 11:18:26 reportPrinter.CreatePDF origin: 0 0 0 0
2020-02-13, 11:18:26 NotificationManager.Post NextMinor
2020-02-13, 11:18:26 NotificationManager.Post PDFCreated
2020-02-13, 11:18:26 reportPrinter.CreatePDF pdf file: /var/folders/jy/r76chkt918d9psvb_4mdqkqc0000gn/T/{E98E446B-77E1-4E98-84FC-8B090485BC60}
2020-02-13, 11:18:26 reportPrinter.CreatePDF origin: 0 0 0 0
2020-02-13, 11:18:27 NotificationManager.Post NextMinor
2020-02-13, 11:18:27 NotificationManager.Post PDFCreated
2020-02-13, 11:18:27 reportPrinter.CreatePDF pdf file: /var/folders/jy/r76chkt918d9psvb_4mdqkqc0000gn/T/{F01F6B25-6CD7-4076-892E-6357563794DE}
2020-02-13, 11:18:27 reportPrinter.CreatePDF origin: 0 0 0 0
2020-02-13, 11:18:27 NotificationManager.Post NextMinor
2020-02-13, 11:18:28 NotificationManager.Post PDFCreated
2020-02-13, 11:18:28 reportPrinter.CreatePDF pdf file: /var/folders/jy/r76chkt918d9psvb_4mdqkqc0000gn/T/{FC9847D0-E0C3-4DED-A9AF-82B71219DC95}
2020-02-13, 11:18:28 reportPrinter.CreatePDF origin: 0 0 0 0
2020-02-13, 11:18:28 Dialog: Es gab ein Problem beim Erzeugen des PDFs für den Betreff "Rechnung für Ihre Bootsversicherung Police 855683 ".
2020-02-13, 11:18:32 print path: /Volumes/Secomba/thomas/Boxcryptor/Dropbox (Privat)/_save_data/Local Folders/Archiv/Freizeit/Boot/Mails/20xx-xx-xx 17-52-48 Rechnung für Ihre Bootsversicherung Police 855683 /20xx-xx-xx 17-52-48 Rechnung für Ihre Bootsversicherung Police .pdf
2020-02-13, 11:18:32 ArchiveThread.Archive done
2020-02-13, 11:18:32 ArchiveThread.ToTrash[/quote]

I’m not really sure if the problem is related to Boxcryptor or not. From the session log it looks like other pdf files were written.

How about creating the PDF in the temporary folder first; upon completion move the file to the user selected destination.

Just as an aside… I keep encountering end user systems where temp is missing or read-only.
Not sure what that is about - I have had to add a fall back to use ApplicationData or Documents as a temporary area when I cannot use Temp.

@Jeff Tullin : I’m assuming Catalina. But which version of Xojo do you use?

@Sam Rowlands : the user can create PDFs on the drive. Perhaps the name is too long?

[quote=475669:@Jeff Tullin]Just as an aside… I keep encountering end user systems where temp is missing or read-only.
Not sure what that is about - I have had to add a fall back to use ApplicationData or Documents as a temporary area when I cannot use Temp.[/quote]
Yeah I forgot about that one, you can also try the Caches folder.

Apple actually have API for specifically dealing with atomic file creation, which uses the temporary folder, and it works when I can’t directly access the temporary folder. I keep meaning to clean up my code for it and to share it.

Apple doesn’t document that this API has a glaring bug, whereby it leaves behind an empty folder. That if unremoved, reaches the limit of the number of folders allowed within a folder, and then fails. The folders get auto removed when the system restarts, so my guess is that Apple employees shut their Macs down on a daily basis.

I don’t think so, but with App Wrapper we had to explicitly check and NOT do any processing in a DropBox, iCloud, Google Drive, One Drive folder because the cloud service helper apps get in the way and mess with things while App Wrapper’s doing it’s work.

App Wrapper 4 is in production, and I’ve already compensated for this by moving the application to another location, then working on it, and putting it back when I’m finished.

@Sam Rowlands: something must be different for the file. But I’m going to try with the “create a second temp file and move it to the final location” next.

Yep. Very much this… especially if you have a couple of passes at a file… appending to a PDF, adding a custom icon to a document… these internet file based systems get their claws in halfway through the job and break the process.