Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Using image from Newsstand path #348

holgersindbaek opened this Issue Mar 15, 2013 · 2 comments


None yet
2 participants

holgersindbaek commented Mar 15, 2013

I'm using DTCoreText in my newsstand app and would like to show the images I've download to my newsstand issue. For example the image at this path:


When I use it as the source for my image, it doesn't display anything though:

<img src="/var/mobile/Applications/7135E3EA-4DBD-4D3C-8242-BB4C70343608/Library/Caches/Newsstand/348A5941-CB8A-41E0-B064-7257B8C8A29C/Logo.jpg" height="100" width="200">

If I use a local file it works:

<img src="Makerminds_Magazine.jpg" height="100" width="200">

Am I doing something wrong? How can I get to use my newsstand images in my attributed text?


odrobnik commented Mar 16, 2013

see DTTextAttachment.m:107ff for how the URL is decoded.

It bois down to two options:

  • specify the base URL correctly, the image src URL will be appended to that
  • implement support for the file:// scheme to specify an absolute path

holgersindbaek commented Mar 16, 2013

Thanks a lot for the pointer. I ended up going with the URL solution:

    // 1. Set the path to the "stylesheet"
    NSString *stylePath = [[NSBundle mainBundle] pathForResource:@"Style" ofType:@"html"];

    // 2. Insert the text into the stylesheet
    NSString* htmlString = [NSString stringWithContentsOfFile:stylePath encoding:NSUTF8StringEncoding error:nil];
    htmlString = [htmlString stringByReplacingOccurrencesOfString:@"**Placeholder**" withString:text];
    htmlString = [htmlString stringByReplacingOccurrencesOfString:@"**logo_path**'" withString:[NSString stringWithFormat:@"Logo.jpg' width='200' height='100'"]];

    // 4. Convert it into a data type
    NSData *htmlData = [htmlString dataUsingEncoding:NSUTF8StringEncoding];

    // 5. Define the latest issue
    NKIssue *latestIssue = [_library.issues lastObject];

    // 6. Define the options
    NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
    NSURL *bundleBaseURL = [NSURL fileURLWithPath: [latestIssue.contentURL path]];

    // 7. Define the attributed string
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithHTMLData:htmlData baseURL:latestIssue.contentURL documentAttributes:NULL];

Would be great with some more examples of how to use this library. I know the we have the example app (and it is great), but it can become a bit confusing sometimes.

Keep up the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment